Added: hadoop/zookeeper/trunk/src/contrib/zkperl/t/50_access.t
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zkperl/t/50_access.t?rev=769079&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/zkperl/t/50_access.t (added)
+++ hadoop/zookeeper/trunk/src/contrib/zkperl/t/50_access.t Mon Apr 27 18:07:56 
2009
@@ -0,0 +1,340 @@
+# Net::ZooKeeper - Perl extension for Apache ZooKeeper
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use File::Spec;
+use Test::More tests => 38;
+
+BEGIN { use_ok('Net::ZooKeeper', qw(:all)) };
+
+
+my $test_dir;
+(undef, $test_dir, undef) = File::Spec->splitpath($0);
+require File::Spec->catfile($test_dir, 'util.pl');
+
+my($hosts, $root_path, $node_path) = zk_test_setup(0);
+
+my($username, $password, $digest) = zk_acl_test_setup();
+
+
+SKIP: {
+    my $zkh = Net::ZooKeeper->new($hosts);
+
+    my $path = $zkh->create($node_path, 'foo',
+                            'acl' => ZOO_OPEN_ACL_UNSAFE) if (defined($zkh));
+
+    skip 'no connection to ZooKeeper', 36 unless
+        (defined($path) and $path eq $node_path);
+
+
+    ## _zk_acl_constant()
+
+    my $no_read_acl = ZOO_OPEN_ACL_UNSAFE;
+    ok((ref($no_read_acl) eq 'ARRAY' and
+        @{$no_read_acl} == 1 and
+        ref($no_read_acl->[0]) eq 'HASH' and
+        keys(%{$no_read_acl->[0]}) == 3 and
+        $no_read_acl->[0]->{'perms'} == ZOO_PERM_ALL),
+       '_zk_acl_constant(): returned default ACL');
+
+    $no_read_acl->[0]->{'perms'} &= ~ZOO_PERM_READ;
+    is($no_read_acl->[0]->{'perms'}, ((ZOO_PERM_ALL) & ~ZOO_PERM_READ),
+       'assign: altered default ACL');
+
+    is(ZOO_OPEN_ACL_UNSAFE->[0]->{'perms'}, ZOO_PERM_ALL,
+       '_zk_acl_constant(): returned unaltered default ACL');
+
+    my $copy_no_read_acl = $no_read_acl;
+    is_deeply($copy_no_read_acl, $no_read_acl,
+              'assign: copied default ACL');
+
+    undef $no_read_acl;
+    ok(!defined($no_read_acl),
+       'undef: released original default ACL');
+
+    is($copy_no_read_acl->[0]->{'perms'}, ((ZOO_PERM_ALL) & ~ZOO_PERM_READ),
+       'undef: no change to copied default ACL');
+
+    $no_read_acl = $copy_no_read_acl;
+    is_deeply($no_read_acl, $copy_no_read_acl,
+              'assign: re-copied default ACL');
+
+
+    ## create()
+
+    my $acl_node_path = "$node_path/a1";
+
+    $path = $zkh->create($acl_node_path, 'foo', 'acl' => $no_read_acl);
+    is($path, $acl_node_path,
+       'create(): created node with no-read ACL');
+
+    my $node = $zkh->get($acl_node_path);
+
+    my $skip_acl;
+    if (defined($node) and $node eq 'foo') {
+        $skip_acl = 1;
+    }
+    elsif(!defined($node) and $zkh->get_error() == ZNOAUTH) {
+        $skip_acl = 0;
+    }
+    else {
+        $skip_acl = -1;
+        diag(sprintf('unable to get node with no-read ACL %s: %d, %s',
+                     $acl_node_path, $zkh->get_error(), $!));
+    }
+
+    my $ret = $zkh->delete($acl_node_path);
+    diag(sprintf('unable to delete node with no-read ACL %s: %d, %s',
+                 $acl_node_path, $zkh->get_error(), $!)) unless ($ret);
+
+    my $digest_acl = [
+        {
+            'perms'  => ZOO_PERM_READ,
+            'scheme' => 'world',
+            'id'     => 'anyone'
+        },
+        {
+            'perms'  => (ZOO_PERM_WRITE | ZOO_PERM_ADMIN),
+            'scheme' => 'digest',
+            'id'     => "$username:$digest"
+        }
+    ];
+
+    $path = $zkh->create($acl_node_path, 'foo', 'acl' => $digest_acl);
+    is($path, $acl_node_path,
+       'create(): created node with digest auth ACL');
+
+    SKIP: {
+        skip 'ZooKeeper skipping ACLs', 1 unless (!$skip_acl);
+
+        my $acl_node_path = "$node_path/a2";
+
+        my $path = $zkh->create($acl_node_path, 'foo', 'acl' => [
+            {
+                'perms'  => ZOO_PERM_WRITE,
+                'scheme' => 'foo',
+                'id'     => 'bar'
+            }
+        ]);
+        ok((!defined($path) and $zkh->get_error() == ZINVALIDACL and $! eq ''),
+           'create(): undef when attempting to create node with invalid ACL');
+    }
+
+
+    ## get_acl()
+
+    my @acl = ('abc');
+    @acl = $zkh->get_acl($node_path . '/NONE');
+    ok((@acl == 0 and $zkh->get_error() == ZNONODE and $! eq ''),
+       'get_acl(): empty list returned for non-extant node');
+
+    $num_acl_entries = $zkh->get_acl($node_path . '/NONE');
+    ok((!defined($num_acl_entries) and $zkh->get_error() == ZNONODE and
+        $! eq ''),
+       'get_acl(): undef returned for non-extant node');
+
+    @acl = ('abc');
+    @acl = $zkh->get_acl($acl_node_path);
+    is_deeply(\...@acl, $digest_acl,
+              'get_acl(): retrieved digest ACL');
+
+    my $stat = $zkh->stat();
+
+    @acl = ('abc');
+    @acl = $zkh->get_acl($node_path, 'stat' => $stat);
+    is_deeply(\...@acl, ZOO_OPEN_ACL_UNSAFE,
+              'get_acl(): retrieved ACL');
+
+    is($stat->{'data_len'}, 3,
+       'get_acl(): retrieved ACL with stat handle');
+
+    SKIP: {
+        skip 'ZooKeeper not skipping ACLs', 3 unless ($skip_acl > 0);
+
+        my $acl_node_path = "$node_path/a2";
+
+        my $path = $zkh->create($acl_node_path, 'foo', 'acl' => []);
+        is($path, $acl_node_path,
+           'create(): created node with empty ACL');
+
+        my @acl = ('abc');
+        @acl = $zkh->get_acl($acl_node_path);
+        ok((@acl == 0 and $zkh->get_error() == ZOK),
+           'get_acl(): retrieved empty ACL');
+
+        my $num_acl_entries = $zkh->get_acl($acl_node_path);
+        ok((defined($num_acl_entries) and $num_acl_entries == 0),
+           'get_acl(): retrieved zero count of ACL entries');
+
+        my $ret = $zkh->delete($acl_node_path);
+        diag(sprintf('unable to delete node with empty ACL %s: %d, %s',
+                     $acl_node_path, $zkh->get_error(), $!)) unless ($ret);
+    }
+
+
+    ## set_acl()
+
+    SKIP: {
+        skip 'ZooKeeper skipping ACLs', 2 unless (!$skip_acl);
+
+        my $ret = $zkh->set_acl($acl_node_path, [
+            {
+                'perms'  => ZOO_PERM_CREATE,
+                'scheme' => 'foo',
+                'id'     => 'bar'
+            }
+        ]);
+        ok((!$ret and $zkh->get_error() == ZINVALIDACL and $! eq ''),
+           'set_acl(): invalid ACL');
+
+        push @{$digest_acl}, {
+            'perms'  => (ZOO_PERM_CREATE | ZOO_PERM_DELETE),
+            'scheme' => 'host',
+            'id'     => 'foo.bar.123'
+        };
+
+        $ret = $zkh->set_acl($acl_node_path, $digest_acl);
+        ok((!$ret and $zkh->get_error() == ZNOAUTH and $! eq ''),
+           'set_acl(): ACL unchanged if no auth');
+    }
+
+
+    ## add_auth(), set_acl()
+
+    $ret = $zkh->add_auth('digest', '');
+    ok($ret,
+       'add_auth(): empty digest cert');
+
+    SKIP: {
+        skip 'ZooKeeper skipping ACLs', 1 unless (!$skip_acl);
+
+        my $ret = $zkh->set($acl_node_path, 'foo');
+        ok((!$ret and $zkh->get_error() == ZNOAUTH and $! eq ''),
+           'set(): node value unchanged if no auth');
+    }
+
+    $ret = $zkh->add_auth('digest', "$username:$password");
+    ok($ret,
+       'add_auth(): valid digest cert');
+
+    SKIP: {
+        skip 'ZooKeeper skipping ACLs', 13 unless (!$skip_acl);
+
+        my $ret = $zkh->set($acl_node_path, 'baz');
+        ok($ret,
+           'set(): set node value with auth');
+
+        my $node = $zkh->get($acl_node_path);
+        is($node, 'baz',
+           'get(): retrieved node value with auth');
+
+        $ret = $zkh->set_acl($acl_node_path, $digest_acl);
+        ok($ret,
+           'set_acl(): set digest ACL with auth');
+
+        my $stat = $zkh->stat();
+
+        my @acl = ('abc');
+        @acl = $zkh->get_acl($acl_node_path, 'stat' => $stat);
+        is_deeply(\...@acl, $digest_acl,
+                  'get_acl(): retrieved digest ACL with auth');
+
+        is($stat->{'data_len'}, 3,
+           'get_acl(): retrieved digest ACL with stat handle and auth');
+
+        SKIP: {
+            skip 'invalid node data', 2 unless ($stat->{'version'} == 1);
+
+            my $ret = $zkh->set_acl($acl_node_path, $digest_acl,
+                                    'version' => $stat->{'version'});
+            ok($ret,
+               'set_acl(): set digest ACL with matching version with auth');
+
+            $ret = $zkh->set_acl($acl_node_path, $digest_acl,
+                                 'version' => $stat->{'version'});
+            ok((!$ret and $zkh->get_error() == ZBADVERSION and $! eq ''),
+               'set_acl(): ACL unchanged if non-matching version');
+        }
+
+        my $child_node_path = "$acl_node_path/c1";
+
+        my $path = $zkh->create($child_node_path, 'foo',
+                                'acl' => ZOO_OPEN_ACL_UNSAFE);
+        ok((!defined($path) and $zkh->get_error() == ZNOAUTH and $! eq ''),
+           'create(): undef when attempting to create node if no auth');
+
+        $digest_acl->[1]->{'perms'} |= ZOO_PERM_CREATE;
+        $digest_acl->[2]->{'perms'} &= ~ZOO_PERM_CREATE;
+
+        $ret = $zkh->set_acl($acl_node_path, $digest_acl);
+        ok($ret,
+           'set_acl(): set changed digest ACL with auth');
+
+        $path = $zkh->create($child_node_path, 'foo',
+                             'acl' => ZOO_OPEN_ACL_UNSAFE);
+        is($path, $child_node_path,
+           'create(): created node with auth');
+
+        $ret = $zkh->delete($child_node_path);
+        ok((!$ret and $zkh->get_error() == ZNOAUTH and $! eq ''),
+           'delete(): no deletion of node if no auth');
+
+        $digest_acl->[1]->{'perms'} |= ZOO_PERM_DELETE;
+        pop @{$digest_acl};
+
+        $ret = $zkh->set_acl($acl_node_path, $digest_acl);
+        ok($ret,
+           'set_acl(): set reduced digest ACL with auth');
+
+        $ret = $zkh->delete($child_node_path);
+        ok($ret,
+           'delete(): deleted node with auth');
+    }
+
+
+    ## cleanup
+
+    $ret = $zkh->delete($acl_node_path);
+    diag(sprintf('unable to delete node with digest auth ACL %s: %d, %s',
+                 $acl_node_path, $zkh->get_error(), $!)) unless ($ret);
+
+    $ret = $zkh->delete($node_path);
+    diag(sprintf('unable to delete node %s: %d, %s',
+                 $node_path, $zkh->get_error(), $!)) unless ($ret);
+}
+
+SKIP: {
+    my $zkh = Net::ZooKeeper->new($hosts);
+
+    my $ret = $zkh->exists($root_path) if (defined($zkh));
+
+    skip 'no connection to ZooKeeper', 1 unless
+        (defined($ret) and $ret);
+
+
+    ## add_auth()
+
+    $ret = $zkh->add_auth('foo', 'bar');
+    my $err = $zkh->get_error();
+    ok((!$ret and
+        ($err == ZAUTHFAILED or
+         $err == ZCONNECTIONLOSS or
+         $err == ZSESSIONEXPIRED)
+        and $! eq ''),
+       'set_acl(): invalid scheme');
+}
+

