arya-pandemic 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ class HandlerTest < Test::Unit::TestCase
4
+ include TestHelper
5
+
6
+ context "with a basic echo processor" do
7
+ setup do
8
+ echo = Class.new do
9
+ def process(body)
10
+ body.reverse
11
+ end
12
+ end
13
+
14
+ @processor = Pandemic::ServerSide::Processor.new(echo)
15
+ end
16
+
17
+ should "have a running child process" do
18
+ assert !@processor.closed?
19
+ end
20
+
21
+ should "close running child" do
22
+ assert !@processor.closed?
23
+ @processor.close
24
+ assert @processor.closed?
25
+ end
26
+
27
+ should "echo back" do
28
+ 10.times do |i| # just to test the loop part
29
+ assert_equal "#{i} dlrow olleh", @processor.process("hello world #{i}")
30
+ end
31
+ end
32
+ end
33
+ end
data/test/server_test.rb CHANGED
@@ -4,19 +4,17 @@ class ServerTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
 
6
6
  should "initialize peers" do
7
- Pandemic::ServerSide::Config.expects(:bind_to).at_least_once.returns("localhost:4000")
8
7
  Pandemic::ServerSide::Config.expects(:servers).returns(["localhost:4000", "localhost:4001"])
9
8
  Pandemic::ServerSide::Peer.expects(:new).with("localhost:4001", is_a(Pandemic::ServerSide::Server))
10
- @server = Pandemic::ServerSide::Server.new
9
+ @server = Pandemic::ServerSide::Server.new("localhost:4000")
11
10
  end
12
11
 
13
12
  context "with a server" do
14
13
  setup do
15
- Pandemic::ServerSide::Config.expects(:bind_to).at_least_once.returns("localhost:4000")
16
14
  Pandemic::ServerSide::Config.expects(:servers).returns(["localhost:4000", "localhost:4001"])
17
15
  @peer = mock()
18
16
  Pandemic::ServerSide::Peer.expects(:new).with("localhost:4001", is_a(Pandemic::ServerSide::Server)).returns(@peer)
19
- @server = Pandemic::ServerSide::Server.new
17
+ @server = Pandemic::ServerSide::Server.new("localhost:4000")
20
18
  end
21
19
 
22
20
  should "start a TCPServer, and connect to peers" do
@@ -27,7 +25,7 @@ class ServerTest < Test::Unit::TestCase
27
25
  @tcpserver.expects(:accept).twice.returns(nil).then.raises(Pandemic::ServerSide::Server::StopServer)
28
26
  @tcpserver.expects(:close)
29
27
  @peer.expects(:disconnect)
30
- @server.handler = mock()
28
+ @server.handler = mock(:new)
31
29
  @server.start
32
30
  wait_for_threads(ignore_threads)
33
31
  end
@@ -52,7 +50,7 @@ class ServerTest < Test::Unit::TestCase
52
50
  @peer.expects(:disconnect)
53
51
  client.expects(:listen).returns(client)
54
52
  client.expects(:close).at_most_once # optional due to threaded nature, this may not actually happen
55
- @server.handler = mock()
53
+ @server.handler = mock(:new)
56
54
  @server.start
57
55
  wait_for_threads(ignore_threads)
58
56
  end
@@ -74,21 +72,25 @@ class ServerTest < Test::Unit::TestCase
74
72
  @peer.expects(:host).returns("localhost")
75
73
  @peer.expects(:port).returns(4001)
76
74
  @peer.expects(:add_incoming_connection).with(@conn)
77
- @server.handler = mock()
75
+ @server.handler = mock(:new)
78
76
 
79
77
  @server.start
80
78
  wait_for_threads(ignore_threads)
81
79
  end
82
80
 
83
81
  should "call process on handler" do
82
+ handler_class = mock()
84
83
  handler = mock()
84
+ handler_class.expects(:new).once.returns(handler)
85
85
  handler.expects(:process).with("body")
86
- @server.handler = handler
86
+ @server.handler = handler_class
87
87
  @server.process("body")
88
88
  end
89
89
 
90
90
  should "map request, distribute to peers, and reduce" do
91
+ handler_class = mock()
91
92
  handler = mock()
93
+ handler_class.expects(:new).once.returns(handler)
92
94
  request = mock()
93
95
  request.expects(:hash).at_least_once.returns("abcddef134123")
94
96
  @peer.expects(:connected?).returns(true)
@@ -102,7 +104,7 @@ class ServerTest < Test::Unit::TestCase
102
104
  request.expects(:wait_for_responses).once
103
105
  handler.expects(:reduce).with(request)
104
106
 
105
- @server.handler = handler
107
+ @server.handler = handler_class
106
108
 
107
109
  @server.handle_client_request(request)
108
110
  # wait_for_threads
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arya-pandemic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arya Asemanfar
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-10 00:00:00 -07:00
12
+ date: 2009-05-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -50,12 +50,18 @@ extra_rdoc_files:
50
50
  - lib/pandemic/server_side/config.rb
51
51
  - lib/pandemic/server_side/handler.rb
52
52
  - lib/pandemic/server_side/peer.rb
53
+ - lib/pandemic/server_side/processor.rb
53
54
  - lib/pandemic/server_side/request.rb
54
55
  - lib/pandemic/server_side/server.rb
55
56
  - lib/pandemic/util.rb
56
57
  - lib/pandemic.rb
57
58
  - README.markdown
58
59
  files:
60
+ - examples/client/client.rb
61
+ - examples/client/constitution.txt
62
+ - examples/client/pandemic_client.yml
63
+ - examples/server/pandemic_server.yml
64
+ - examples/server/word_count_server.rb
59
65
  - lib/pandemic/client_side/cluster_connection.rb
60
66
  - lib/pandemic/client_side/config.rb
61
67
  - lib/pandemic/client_side/connection.rb
@@ -67,21 +73,23 @@ files:
67
73
  - lib/pandemic/server_side/config.rb
68
74
  - lib/pandemic/server_side/handler.rb
69
75
  - lib/pandemic/server_side/peer.rb
76
+ - lib/pandemic/server_side/processor.rb
70
77
  - lib/pandemic/server_side/request.rb
71
78
  - lib/pandemic/server_side/server.rb
72
79
  - lib/pandemic/util.rb
73
80
  - lib/pandemic.rb
74
81
  - Manifest
75
82
  - MIT-LICENSE
76
- - pandemic.gemspec
77
83
  - Rakefile
78
84
  - README.markdown
85
+ - pandemic.gemspec
79
86
  - test/client_test.rb
80
87
  - test/connection_pool_test.rb
81
88
  - test/functional_test.rb
82
89
  - test/handler_test.rb
83
90
  - test/mutex_counter_test.rb
84
91
  - test/peer_test.rb
92
+ - test/processor_test.rb
85
93
  - test/server_test.rb
86
94
  - test/test_helper.rb
87
95
  - test/util_test.rb
@@ -123,6 +131,7 @@ test_files:
123
131
  - test/handler_test.rb
124
132
  - test/mutex_counter_test.rb
125
133
  - test/peer_test.rb
134
+ - test/processor_test.rb
126
135
  - test/server_test.rb
127
136
  - test/test_helper.rb
128
137
  - test/util_test.rb