dcell 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.gitignore +2 -0
  2. data/.rspec +4 -0
  3. data/CHANGES.md +8 -0
  4. data/Gemfile +2 -0
  5. data/README.md +209 -0
  6. data/Rakefile +3 -0
  7. data/benchmarks/messaging.rb +67 -0
  8. data/benchmarks/receiver.rb +37 -0
  9. data/dcell.gemspec +10 -3
  10. data/lib/celluloid/README +8 -0
  11. data/lib/celluloid/zmq.rb +28 -0
  12. data/lib/celluloid/zmq/mailbox.rb +13 -0
  13. data/lib/celluloid/zmq/reactor.rb +74 -0
  14. data/lib/dcell.rb +92 -2
  15. data/lib/dcell/actor_proxy.rb +4 -0
  16. data/lib/dcell/application.rb +6 -0
  17. data/lib/dcell/celluloid_ext.rb +57 -0
  18. data/lib/dcell/directory.rb +23 -0
  19. data/lib/dcell/global.rb +23 -0
  20. data/lib/dcell/mailbox_proxy.rb +61 -0
  21. data/lib/dcell/messages.rb +67 -0
  22. data/lib/dcell/node.rb +120 -0
  23. data/lib/dcell/registries/redis_adapter.rb +86 -0
  24. data/lib/dcell/registries/zk_adapter.rb +122 -0
  25. data/lib/dcell/responses.rb +16 -0
  26. data/lib/dcell/router.rb +71 -0
  27. data/lib/dcell/rspec.rb +1 -0
  28. data/lib/dcell/server.rb +80 -0
  29. data/lib/dcell/version.rb +1 -1
  30. data/spec/celluloid/zmq/mailbox_spec.rb +6 -0
  31. data/spec/dcell/actor_proxy_spec.rb +60 -0
  32. data/spec/dcell/celluloid_ext_spec.rb +21 -0
  33. data/spec/dcell/directory_spec.rb +8 -0
  34. data/spec/dcell/global_spec.rb +21 -0
  35. data/spec/dcell/node_spec.rb +23 -0
  36. data/spec/dcell/registries/redis_adapter_spec.rb +6 -0
  37. data/spec/dcell/registries/zk_adapter_spec.rb +11 -0
  38. data/spec/spec_helper.rb +16 -0
  39. data/spec/support/helpers.rb +40 -0
  40. data/spec/support/registry_examples.rb +35 -0
  41. data/spec/test_node.rb +33 -0
  42. data/tasks/rspec.task +7 -0
  43. data/tasks/zookeeper.task +58 -0
  44. metadata +111 -7
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Celluloid, "extensions" do
4
+ before do
5
+ class WillKane
6
+ include Celluloid
7
+ end
8
+ @marshal = WillKane.new
9
+ end
10
+
11
+ it "marshals Celluloid::ActorProxy objects" do
12
+ string = Marshal.dump(@marshal)
13
+ Marshal.load(string).should be_alive
14
+ end
15
+
16
+ it "marshals Celluloid::Mailbox objects" do
17
+ @marshal.mailbox.should be_a(Celluloid::Mailbox)
18
+ string = Marshal.dump(@marshal.mailbox)
19
+ Marshal.load(string).should be_alive
20
+ end
21
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe DCell::Directory do
4
+ it "stores node addresses" do
5
+ DCell::Directory["foobar"] = "tcp://localhost:1870"
6
+ DCell::Directory["foobar"].should == "tcp://localhost:1870"
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe DCell::Global do
4
+ it "stores values" do
5
+ DCell::Global[:the_answer] = 42
6
+ DCell::Global[:the_answer].should == 42
7
+
8
+ # Double check the global value is available on all nodes
9
+ node = DCell::Node['test_node']
10
+ node[:test_actor].the_answer.should == 42
11
+ end
12
+
13
+ it "stores the keys of all globals" do
14
+ DCell::Global[:foo] = 1
15
+ DCell::Global[:bar] = 2
16
+ DCell::Global[:baz] = 3
17
+
18
+ keys = DCell::Global.keys
19
+ [:foo, :bar, :baz].each { |key| keys.should include key }
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe DCell::Node do
4
+ before do
5
+ @node = DCell::Node['test_node']
6
+ @node.id.should == 'test_node'
7
+ end
8
+
9
+ it "finds all available nodes" do
10
+ nodes = DCell::Node.all
11
+ nodes.should include(DCell.me)
12
+ end
13
+
14
+ it "finds remote actors" do
15
+ actor = @node[:test_actor]
16
+ actor.value.should == 42
17
+ end
18
+
19
+ it "lists remote actors" do
20
+ @node.actors.should include :test_actor
21
+ @node.all.should include :test_actor
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe DCell::Registry::RedisAdapter do
4
+ subject { DCell::Registry::RedisAdapter.new :env => 'test' }
5
+ it_behaves_like "a DCell registry"
6
+ end
@@ -0,0 +1,11 @@
1
+ # The Zookeeper CRuby dependency is pretty annoying :(
2
+ # Disabling until this can be spun off into a separate gem
3
+ =begin
4
+ require 'spec_helper'
5
+ require 'dcell/registries/zk_adapter'
6
+
7
+ describe DCell::Registry::ZkAdapter do
8
+ subject { DCell::Registry::ZkAdapter.new :server => 'localhost', :env => 'test' }
9
+ it_behaves_like "a DCell registry"
10
+ end
11
+ =end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+
5
+ require 'dcell'
6
+ Dir['./spec/support/*.rb'].map { |f| require f }
7
+
8
+ DCell.setup
9
+ DCell.run!
10
+
11
+ TestNode.start
12
+ TestNode.wait_until_ready
13
+
14
+ at_exit do
15
+ TestNode.stop
16
+ end
@@ -0,0 +1,40 @@
1
+ # For Gem.ruby, and almost certainly already loaded
2
+ require 'rubygems'
3
+
4
+ module TestNode
5
+ PORT = 21264
6
+
7
+ def self.start
8
+ @pid = Process.spawn Gem.ruby, File.expand_path("../../test_node.rb", __FILE__)
9
+ end
10
+
11
+ def self.wait_until_ready
12
+ STDERR.print "Waiting for test node to start up..."
13
+
14
+ socket = nil
15
+ 30.times do
16
+ begin
17
+ socket = TCPSocket.open("127.0.0.1", PORT)
18
+ break if socket
19
+ rescue Errno::ECONNREFUSED
20
+ STDERR.print "."
21
+ sleep 1
22
+ end
23
+ end
24
+
25
+ if socket
26
+ STDERR.puts " done!"
27
+ socket.close
28
+ else
29
+ STDERR.puts " FAILED!"
30
+ raise "couldn't connect to test node!"
31
+ end
32
+ end
33
+
34
+ def self.stop
35
+ Process.kill 9, @pid
36
+ rescue Errno::ESRCH
37
+ ensure
38
+ Process.wait @pid rescue nil
39
+ end
40
+ end
@@ -0,0 +1,35 @@
1
+ shared_context "a DCell registry" do
2
+ context "node registry" do
3
+ before :each do
4
+ subject.clear_nodes
5
+ end
6
+
7
+ it "stores node addresses" do
8
+ address = "tcp://localhost:7777"
9
+
10
+ subject.set_node("foobar", address)
11
+ subject.get_node("foobar").should == address
12
+ end
13
+
14
+ it "stores the IDs of all nodes" do
15
+ subject.set_node("foobar", "tcp://localhost:7777")
16
+ subject.nodes.should include "foobar"
17
+ end
18
+ end
19
+
20
+ context "global registry" do
21
+ before :each do
22
+ subject.clear_globals
23
+ end
24
+
25
+ it "stores values" do
26
+ subject.set_global("foobar", [1,2,3])
27
+ subject.get_global("foobar").should == [1,2,3]
28
+ end
29
+
30
+ it "stores the keys of all globals" do
31
+ subject.set_global("foobar", true)
32
+ subject.global_keys.should include "foobar"
33
+ end
34
+ end
35
+ end
data/spec/test_node.rb ADDED
@@ -0,0 +1,33 @@
1
+ # The DCell specs start a completely separate Ruby VM running this code
2
+ # for complete integration testing using 0MQ over TCP
3
+
4
+ require 'rubygems'
5
+ require 'bundler'
6
+ Bundler.setup
7
+
8
+ require 'dcell'
9
+ DCell.setup :id => 'test_node', :addr => 'tcp://127.0.0.1:21264'
10
+
11
+ class TestActor
12
+ include Celluloid
13
+ attr_reader :value
14
+
15
+ def initialize
16
+ @value = 42
17
+ end
18
+
19
+ def the_answer
20
+ DCell::Global[:the_answer]
21
+ end
22
+
23
+ def crash
24
+ raise "the spec purposely crashed me :("
25
+ end
26
+ end
27
+
28
+ class TestApplication < Celluloid::Application
29
+ supervise DCell::Application
30
+ supervise TestActor, :as => :test_actor
31
+ end
32
+
33
+ TestApplication.run
data/tasks/rspec.task ADDED
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new
4
+
5
+ RSpec::Core::RakeTask.new(:rcov) do |task|
6
+ task.rcov = true
7
+ end
@@ -0,0 +1,58 @@
1
+ require 'rake/clean'
2
+
3
+ namespace :zookeeper do
4
+ ZK_VERSION = "3.3.3"
5
+ ZK_TARBALL = "zookeeper-#{ZK_VERSION}.tar.gz"
6
+
7
+ task :download => "tmp/#{ZK_TARBALL}"
8
+ directory 'tmp'
9
+
10
+ file "tmp/#{ZK_TARBALL}" => "tmp" do
11
+ puts "*** Downloading Zookeeper"
12
+ sh "curl http://archive.apache.org/dist/zookeeper/zookeeper-#{ZK_VERSION}/#{ZK_TARBALL} -o tmp/#{ZK_TARBALL}"
13
+ end
14
+
15
+ task :install => :download do
16
+ puts "*** Unpacking Zookeeper"
17
+
18
+ rm_rf "zookeeper" if File.exists? "zookeeper"
19
+ sh "tar -zxvf tmp/#{ZK_TARBALL}"
20
+ mv "zookeeper-#{ZK_VERSION}", "zookeeper"
21
+ home = File.expand_path("../../zookeeper", __FILE__)
22
+
23
+ # Create base configuration
24
+ data = File.join(home, "data")
25
+ mkdir_p data
26
+ config = File.join(home, "conf", "zoo.cfg")
27
+ rm_r File.join(home, "conf", "zoo_sample.cfg")
28
+
29
+ File.open(config, "w") do |file|
30
+ # Maybe some kind soul will move this ugly heredoc into a template
31
+ file << <<-ZK_CONFIG
32
+ # The number of milliseconds of each tick
33
+ tickTime=2000
34
+ # The number of ticks that the initial
35
+ # synchronization phase can take
36
+ initLimit=10
37
+ # The number of ticks that can pass between
38
+ # sending a request and getting an acknowledgement
39
+ syncLimit=5
40
+ # the directory where the snapshot is stored.
41
+ dataDir=#{data}
42
+ # the port at which the clients will connect
43
+ clientPort=2181
44
+ ZK_CONFIG
45
+ end
46
+ end
47
+
48
+ task :start => :zookeeper do
49
+ puts "*** Starting Zookeeper"
50
+ sh "cd zookeeper && bin/zkServer.sh start"
51
+ end
52
+ end
53
+
54
+ file 'zookeeper' do
55
+ Rake::Task['zookeeper:install'].invoke
56
+ end
57
+
58
+ CLEAN.include "tmp", "zookeeper"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dcell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-26 00:00:00.000000000Z
12
+ date: 2011-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: celluloid
16
- requirement: &70249065627280 !ruby/object:Gem::Requirement
16
+ requirement: &70327976661520 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.6.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70327976661520
25
+ - !ruby/object:Gem::Dependency
26
+ name: ffi
27
+ requirement: &70327976682840 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
@@ -21,10 +32,32 @@ dependencies:
21
32
  version: '0'
