arya-pandemic 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('pandemic', '0.5.1') do |p|
5
+ Echoe.new('pandemic', '0.5.2') do |p|
6
6
  p.description = "A framework for distributing work for real-time services and offline tasks."
7
7
  p.url = "https://github.com/arya/pandemic/"
8
8
  p.author = "Arya Asemanfar"
@@ -15,12 +15,12 @@ module Pandemic
15
15
  end
16
16
 
17
17
  def connect
18
- debug("Forced connection to peer")
18
+ # debug("Forced connection to peer")
19
19
  @connection_pool.connect
20
20
  end
21
21
 
22
22
  def disconnect
23
- debug("Disconnecting from peer")
23
+ # debug("Disconnecting from peer")
24
24
  @connection_pool.disconnect
25
25
  end
26
26
 
@@ -31,29 +31,41 @@ module Pandemic
31
31
  def client_request(request, body)
32
32
  # debug("Sending client's request to peer")
33
33
  # debug("Connection pool has #{@connection_pool.available_count} of #{@connection_pool.connections_count} connections available")
34
- # TODO: Consider adding back threads here if it will be faster that way in Ruby 1.9
35
- @connection_pool.with_connection do |connection|
36
- if connection && !connection.closed?
37
- @pending_requests.synchronize do
38
- @pending_requests[request.hash] = request
34
+
35
+ successful = true
36
+ @pending_requests.synchronize do
37
+ @pending_requests[request.hash] = request
38
+ end
39
+ begin
40
+ @connection_pool.with_connection do |connection|
41
+ if connection && !connection.closed?
42
+ # debug("Writing client's request")
43
+ connection.write("PROCESS #{request.hash} #{body.size}\n#{body}")
44
+ connection.flush
45
+ # debug("Finished writing client's request")
46
+ else
47
+ successful = false
39
48
  end
40
- # debug("Writing client's request")
41
- connection.write("PROCESS #{request.hash} #{body.size}\n#{body}")
42
- connection.flush
43
- # debug("Finished writing client's request")
44
- end # TODO: else? fail silently? reconnect?
49
+ end
50
+ rescue Exception
51
+ @pending_requests.synchronize { @pending_requests.delete(request.hash) }
52
+ raise
53
+ else
54
+ if !successful
55
+ @pending_requests.synchronize { @pending_requests.delete(request.hash) }
56
+ end
45
57
  end
46
58
  end
47
59
 
48
60
  def add_incoming_connection(conn)
49
- debug("Adding incoming connection")
61
+ # debug("Adding incoming connection")
50
62
 
51
63
  connect # if we're not connected, we should be
52
64
 
53
65
 
54
66
  thread = Thread.new(conn) do |connection|
55
67
  begin
56
- debug("Incoming connection thread started")
68
+ # debug("Incoming connection thread started")
57
69
  while @server.running
58
70
  # debug("Listening for incoming requests")
59
71
  request = connection.gets
@@ -71,7 +83,7 @@ module Pandemic
71
83
  rescue Exception => e
72
84
  warn("Unhandled exception in peer listener thread:\n#{e.inspect}\n#{e.backtrace.join("\n")}")
73
85
  ensure
74
- debug("Incoming connection closing")
86
+ # debug("Incoming connection closing")
75
87
  conn.close if conn && !conn.closed?
76
88
  @inc_threads_mutex.synchronize { @incoming_connection_listeners.delete(Thread.current)}
77
89
  if @incoming_connection_listeners.empty?
@@ -95,9 +107,9 @@ module Pandemic
95
107
  connection = TCPSocket.new(@host, @port)
96
108
  rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED => e
97
109
  connection = nil
98
- debug("Connection timeout or refused: #{e.inspect}")
110
+ # debug("Connection timeout or refused: #{e.inspect}")
99
111
  if retries == 0
100
- debug("Retrying connection")
112
+ # debug("Retrying connection")
101
113
  retries += 1
102
114
  sleep 0.01
103
115
  retry
data/pandemic.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{pandemic}
5
- s.version = "0.5.1"
5
+ s.version = "0.5.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Arya Asemanfar"]
9
- s.date = %q{2009-08-09}
9
+ s.date = %q{2009-08-11}
10
10
  s.description = %q{A framework for distributing work for real-time services and offline tasks.}
11
11
  s.email = %q{aryaasemanfar@gmail.com}
12
12
  s.extra_rdoc_files = ["lib/pandemic/client_side/cluster_connection.rb", "lib/pandemic/client_side/config.rb", "lib/pandemic/client_side/connection.rb", "lib/pandemic/client_side/connection_proxy.rb", "lib/pandemic/client_side/pandemize.rb", "lib/pandemic/connection_pool.rb", "lib/pandemic/mutex_counter.rb", "lib/pandemic/requests_per_second.rb", "lib/pandemic/server_side/client.rb", "lib/pandemic/server_side/config.rb", "lib/pandemic/server_side/handler.rb", "lib/pandemic/server_side/peer.rb", "lib/pandemic/server_side/processor.rb", "lib/pandemic/server_side/request.rb", "lib/pandemic/server_side/server.rb", "lib/pandemic/util.rb", "lib/pandemic.rb", "README.markdown"]
