test/test_basic.rb in zookeeper-0.2.2 vs test/test_basic.rb in zookeeper-0.3.0

- old
+ new

@@ -1,63 +1,40 @@ +require 'rubygems' + HERE = File.expand_path(File.dirname(__FILE__)) require "#{HERE}/../lib/zookeeper" z = Zookeeper.new("localhost:2181") -puts "root: #{z.get_children("/").inspect}" +puts "root: #{z.get_children(:path => "/").inspect}" path = "/testing_node" puts "working with path #{path}" -stat = z.stat(path) +h = z.stat(:path => path) +stat = h[:stat] puts "exists? #{stat.inspect}" -unless stat.nil? - z.get_children(path).each do |o| +if stat.exists + z.get_children(:path => path)[:children].each do |o| puts " child object: #{o}" end - puts "delete: #{z.delete(path, stat.version).inspect}" + puts "delete: #{z.delete(:path => path, :version => stat.version).inspect}" end -puts "create: #{z.create(path, "initial value", 0).inspect}" +puts "create: #{z.create(:path => path, :data => 'initial value').inspect}" -value, stat = z.get(path) +v = z.get(:path => path) +value, stat = v[:data], v[:stat] puts "current value #{value}, stat #{stat.inspect}" -puts "set: #{z.set(path, "this is a test", stat.version).inspect}" +puts "set: #{z.set(:path => path, :data => 'this is a test', :version => stat.version).inspect}" -value, stat = z.get(path) +v = z.get(:path => path) +value, stat = v[:data], v[:stat] puts "new value: #{value.inspect} #{stat.inspect}" -puts "delete: #{z.delete(path, stat.version).inspect}" +puts "delete: #{z.delete(:path => path, :version => stat.version).inspect}" -begin - puts "exists? #{z.exists(path)}" - raise Exception, "it shouldn't exist" -rescue Zookeeper::NoNodeError - puts "doesn't exist - good, because we just deleted it!" -end - -puts "trying a watcher" -puts z -if s = z.stat("/test"); z.delete("/test", s.version); end -z.create("/test", "foo", 0) -z.exists("/test") do - puts "callback!!!" -end -puts "now changing it" -z.set("/test", "bar", 0) -sleep 1 -puts "did the watcher say something?" - -puts "let's try using a lock" -z.try_acquire("/test_lock", "this is the content of the lock file") do |have_lock| - puts have_lock ? "we have the lock!" : "failed to obtain lock :(" - if have_lock - puts "sleeping" - sleep 5 - end -end -puts "done with locking..." - +puts "exists? #{z.stat(:path => path)[:stat].exists}"