ruby_skynet 0.8.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,200 @@
1
+ # Allow test to be run in-place without requiring a gem install
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'shoulda'
7
+ require 'ruby_skynet/zookeeper'
8
+ require 'date'
9
+
10
+ # NOTE:
11
+ # This test assumes that ZooKeeper is running locally on the default port
12
+
13
+ # Register an appender if one is not already registered
14
+ SemanticLogger.default_level = :trace
15
+ SemanticLogger.add_appender('test.log') if SemanticLogger.appenders.size == 0
16
+
17
+ # Unit Test for RubySkynet::Zookeeper::Registry
18
+ class ZookeeperRegistryTest < Test::Unit::TestCase
19
+ context RubySkynet::Zookeeper::Registry do
20
+ setup do
21
+ @date = Date.parse('2013-04-04')
22
+ @time = Time.at(1365102658)
23
+ @test_data = {
24
+ 'bar' => 'test',
25
+ 'one' => 'one',
26
+ 'string_with_underscores' => 'and_a_value',
27
+ 'two' => :two,
28
+ 'integer' => 10,
29
+ 'float' => 10.5,
30
+ 'date' => @date,
31
+ 'time' => @time,
32
+ 'false' => false,
33
+ 'true' => true,
34
+ 'child' => { :symbol_with_underscores => :and_a_value, :this => 'is', :an => ['array', :symbol, :smallest => {'a' => 'b', :c => :d}]}
35
+ }
36
+ @test_data['all_types'] = @test_data.dup
37
+ end
38
+
39
+ context "serialization" do
40
+ setup do
41
+ @json = {
42
+ 'bar' => 'test',
43
+ 'one' => 'one',
44
+ 'string_with_underscores' => 'and_a_value',
45
+ 'two' => ':two',
46
+ 'integer' => '10',
47
+ 'float' => '10.5',
48
+ 'date' => @date.to_s,
49
+ 'time' => @time.to_s,
50
+ 'false' => 'false',
51
+ 'true' => 'true',
52
+ 'child' => "{\":symbol_with_underscores\":\":and_a_value\",\":this\":\"is\",\":an\":[\"array\",\":symbol\",{\":smallest\":{\"a\":\"b\",\":c\":\":d\"}}]}",
53
+ 'all_types' => "{\"bar\":\"test\",\"one\":\"one\",\"string_with_underscores\":\"and_a_value\",\"two\":\":two\",\"integer\":\"10\",\"float\":\"10.5\",\"date\":\"2013-04-04\",\"time\":\"2013-04-04 15:10:58 -0400\",\"false\":\"false\",\"true\":\"true\",\"child\":{\":symbol_with_underscores\":\":and_a_value\",\":this\":\"is\",\":an\":[\"array\",\":symbol\",{\":smallest\":{\"a\":\"b\",\":c\":\":d\"}}]}}"
54
+ }
55
+ end
56
+
57
+ should ".serialize" do
58
+ @test_data.each_pair do |k,v|
59
+ assert_equal @json[k], RubySkynet::Zookeeper::Json::Serializer.serialize(v), "Key: #{k}"
60
+ end
61
+ end
62
+
63
+ should ".deserialize" do
64
+ @json.each_pair do |k,v|
65
+ assert_equal @test_data[k], RubySkynet::Zookeeper::Json::Deserializer.deserialize(v), "Key: #{k}"
66
+ end
67
+ end
68
+ end
69
+
70
+ context "with registry" do
71
+ setup do
72
+ @registry = RubySkynet::Zookeeper::Registry.new(:root => "/registrytest")
73
+ @registry.each_pair {|k,v, ver, num_children| @registry.delete(k) if num_children == 0}
74
+ @test_data.each_pair {|k,v| @registry[k] = v}
75
+ @path = 'a/b/c/d/e/f/g/h'
76
+ @registry[@path] = 'hello'
77
+ end
78
+
79
+ def teardown
80
+ if @registry
81
+ @registry.each_pair {|k,v, ver, num_children| @registry.delete(k) if num_children == 0}
82
+ # Allow callbacks to complete so that errors are not generated on close
83
+ sleep 0.1
84
+ @registry.close
85
+ end
86
+ end
87
+
88
+ should "#[]" do
89
+ @test_data.each_pair do |k,v|
90
+ assert_equal v, @registry[k], "Expected #{k}=>#{v}, #{@registry.to_h.inspect}"
91
+ end
92
+ end
93
+
94
+ should "#each_pair" do
95
+ h = {}
96
+ @registry.each_pair {|k,v| h[k] = v}
97
+ assert_hash_equal @test_data, h
98
+ end
99
+
100
+ should "#to_h" do
101
+ assert_hash_equal @test_data, @registry.to_h
102
+ end
103
+
104
+ should "#[]=" do
105
+ @registry['three'] = 'value'
106
+ # Give Zookeeper time to send back the change
107
+ sleep 0.3
108
+ result = @registry['three']
109
+ assert_equal 'value', result
110
+ end
111
+
112
+ should "#delete parent paths when no other leaf nodes exist" do
113
+ @registry.delete(@path)
114
+ assert_equal nil, @registry['a']
115
+ end
116
+
117
+ [nil, '*'].each do |monitor_path|
118
+ context "with monitor_path:#{monitor_path}" do
119
+ should "callback on update" do
120
+ updated_revision = nil
121
+ updated_path = nil
122
+ updated_value = nil
123
+ @registry.on_update(monitor_path||'bar') do |path, value, revision|
124
+ updated_revision = revision
125
+ updated_path = path
126
+ updated_value = value
127
+ end
128
+ # Allow monitoring thread to start
129
+ sleep 0.1
130
+ @registry['bar'] = 'updated'
131
+ # Allow Zookeeper to send back the change
132
+ sleep 0.3
133
+ assert_equal 'bar', updated_path
134
+ assert_equal 'updated', updated_value
135
+ assert_equal true, updated_revision > 0
136
+ end
137
+
138
+ should "callback on delete" do
139
+ deleted_path = nil
140
+ @registry.on_delete(monitor_path||'bar') do |path, revision|
141
+ deleted_path = path
142
+ end
143
+ # Allow monitoring thread to start
144
+ sleep 0.1
145
+ # Allow Zookeeper to send back the change
146
+ @registry.delete('bar')
147
+ sleep 0.3
148
+ assert_equal 'bar', deleted_path
149
+ end
150
+ end
151
+ end
152
+
153
+ ['other', 'one'].each do |monitor_path|
154
+ context "with monitor_path:#{monitor_path}" do
155
+ should "not callback on update" do
156
+ updated_path = nil
157
+ updated_value = nil
158
+ @registry.on_update(monitor_path) do |path, value|
159
+ updated_path = path
160
+ updated_value = value
161
+ end
162
+ # Allow monitoring thread to start
163
+ sleep 0.1
164
+ @registry['bar'] = 'updated'
165
+ # Allow Zookeeper to send back the change
166
+ sleep 0.3
167
+ assert_equal nil, updated_path
168
+ assert_equal nil, updated_value
169
+ end
170
+
171
+ should "not callback on delete" do
172
+ deleted_path = nil
173
+ @registry.on_delete(monitor_path) do |path|
174
+ deleted_path = path
175
+ end
176
+ # Allow monitoring thread to start
177
+ sleep 0.1
178
+ # Allow Zookeeper to send back the change
179
+ @registry.delete('bar')
180
+ sleep 0.3
181
+ assert_equal nil, deleted_path
182
+ end
183
+ end
184
+ end
185
+
186
+ end
187
+ end
188
+
189
+ # Verify that two hashes match
190
+ def assert_hash_equal(expected, actual)
191
+ expected.each_pair do |k,v|
192
+ if v.is_a?(Hash)
193
+ assert_hash_equal(v, actual[k])
194
+ else
195
+ assert_equal expected[k], actual[k], "Expected: #{expected.inspect}, Actual:#{actual.inspect}"
196
+ end
197
+ end
198
+ end
199
+
200
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_skynet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-04 00:00:00.000000000 Z
11
+ date: 2013-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semantic_logger
@@ -67,47 +67,33 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.3.0
69
69
  - !ruby/object:Gem::Dependency