22
33
  type: :runtime
23
34
  prerelease: false
24
- version_requirements: *70249065627280
35
+ version_requirements: *70327976682840
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: ffi-rzmq
27
- requirement: &70249065626860 !ruby/object:Gem::Requirement
38
+ requirement: &70327976681680 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70327976681680
47
+ - !ruby/object:Gem::Dependency
48
+ name: redis
49
+ requirement: &70327976681260 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70327976681260
58
+ - !ruby/object:Gem::Dependency
59
+ name: redis-namespace
60
+ requirement: &70327976680800 !ruby/object:Gem::Requirement
28
61
  none: false
29
62
  requirements:
30
63
  - - ! '>='
@@ -32,7 +65,29 @@ dependencies:
32
65
  version: '0'
33
66
  type: :runtime
34
67
  prerelease: false
35
- version_requirements: *70249065626860
68
+ version_requirements: *70327976680800
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: &70327976680260 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70327976680260
80
+ - !ruby/object:Gem::Dependency
81
+ name: rspec
82
+ requirement: &70327976679760 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: 2.7.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70327976679760
36
91
  description: DCell is an distributed object framework based on Celluloid built on
37
92
  0MQ and Zookeeper
38
93
  email:
@@ -42,11 +97,48 @@ extensions: []
42
97
  extra_rdoc_files: []
