35_log.t 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_DEBUG);
  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. $/ = undef; # slurp mode.
  37. select($old_select);
  38. }
  39. else {
  40. open(STDERR, '>&', fileno(OLDERR));
  41. close(OLDERR);
  42. }
  43. }
  44. skip 'no duplicated stderr', 2 unless ($dup);
  45. SKIP: {
  46. $zkh->exists($root_path);
  47. sleep(1);
  48. skip 'no seek on stderr', 1 unless (seek(STDERR, 0, 0));
  49. my $log = <STDERR>;
  50. like($log, qr/ZOO_.*exists/,
  51. 'exists(): generated log message');
  52. }
  53. SKIP: {
  54. $zkh->DESTROY();
  55. sleep(1);
  56. skip 'no seek on stderr', 1 unless (seek(STDERR, 0, 0));
  57. my $log = <STDERR>;
  58. like($log, qr/ZOO_.*close/,
  59. 'DESTROY(): generated log message');
  60. }
  61. open(STDERR, '>&', fileno(OLDERR));
  62. close(OLDERR);
  63. }
  64. }
  65. Net::ZooKeeper::set_log_level(ZOO_LOG_LEVEL_OFF);