util.pl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. sub zk_test_setup
  19. {
  20. my $verbose = shift;
  21. $SIG{'PIPE'} = 'IGNORE';
  22. my $hosts = $ENV{'ZK_TEST_HOSTS'};
  23. unless (defined($hosts) and $hosts =~ /\S/) {
  24. $hosts = 'localhost:0';
  25. diag('no ZooKeeper hostnames specified in ZK_TEST_HOSTS env var, ' .
  26. "using $hosts") if ($verbose);
  27. }
  28. my $root_path = $ENV{'ZK_TEST_PATH'};
  29. if (defined($root_path) and $root_path =~ /^\//) {
  30. $root_path =~ s/\/+/\//g;
  31. $root_path =~ s/\/$//;
  32. }
  33. else {
  34. $root_path = '/';
  35. diag('no ZooKeeper path specified in ZK_TEST_PATH env var, ' .
  36. 'using root path') if ($verbose);
  37. }
  38. my $node_path = $root_path . (($root_path =~ /\/$/) ? '' : '/') .
  39. '_net_zookeeper_test';
  40. return ($hosts, $root_path, $node_path);
  41. }
  42. sub zk_acl_test_setup
  43. {
  44. my $username = '_net_zookeeper_test';
  45. my $password = 'test';
  46. ## digest is Base64-encoded SHA1 digest of username:password
  47. my $digest = '2qi7Erp2cXYLGcQbXADiwUFaOGo=';
  48. return ($username, $password, $digest);
  49. }
  50. 1;