43
98
  files:
44
99
  - .gitignore
100
+ - .rspec
101
+ - CHANGES.md
45
102
  - Gemfile
103
+ - README.md
46
104
  - Rakefile
105
+ - benchmarks/messaging.rb
106
+ - benchmarks/receiver.rb
47
107
  - dcell.gemspec
108
+ - lib/celluloid/README
109
+ - lib/celluloid/zmq.rb
110
+ - lib/celluloid/zmq/mailbox.rb
111
+ - lib/celluloid/zmq/reactor.rb
48
112
  - lib/dcell.rb
113
+ - lib/dcell/actor_proxy.rb
114
+ - lib/dcell/application.rb
115
+ - lib/dcell/celluloid_ext.rb
116
+ - lib/dcell/directory.rb
117
+ - lib/dcell/global.rb
118
+ - lib/dcell/mailbox_proxy.rb
119
+ - lib/dcell/messages.rb
120
+ - lib/dcell/node.rb
121
+ - lib/dcell/registries/redis_adapter.rb
122
+ - lib/dcell/registries/zk_adapter.rb
123
+ - lib/dcell/responses.rb
124
+ - lib/dcell/router.rb
125
+ - lib/dcell/rspec.rb
126
+ - lib/dcell/server.rb
49
127
  - lib/dcell/version.rb
