zkruby 3.4.4.rc4 → 3.4.4.rc5

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,22 +2,31 @@
2
2
  require 'bindata'
3
3
  module ZooKeeper
4
4
 
5
- class ZKBuffer < BinData::Primitive
6
- int32be :len, :value => lambda { data.nil? ? -1 : data.length }
7
- string :data, :read_length => :len
5
+ class ZKBuffer < BinData::BasePrimitive
8
6
 
9
- def get; self.data; end
10
- def set(v) self.data = v; end
7
+ def value_to_binary_string(v)
8
+ vlen = v.nil? ? -1 : v.length
9
+ [ vlen, v ].pack("NA*")
10
+ end
11
+
12
+ def read_and_return_value(io)
13
+ vlen = io.readbytes(4).unpack("i!>")[0]
14
+ vlen < 0 ? nil : io.readbytes(vlen)
15
+ end
16
+
17
+ def sensible_default
18
+ nil
19
+ end
11
20
  end
12
21
 
13
- class ZKString < BinData::Primitive
14
- int32be :len, :value => lambda { data.nil? ? -1 : data.length }
15
- string :data, :read_length => :len
22
+ class ZKString < ZKBuffer
23
+ def read_and_return_value(io)
24
+ value = super
25
+ value.force_encoding('UTF-8') unless value.nil?
26
+ end
16
27
 
17
- def get; self.data; end
18
- def set(v) self.data = v; end
19
- def snapshot
20
- super.force_encoding('UTF-8')
28
+ def sensible_default
29
+ ""
21
30
  end
22
31
  end
23
32
 
data/lib/zkruby/client.rb CHANGED
@@ -333,7 +333,7 @@ module ZooKeeper
333
333
  req = Proto::GetDataRequest.new(:path => path, :watch => watch)
334
334
 
335
335
  queue_request(req,:get,4,Proto::GetDataResponse,:data,watch) do | response |
336
- blk.call( response.stat, response.data.to_s)
336
+ blk.call( response.stat, response.data.value)
337
337
  end
338
338
  end
339
339
 
@@ -329,7 +329,7 @@ module ZooKeeper
329
329
  req = Proto::ConnectRequest.new( :timeout => timeout )
330
330
  req.last_zxid_seen = @last_zxid_seen if @last_zxid_seen
331
331
  req.session_id = @session_id if @session_id
332
- req.passwd = @session_passwd if @session_passwd
332
+ req.passwd = @session_passwd || ""
333
333
  conn.send_records(req)
334
334
  end
335
335
 
@@ -1,5 +1,5 @@
1
1
 
2
2
  module ZooKeeper
3
3
  # Major/Minor numbers track zookeeper itself, final digit is our build number
4
- VERSION = "3.4.4.rc4"
4
+ VERSION = "3.4.4.rc5"
5
5
  end
data/spec/bindata_spec.rb CHANGED
@@ -5,6 +5,48 @@ class ZKBTest < BinData::Record
5
5
  zk_boolean :bool
6
6
  end
7
7
 
8
+ class ZKBufferTest < BinData::Record
9
+ zk_buffer :buff
10
+ end
11
+ class ZKStringTest < BinData::Record
12
+ zk_string :str
13
+ end
14
+
15
+ describe ZK::ZKBuffer do
16
+
17
+ it "should read null values" do
18
+ hex = "ffffffff"
19
+ bin = [ hex ].pack("H*")
20
+
21
+ buffer = ZKBufferTest.read(bin)
22
+
23
+ buffer.buff.should == nil
24
+ buffer.buff.value.should be_nil
25
+ end
26
+
27
+ it "should write null values" do
28
+ buffer = ZK::ZKBuffer.new(nil)
29
+ buffer.value.should be_nil
30
+ buffer.to_binary_s.should == [ "ffffffff" ].pack("H*")
31
+ end
32
+
33
+ it "should read non null values as binary strings"
34
+ it "should write non null values"
35
+ it "should write encoded calues as binary strings"
36
+ end
37
+
38
+ describe ZK::ZKString do
39
+ it "should produce UTF8 encoded strings" do
40
+
41
+ hex = "000000086162636465666768"
42
+ bin = [ hex ].pack("H*")
43
+ zk_string = ZKStringTest.read(bin)
44
+ zk_string.str.should == "abcdefgh"
45
+ zk_string.str.encoding.name.should == "UTF-8"
46
+
47
+ end
48
+ end
49
+
8
50
  describe ZK::ZKBoolean do
9
51
 
10
52
  it "should behave like 'false' after reading 00" do
data/spec/shared/basic.rb CHANGED
@@ -37,6 +37,25 @@ shared_examples_for "basic integration" do
37
37
  @zk.exists?("/zkruby/rspec").should be_false
38
38
  end
39
39
 
40
+ it "should differentiate null data from empty strings" do
41
+ path = @zk.create("/zkruby/rspec",nil,ZK::ACL_OPEN_UNSAFE,:ephemeral)
42
+ stat,data = @zk.get(path)
43
+ data.should be_nil
44
+ # this isn't very helpful
45
+ stat.data_length.should == 0
46
+
47
+ @zk.set(path,"",-1)
48
+ stat,data = @zk.get(path)
49
+ data.should == ""
50
+ stat.data_length.should == 0
51
+
52
+ @zk.set(path,nil,-1)
53
+ stat,data = @zk.get(path)
54
+ data.should be_nil
55
+ # this isn't very helpful
56
+ stat.data_length.should == 0
57
+ end
58
+
40
59
  it "should accept -1 to delete any version" do
41
60
  path = @zk.create("/zkruby/rspec","someData",ZK::ACL_OPEN_UNSAFE,:ephemeral)
42
61
  @zk.delete("/zkruby/rspec",-1)
data/zkruby.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  # Yard options in .yardopts
22
22
 
23
23
  s.add_dependency 'slf4r' , '~> 0.4.2'
24
- s.add_dependency 'bindata', '~> 1.4.1'
24
+ s.add_dependency 'bindata', '~> 1.8.2'
25
25
 
26
26
  s.add_development_dependency 'eventmachine', '>= 0.12.10'
27
27
  s.add_development_dependency 'empathy', '>=0.1.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zkruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.4.rc4
4
+ version: 3.4.4.rc5
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-27 00:00:00.000000000 Z
12
+ date: 2014-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: slf4r
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 1.4.1
37
+ version: 1.8.2
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 1.4.1
45
+ version: 1.8.2
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: eventmachine
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -253,6 +253,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
253
  - - ! '>='
254
254
  - !ruby/object:Gem::Version
255
255
  version: '0'
256
+ segments:
257
+ - 0
258
+ hash: -2894475851857234874
256
259
  required_rubygems_version: !ruby/object:Gem::Requirement
257
260
  none: false
258
261
  requirements:
@@ -261,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
261
264
  version: 1.3.1
262
265
  requirements: []
263
266
  rubyforge_project:
264
- rubygems_version: 1.8.25
267
+ rubygems_version: 1.8.23
265
268
  signing_key:
266
269
  specification_version: 3
267
270
  summary: Pure Ruby language binding for ZooKeeper