data/test/client_test.rb CHANGED
@@ -6,15 +6,20 @@ class ClientTest < Test::Unit::TestCase
6
6
  context "with a client object" do
7
7
  setup do
8
8
  @server = mock()
9
- @server.expects(:running).returns(true).then.returns(false)
9
+ @server.stubs(:client_closed)
10
+ @server.stubs(:handle_client_request)
11
+ @server.expects(:running).at_least_once.returns(true).then.returns(false)
10
12
  @connection = mock()
11
- @connection.expects(:peeraddr).returns(['','','',''])
13
+ @connection.stubs(:write)
14
+ @connection.stubs(:flush)
15
+ @connection.stubs(:peeraddr).returns(['','','',''])
12
16
  @connection.expects(:nil?).returns(false).at_least_once
13
17
  @client = Pandemic::ServerSide::Client.new(@connection, @server)
14
18
  end
15
19
 
16
20
  should "read size from the connection" do
17
21
  @connection.expects(:gets).returns("5\n")
22
+ @connection.expects(:read).with(5)
18
23
  @server.expects(:client_closed).with(@client)
19
24
  @client.listen
20
25
  wait_for_threads
@@ -34,7 +39,9 @@ class ClientTest < Test::Unit::TestCase
34
39
 
35
40
  request = mock()
36
41
  Pandemic::ServerSide::Request.expects(:new).returns(request)
37
- @server.expects(:handle_client_request).with(request)
42
+ @server.expects(:handle_client_request).with(request).returns(nil)
43
+ @connection.stubs(:write)
44
+ @connection.stubs(:flush)
38
45
 
39
46
  @server.expects(:client_closed).with(@client)
40
47
  @client.listen
data/test/peer_test.rb CHANGED
@@ -34,7 +34,7 @@ class PeerTest < Test::Unit::TestCase
34
34
 
35
35
  should "send client request to peer connection" do
36
36
  request, body = stub(:hash => "asdasdfadsf"), "hello world"
37
- @connection_pool.expects(:available_count => 1, :connections_count => 1)
37
+ @connection_pool.stubs(:available_count => 1, :connections_count => 1)
38
38
  conn = mock()
39
39
  @connection_pool.expects(:with_connection).yields(conn)
40
40
 
data/test/server_test.rb CHANGED
@@ -14,9 +14,11 @@ class ServerTest < Test::Unit::TestCase
14
14
  @tcpserver = mock()
15
15
  TCPServer.expects(:new).with("localhost", 4000).returns(@tcpserver)
16
16
 
17
- @conn = mock(:peeraddr => ['','','',''])
17
+ @conn = mock()
18
+ @conn.stubs(:peeraddr => ['','','',''])
18
19
  @tcpserver.expects(:accept).twice.returns(@conn).then.raises(Pandemic::ServerSide::Server::StopServer)
19
20
  peer = mock()
21
+ peer.stubs(:add_incoming_connection)
20
22
  @conn.expects(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
21
23
 
22
24
  @conn.expects(:gets).returns("SERVER localhost:4001\n")
@@ -91,7 +93,8 @@ class ServerTest < Test::Unit::TestCase
91
93
  TCPServer.expects(:new).with("localhost", 4000).returns(@tcpserver)
92
94
  @peer.expects(:connect).once
93
95
 
94
- @conn = mock(:peeraddr => ['','','',''])
96
+ @conn = mock()
97
+ @conn.stubs(:peeraddr => ['','','',''])
95
98
  @tcpserver.expects(:accept).twice.returns(@conn).then.raises(Pandemic::ServerSide::Server::StopServer)
96
99
  client = mock()
97
100
  @conn.expects(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
@@ -115,7 +118,8 @@ class ServerTest < Test::Unit::TestCase
115
118
  TCPServer.expects(:new).with("localhost", 4000).returns(@tcpserver)
116
119
  @peer.expects(:connect).once
117
120
 
118
- @conn = mock(:peeraddr => ['','','',''])
121
+ @conn = mock()
122
+ @conn.stubs(:peeraddr => ['','','',''])
119
123
  @tcpserver.expects(:accept).twice.returns(@conn).then.raises(Pandemic::ServerSide::Server::StopServer)
120
124
  @tcpserver.expects(:close)
121
125
  @peer.expects(:disconnect)
@@ -146,7 +150,7 @@ class ServerTest < Test::Unit::TestCase
146
150
  handler = mock()
147
151
  handler_class.expects(:new).once.returns(handler)
148
152
  request = mock()
149
- request.expects(:hash).at_least_once.returns("abcddef134123")
153
+ request.stubs(:hash => "abcddef134123")
150
154
  @peer.expects(:connected?).returns(true)
151
155
  handler.expects(:partition).with(request, is_a(Hash)).returns({"localhost:4000" => "1", "localhost:4001" => "2"})
152
156
  request.expects(:max_responses=).with(2)
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.5.1
4
+ version: 0.5.2
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-08-09 00:00:00 -07:00
12
+ date: 2009-08-11 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency