"Fossies" - the Fresh Open Source Software Archive 
Member "apache-zookeeper-3.8.1/zookeeper-contrib/zookeeper-contrib-zkperl/t/15_thread.t" (25 Jan 2023, 3274 Bytes) of package /linux/misc/apache-zookeeper-3.8.1.tar.gz:
As a special service "Fossies" has tried to format the requested text file into HTML format (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
1 # Net::ZooKeeper - Perl extension for Apache ZooKeeper
2 #
3 # Licensed to the Apache Software Foundation (ASF) under one
4 # or more contributor license agreements. See the NOTICE file
5 # distributed with this work for additional information
6 # regarding copyright ownership. The ASF licenses this file
7 # to you under the Apache License, Version 2.0 (the
8 # "License"); you may not use this file except in compliance
9 # with the License. You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18
19 use Config;
20 use File::Spec;
21 use Test::More;
22
23 BEGIN {
24 if ($Config{'useithreads'}) {
25 plan tests => 10;
26 }
27 else {
28 plan skip_all => 'no thread support';
29 }
30 }
31
32 use threads;
33
34 BEGIN { use_ok('Net::ZooKeeper', qw(:all)) };
35
36
37 my $test_dir;
38 (undef, $test_dir, undef) = File::Spec->splitpath($0);
39 require File::Spec->catfile($test_dir, 'util.pl');
40
41 my($hosts, $root_path, $node_path) = zk_test_setup(0);
42
43
44 my $zkh = Net::ZooKeeper->new($hosts);
45
46 SKIP: {
47 skip 'no valid handle', 9 unless (defined($zkh));
48
49 my($thread) = threads->new(\&thread_test, $zkh);
50
51 SKIP: {
52 skip 'no valid thread', 3 unless (defined($thread));
53
54 my(@ret) = $thread->join;
55
56 ok((@ret == 3 and $ret[0]),
57 'CLONE_SKIP(): handle reference after spawning thread');
58
59 ok((@ret == 3 and $ret[1]),
60 'CLONE_SKIP(): scalar handle reference after spawning thread');
61
62 ok((@ret == 3 and $ret[2]),
63 'CLONE_SKIP(): undef handle reference after spawning thread');
64 }
65
66 my $stat = $zkh->stat();
67
68 ($thread) = threads->new(\&thread_test, $stat);
69
70 SKIP: {
71 skip 'no valid thread', 3 unless (defined($thread));
72
73 my(@ret) = $thread->join;
74
75 ok((@ret == 3 and $ret[0]),
76 'stat CLONE_SKIP(): stat handle reference after spawning thread');
77
78 ok((@ret == 3 and $ret[1]),
79 'stat CLONE_SKIP(): scalar stat handle reference after ' .
80 'spawning thread');
81
82 ok((@ret == 3 and $ret[2]),
83 'stat CLONE_SKIP(): undef stat handle reference after ' .
84 'spawning thread');
85 }
86
87 my $watch = $zkh->watch();
88
89 ($thread) = threads->new(\&thread_test, $watch);
90
91 SKIP: {
92 skip 'no valid thread', 3 unless (defined($thread));
93
94 my(@ret) = $thread->join;
95
96 ok((@ret == 3 and $ret[0]),
97 'watch CLONE_SKIP(): watch handle reference after spawning thread');
98
99 ok((@ret == 3 and $ret[1]),
100 'watch CLONE_SKIP(): scalar watch handle reference after ' .
101 'spawning thread');
102
103 ok((@ret == 3 and $ret[2]),
104 'watch CLONE_SKIP(): undef watch handle reference after ' .
105 'spawning thread');
106 }
107 }
108
109 sub thread_test
110 {
111 my $zkh = shift;
112
113 my @ret;
114
115 $ret[0] = ref($zkh) ? 1 : 0;
116 $ret[1] = ($ret[0] and ref($zkh) eq 'SCALAR') ? 1 : 0;
117 $ret[2] = ($ret[1] and !defined(${$zkh})) ? 1 : 0;
118
119 return @ret;
120 }
121