Skip to content

Commit

Permalink
Add EM.connection_count to java reactor and make test_connection_coun…
Browse files Browse the repository at this point in the history
…t less retarded
  • Loading branch information
jakedouglas committed Aug 5, 2009
1 parent e66d100 commit 979b921
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
4 changes: 4 additions & 0 deletions java/src/com/rubyeventmachine/EmReactor.java
Original file line number Diff line number Diff line change
Expand Up @@ -483,4 +483,8 @@ public boolean isNotifyReadable (long sig) {
public boolean isNotifyWritable (long sig) {
return Connections.get(sig).isNotifyWritable();
}

public int getConnectionCount() {
return Connections.size() + Acceptors.size();
}
}
3 changes: 3 additions & 0 deletions lib/jeventmachine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ def self.is_notify_readable sig
def self.is_notify_writable sig
@em.isNotifyWritable(sig)
end
def self.get_connection_count
@em.getConnectionCount
end

class Connection
def associate_callback_target sig
Expand Down
30 changes: 10 additions & 20 deletions tests/test_connection_count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,22 @@ def test_idle_connection_count

module Client
def connection_completed
EM.next_tick{
$client_connected = EM.connection_count
EM.stop
}
end
end

module Server
def post_init
$server_connected = EM.connection_count
$client_conns += 1
EM.stop if $client_conns == 3
end
end

def test_with_some_connections
EM.run {
$initial = EM.connection_count
EM.start_server("127.0.0.1", 9999, Server)
$server_started = EM.connection_count
EM.next_tick{
EM.connect("127.0.0.1", 9999, Client)
}
$client_conns = 0
$initial_conns = EM.connection_count
EM.start_server("127.0.0.1", 9999)
$server_conns = EM.connection_count
3.times { EM.connect("127.0.0.1", 9999, Client) }
}

assert_equal(0, $initial)
assert_equal(1, $server_started)
assert_equal(2, $server_connected)
assert_equal(3, $client_connected)
assert_equal(0, $initial_conns)
assert_equal(1, $server_conns)
assert_equal(4, $client_conns + $server_conns)
end
end

0 comments on commit 979b921

Please sign in to comment.