70
- name: sync_attr
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '>='
74
- - !ruby/object:Gem::Version
75
- version: 1.0.0
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: 1.0.0
83
- - !ruby/object:Gem::Dependency
84
- name: ruby_doozer
70
+ name: zookeeper
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - '>='
88
74
  - !ruby/object:Gem::Version
89
- version: 0.7.0
75
+ version: 1.4.4
90
76
  type: :runtime
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - '>='
95
81
  - !ruby/object:Gem::Version
96
- version: 0.7.0
82
+ version: 1.4.4
97
83
  - !ruby/object:Gem::Dependency
98
- name: gene_pool
84
+ name: sync_attr
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - '>='
102
88
  - !ruby/object:Gem::Version
103
- version: 1.3.0
89
+ version: 1.0.0
104
90
  type: :runtime
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
94
  - - '>='
109
95
  - !ruby/object:Gem::Version
110
- version: 1.3.0
96
+ version: 1.0.0
111
97
  description: Ruby Client for invoking Skynet services
112
98
  email:
113
99
  - reidmo@gmail.com
@@ -132,15 +118,22 @@ files:
132
118
  - lib/ruby_skynet/exceptions.rb
133
119
  - lib/ruby_skynet/railtie.rb
134
120
  - lib/ruby_skynet/railties/ruby_skynet.rake
121
+ - lib/ruby_skynet/registry.rb
135
122
  - lib/ruby_skynet/ruby_skynet.rb
136
123
  - lib/ruby_skynet/server.rb
137
124
  - lib/ruby_skynet/service.rb
138
125
  - lib/ruby_skynet/service_registry.rb
139
126
  - lib/ruby_skynet/version.rb
140
- - test.sh
127
+ - lib/ruby_skynet/zookeeper.rb
128
+ - lib/ruby_skynet/zookeeper/cached_registry.rb
129
+ - lib/ruby_skynet/zookeeper/extensions/java_base.rb
130
+ - lib/ruby_skynet/zookeeper/json/deserializer.rb
131
+ - lib/ruby_skynet/zookeeper/json/serializer.rb
132
+ - lib/ruby_skynet/zookeeper/registry.rb
141
133
  - test/client_test.rb
142
134
  - test/service_registry_test.rb
143
135
  - test/service_test.rb
136
+ - test/zookeeper_registry_test.rb
144
137
  homepage: https://github.com/ClarityServices/ruby_skynet
145
138
  licenses:
146
139
  - Apache License V2.0
data/test.sh DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- # This script require RVM to be installed and for ruby and jruby to be installed
3
- [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
4
- rvm use ruby@ruby_skynet --create
5
- rake test
6
- rvm use jruby@ruby_skynet --create
7
- rake test