128
+ - spec/celluloid/zmq/mailbox_spec.rb
129
+ - spec/dcell/actor_proxy_spec.rb
130
+ - spec/dcell/celluloid_ext_spec.rb
131
+ - spec/dcell/directory_spec.rb
132
+ - spec/dcell/global_spec.rb
133
+ - spec/dcell/node_spec.rb
134
+ - spec/dcell/registries/redis_adapter_spec.rb
135
+ - spec/dcell/registries/zk_adapter_spec.rb
136
+ - spec/spec_helper.rb
137
+ - spec/support/helpers.rb
138
+ - spec/support/registry_examples.rb
139
+ - spec/test_node.rb
140
+ - tasks/rspec.task
141
+ - tasks/zookeeper.task
50
142
  homepage: http://github.com/tarcieri/dcell
51
143
  licenses: []
52
144
  post_install_message:
@@ -71,5 +163,17 @@ rubygems_version: 1.8.10
71
163
  signing_key:
72
164
  specification_version: 3
73
165
  summary: An asynchronous distributed object framework based on Celluloid
74
- test_files: []
166
+ test_files:
167
+ - spec/celluloid/zmq/mailbox_spec.rb
168
+ - spec/dcell/actor_proxy_spec.rb
169
+ - spec/dcell/celluloid_ext_spec.rb
170
+ - spec/dcell/directory_spec.rb
171
+ - spec/dcell/global_spec.rb
172
+ - spec/dcell/node_spec.rb
173
+ - spec/dcell/registries/redis_adapter_spec.rb
174
+ - spec/dcell/registries/zk_adapter_spec.rb
175
+ - spec/spec_helper.rb
176
+ - spec/support/helpers.rb
177
+ - spec/support/registry_examples.rb
178
+ - spec/test_node.rb
75
179
  has_rdoc: