Sha256: ce22cbd2013814e7129620b241f81313b99f87a85be77c3a1bd0b21172a40401

Contents?: true

Size: 1.34 KB

Versions: 63

Compression:

Stored size: 1.34 KB

Contents

require 'rubygems'
require 'zookeeper'

def wait_until(timeout=10, &block)
  time_to_stop = Time.now + timeout
  until yield do
    break if Time.now > time_to_stop
    sleep 0.1
  end
end

puts 'Initializing Zookeeper'

zk = Zookeeper.new('localhost:2181')

if zk.state != Zookeeper::ZOO_CONNECTED_STATE
  puts 'Unable to connect to Zookeeper!'
  Kernel.exit
end

def watcher(args)
  puts "#{args.inspect}"
  puts "In watcher: path=#{args.path}, context=#{args.context}"
  if args.path == args.context
    puts "TEST PASSED IN WATCHER"
  else
    puts "TEST FAILED IN WATCHER"
  end
end

wcb = Zookeeper::WatcherCallback.new do
  watcher(wcb)
end

resp = zk.create(:path => '/test', :sequence => true)
puts "#{resp.inspect}"
puts "TEST FAILED [create]" unless resp[:rc] == Zookeeper::ZOK
 
base_path = resp[:path]
watched_file = "#{base_path}/file.does.not.exist"

resp = zk.stat(:path => watched_file, :watcher => wcb, :watcher_context => watched_file)
puts "#{resp.inspect}"
puts "TEST FAILED [stat]" unless resp[:rc] == Zookeeper::ZNONODE

resp = zk.create(:path => watched_file, :data => 'test data', :ephemeral => true)
puts "#{resp.inspect}"
puts "TEST FAILED [create]" unless resp[:rc] == Zookeeper::ZOK

wait_until { wcb.completed? }

puts "TEST FAILED" unless wcb.completed?
puts "TEST PASSED"

zk.delete(:path => watched_file)
zk.delete(:path => base_path)

Version data entries

63 entries across 63 versions & 2 rubygems

Version Path
slyphon-zookeeper-0.8.1 test/test_watcher1.rb
slyphon-zookeeper-0.8.1-java test/test_watcher1.rb
slyphon-zookeeper-0.8.0 test/test_watcher1.rb
slyphon-zookeeper-0.8.0-java test/test_watcher1.rb
slyphon-zookeeper-0.8.0.rc.1-java test/test_watcher1.rb
slyphon-zookeeper-0.8.0.rc.1 test/test_watcher1.rb
slyphon-zookeeper-0.3.0 test/test_watcher1.rb
slyphon-zookeeper-0.3.0-java test/test_watcher1.rb
slyphon-zookeeper-0.2.11 test/test_watcher1.rb
slyphon-zookeeper-0.2.11-java test/test_watcher1.rb
slyphon-zookeeper-0.2.10 test/test_watcher1.rb
slyphon-zookeeper-0.2.10-java test/test_watcher1.rb
slyphon-zookeeper-0.2.9-java test/test_watcher1.rb
slyphon-zookeeper-0.2.9 test/test_watcher1.rb
slyphon-zookeeper-0.2.8-java test/test_watcher1.rb
slyphon-zookeeper-0.2.8 test/test_watcher1.rb
slyphon-zookeeper-0.2.7 test/test_watcher1.rb
slyphon-zookeeper-0.2.7-java test/test_watcher1.rb
slyphon-zookeeper-0.2.5 test/test_watcher1.rb
slyphon-zookeeper-0.2.5-java test/test_watcher1.rb