Added: hadoop/zookeeper/trunk/src/contrib/zkperl/t/60_watch.t
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zkperl/t/60_watch.t?rev=769079&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/zkperl/t/60_watch.t (added)
+++ hadoop/zookeeper/trunk/src/contrib/zkperl/t/60_watch.t Mon Apr 27 18:07:56 
2009
@@ -0,0 +1,304 @@
+# Net::ZooKeeper - Perl extension for Apache ZooKeeper
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use File::Spec;
+use Test::More tests => 30;
+
+BEGIN { use_ok('Net::ZooKeeper', qw(:all)) };
+
+
+my $test_dir;
+(undef, $test_dir, undef) = File::Spec->splitpath($0);
+require File::Spec->catfile($test_dir, 'util.pl');
+
+my($hosts, $root_path, $node_path) = zk_test_setup(0);
+
+
+SKIP: {
+    my $zkh = Net::ZooKeeper->new($hosts);
+
+    my $path = $zkh->create($node_path, 'foo',
+                            'acl' => ZOO_OPEN_ACL_UNSAFE) if (defined($zkh));
+
+    skip 'no connection to ZooKeeper', 20 unless
+        (defined($path) and $path eq $node_path);
+
+
+    ## exists()
+
+    $zkh->{'watch_timeout'} = 100;
+
+    my $watch = $zkh->watch();
+
+    my $ret = $zkh->exists($node_path, 'watch' => $watch);
+    ok($ret,
+       'exists(): checked node existence with watch handle');
+
+    $ret = $watch->wait();
+    ok(!$ret,
+       'wait(): watch after checking node existence timed out');
+
+    $ret = $zkh->exists($node_path, 'watch' => $watch);
+    ok($ret,
+       'exists(): checked node existence with renewed watch handle');
+
+    $ret = $watch->wait();
+    ok(!$ret,
+       'wait(): watch after checking node existence timed out with ' .
+       'renewed watch handle');
+
+    undef $watch;
+    ok(!defined($watch),
+       'undef: released watch handle');
+
+    my $pending_watches = $zkh->{'pending_watches'};
+    is($pending_watches, 2,
+       '_zk_release_watches(): report pending watches');
+
+
+    ## get_children()
+
+    $watch = $zkh->watch('timeout' => 50);
+
+    my $num_children = $zkh->get_children($node_path, 'watch' => $watch);
+    ok((defined($num_children) and $num_children == 0),
+       'get_children(): retrieved zero count of child nodes with ' .
+       'watch handle');
+
+    $ret = $watch->wait();
+    ok(!$ret,
+       'wait(): watch after retrieving child nodes timed out with ' .
+       'watch handle');
+
+    $watch->{'timeout'} = 100;
+
+    my @child_paths = $zkh->get_children($node_path, 'watch' => $watch);
+    ok((@child_paths == 0),
+       'get_children(): retrieved empty list of child nodes with ' .
+       'renewed watch handle');
+
+    $ret = $watch->wait();
+    ok(!$ret,
+       'wait(): watch after retrieving child nodes timed out with ' .
+       'renewed watch handle');
+
+    $pending_watches = $zkh->{'pending_watches'};
+    is($pending_watches, 4,
+       '_zk_release_watches(): report pending watches');
+
+
+    ## get()
+
+    $watch = $zkh->watch();
+
+    my $node = $zkh->get($node_path, 'watch' => $watch);
+    is($node, 'foo',
+       'get(): retrieved node value with watch handle');
+
+    $ret = $watch->wait('timeout' => 0);
+    ok(!$ret,
+       'wait(): watch after retrieving node value timed out with ' .
+       'watch handle');
+
+    $node = $zkh->get($node_path, 'watch' => $watch);
+    is($node, 'foo',
+       'get(): retrieved node value with renewed watch handle');
+
+    $ret = $watch->wait();
+    ok(!$ret,
+       'wait(): watch after retrieving node value timed out with ' .
+       'renewed watch handle');
+
+    $pending_watches = $zkh->{'pending_watches'};
+    is($pending_watches, 6,
+       '_zk_release_watches(): all watches pending');
+
+
+    ## _zk_release_watches()
+
+    $ret = $zkh->DESTROY();
+    ok($ret,
+       'DESTROY(): destroyed handle with pending watches');
+
+    my $event = $watch->{'event'};
+    is($event, 0,
+       '_zk_release_watches(): watch not destroyed when tied to watch handle');
+
+    $zkh = Net::ZooKeeper->new($hosts);
+
+    SKIP: {
+        my $ret = $zkh->exists($node_path, 'watch' => $watch);
+
+        skip 'no connection to ZooKeeper', 2 unless
+            (defined($ret) and $ret);
+
+        ok($ret,
+           'exists(): checked node existence with renewed watch handle ' .
+           'from prior connection');
+
+        $ret = $watch->wait();
+        ok(!$ret,
+           'wait(): watch after checking node existence timed out with ' .
+           'renewed watch handle from prior connection');
+
+
+    }
+}
+
+my $pid = fork();
+
+SKIP: {
+    skip 'unable to fork', 4 unless (defined($pid));
+
+    my $zkh = Net::ZooKeeper->new($hosts);
+
+    my $ret = $zkh->exists($node_path) if (defined($zkh));
+
+    if ($pid == 0) {
+        ## child process
+
+        my $code = 0;
+
+        if (defined($ret) and $ret) {
+            sleep(1);
+
+            my $ret = $zkh->set($node_path, 'foo');
+
+            diag(sprintf('set(): failed in child process: %d, %s',
+                         $zkh->get_error(), $!)) unless ($ret);
+
+            $code = !$ret;
+
+            sleep(1);
+
+            my $path = $zkh->create("$node_path/c", 'foo',
+                                    'acl' => ZOO_OPEN_ACL_UNSAFE);
+
+            diag(sprintf('create(): failed in child process: %d, %s',
+                         $zkh->get_error(), $!)) unless
+                (defined($path) and $path eq "$node_path/c");
+
+            $code &= !$ret;
+
+            sleep(1);
+
+            $ret = $zkh->delete("$node_path/c");
+
+            diag(sprintf('delete(): failed in child process: %d, %s',
+                         $zkh->get_error(), $!)) unless ($ret);
+
+            $code &= !$ret;
+
+            sleep(1);
+
+            $ret = $zkh->set($node_path, 'foo');
+
+            diag(sprintf('set(): failed in child process: %d, %s',
+                         $zkh->get_error(), $!)) unless ($ret);
+
+            $code &= !$ret;
+        }
+
+        exit($code);
+    }
+    else {
+        ## parent process
+
+        SKIP: {
+            skip 'no connection to ZooKeeper', 9 unless
+                (defined($ret) and $ret);
+
+            my $watch = $zkh->watch('timeout' => 5000);
+
+
+            ## wait()
+
+            my $ret = $zkh->exists($node_path, 'watch' => $watch);
+            ok($ret,
+               'exists(): checked node existence with watch handle ' .
+               'in parent');
+
+            $ret = $watch->wait();
+            ok(($ret and $watch->{'event'} == ZOO_CHANGED_EVENT and
+                $watch->{'state'} == ZOO_CONNECTED_STATE),
+               'wait(): waited for event after checking node existence');
+
+            my $num_children = $zkh->get_children($node_path,
+                                                 'watch' => $watch);
+            ok((defined($num_children) and $num_children == 0),
+               'get_children(): retrieved zero count of child nodes with ' .
+               'watch handle in parent');
+
+            $ret = $watch->wait();
+            ok(($ret and $watch->{'event'} == ZOO_CHILD_EVENT and
+                $watch->{'state'} == ZOO_CONNECTED_STATE),
+               'wait(): waited for create child event after ' .
+               'retrieving child nodes');
+
+            my @child_paths = $zkh->get_children($node_path,
+                                                'watch' => $watch);
+            ok((@child_paths == 1 and $child_paths[0] eq 'c'),
+               'get_children(): retrieved list of child nodes with ' .
+               'watch handle in parent');
+
+            $ret = $watch->wait();
+            ok(($ret and $watch->{'event'} == ZOO_CHILD_EVENT and
+                $watch->{'state'} == ZOO_CONNECTED_STATE),
+               'wait(): waited for delete child event after ' .
+               'retrieving child nodes');
+
+            my $node = $zkh->get($node_path, 'watch' => $watch);
+            is($node, 'foo',
+               'get(): retrieved node value with watch handle in parent');
+
+            $ret = $watch->wait();
+            ok(($ret and $watch->{'event'} == ZOO_CHANGED_EVENT and
+                $watch->{'state'} == ZOO_CONNECTED_STATE),
+               'wait(): waited for event after retrieving node value');
+
+            undef $watch;
+
+            my $pending_watches = $zkh->{'pending_watches'};
+            is($pending_watches, 0,
+               '_zk_release_watches(): no watches pending');
+        }
+
+        my $reap = waitpid($pid, 0);
+
+        diag(sprintf('child process failed: exit %d, signal %d%s',
+                     ($? >> 8), ($? & 127),
+                     (($? & 128) ? ', core dump' : ''))) if
+            ($reap == $pid and $? != 0);
+    }
+}
+
+
+## cleanup
+
+{
+    my $zkh = Net::ZooKeeper->new($hosts);
+
+    my $ret = $zkh->exists($node_path) if (defined($zkh));
+
+    if (defined($ret) and $ret) {
+        $ret = $zkh->delete($node_path);
+        diag(sprintf('unable to delete node %s: %d, %s',
+                     $node_path, $zkh->get_error(), $!)) unless ($ret);
+    }
+}
+

Added: hadoop/zookeeper/trunk/src/contrib/zkperl/t/util.pl
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zkperl/t/util.pl?rev=769079&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/zkperl/t/util.pl (added)
+++ hadoop/zookeeper/trunk/src/contrib/zkperl/t/util.pl Mon Apr 27 18:07:56 2009
@@ -0,0 +1,62 @@
+# Net::ZooKeeper - Perl extension for Apache ZooKeeper
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+sub zk_test_setup
+{
+    my $verbose = shift;
+
+    $SIG{'PIPE'} = 'IGNORE';
+
+    my $hosts = $ENV{'ZK_TEST_HOSTS'};
+    unless (defined($hosts) and $hosts =~ /\S/) {
+        $hosts = 'localhost:0';
+        diag('no ZooKeeper hostnames specified in ZK_TEST_HOSTS env var, ' .
+             "using $hosts") if ($verbose);
+    }
+
+    my $root_path = $ENV{'ZK_TEST_PATH'};
+    if (defined($root_path) and $root_path =~ /^\//) {
+        $root_path =~ s/\/+/\//g;
+        $root_path =~ s/\/$//;
+    }
+    else {
+        $root_path = '/';
+        diag('no ZooKeeper path specified in ZK_TEST_PATH env var, ' .
+             'using root path') if ($verbose);
+    }
+
+    my $node_path = $root_path . (($root_path =~ /\/$/) ? '' : '/') .
+        '_net_zookeeper_test';
+
+    return ($hosts, $root_path, $node_path);
+}
+
+sub zk_acl_test_setup
+{
+    my $username = '_net_zookeeper_test';
+
+    my $password = 'test';
+
+    ## digest is Base64-encoded SHA1 digest of username:password
+    my $digest = '2qi7Erp2cXYLGcQbXADiwUFaOGo=';
+
+    return ($username, $password, $digest);
+}
+
+1;
+    

Added: hadoop/zookeeper/trunk/src/contrib/zkperl/typemap
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zkperl/typemap?rev=769079&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/zkperl/typemap (added)
+++ hadoop/zookeeper/trunk/src/contrib/zkperl/typemap Mon Apr 27 18:07:56 2009
@@ -0,0 +1,38 @@
+# Net::ZooKeeper - Perl extension for Apache ZooKeeper
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+TYPEMAP
+Net::ZooKeeper T_ZK_HANDLE
+Net::ZooKeeper::Stat   T_ZK_HANDLE
+Net::ZooKeeper::Watch  T_ZK_HANDLE
+
+INPUT
+T_ZK_HANDLE
+       if (SvROK($arg) && SvTYPE(SvRV($arg)) == SVt_PVHV &&
+           sv_derived_from($arg, \"${ntype}\")) {
+           $var = (HV*) SvRV($arg);
+       }
+       else {
+           Perl_croak(aTHX_
+                       \"$var is not a hash reference of type ${ntype}\");
+       }
+
+OUTPUT
+T_ZK_HANDLE
+       NOT_IMPLEMENTED
+


Reply via email to