35_log.t 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. use File::Spec;
  19. use Test::More tests => 3;
  20. BEGIN { use_ok('Net::ZooKeeper', qw(:all)) };
  21. my $test_dir;
  22. (undef, $test_dir, undef) = File::Spec->splitpath($0);
  23. require File::Spec->catfile($test_dir, 'util.pl');
  24. my($hosts, $root_path, $node_path) = zk_test_setup(0);
  25. my $zkh = Net::ZooKeeper->new($hosts);
  26. Net::ZooKeeper::set_log_level(ZOO_LOG_LEVEL_INFO);
  27. SKIP: {
  28. skip 'no valid handle', 2 unless (defined($zkh));
  29. SKIP: {
  30. my $dup = 0;
  31. if (open(OLDERR, '>&', fileno(STDERR))) {
  32. if (close(STDERR) and open(STDERR, '+>', undef)) {
  33. $dup = 1;
  34. my $old_select = select(STDERR);
  35. $| = 1;
  36. select($old_select);
  37. }
  38. else {
  39. open(STDERR, '>&', fileno(OLDERR));
  40. close(OLDERR);
  41. }
  42. }
  43. skip 'no duplicated stderr', 2 unless ($dup);
  44. SKIP: {
  45. $zkh->exists($root_path);
  46. sleep(1);
  47. skip 'no seek on stderr', 1 unless (seek(STDERR, 0, 0));
  48. my $log = <STDERR>;
  49. like($log, qr/ZOO_/,
  50. 'exists(): generated log message');
  51. }
  52. SKIP: {
  53. $zkh->DESTROY();
  54. sleep(1);
  55. skip 'no seek on stderr', 1 unless (seek(STDERR, 0, 0));
  56. my $log = <STDERR>;
  57. like($log, qr/ZOO_/,
  58. 'DESTROY(): generated log message');
  59. }
  60. open(STDERR, '>&', fileno(OLDERR));
  61. close(OLDERR);
  62. }
  63. }
  64. Net::ZooKeeper::set_log_level(ZOO_LOG_LEVEL_OFF);