zmachine 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +1 -0
- data/{echo_client.rb → examples/echo_client.rb} +0 -0
- data/{echo_server.rb → examples/echo_server.rb} +0 -0
- data/lib/zmachine.rb +3 -115
- data/lib/zmachine/acceptor.rb +1 -1
- data/lib/zmachine/channel.rb +38 -5
- data/lib/zmachine/connection.rb +57 -152
- data/lib/zmachine/connection_manager.rb +34 -25
- data/lib/zmachine/hashed_wheel.rb +6 -5
- data/lib/zmachine/jeromq-0.3.2-SNAPSHOT.jar +0 -0
- data/lib/zmachine/reactor.rb +9 -7
- data/lib/zmachine/tcp_channel.rb +13 -40
- data/lib/zmachine/timers.rb +15 -43
- data/lib/zmachine/zmq_channel.rb +52 -60
- data/spec/channel_spec.rb +178 -0
- data/spec/connection_spec.rb +36 -11
- data/spec/hashed_wheel_spec.rb +15 -15
- data/spec/support/echo_mock.rb +32 -0
- data/zmachine.gemspec +1 -1
- metadata +9 -9
- data/lib/zmachine/jeromq-0.3.0-SNAPSHOT.jar +0 -0
- data/spec/tcp_channel_spec.rb +0 -109
- data/spec/zmq_channel_spec.rb +0 -113
data/spec/zmq_channel_spec.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
require 'zmachine/zmq_channel'
|
2
|
-
|
3
|
-
include ZMachine
|
4
|
-
|
5
|
-
describe ZMachine::ZMQChannel do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@server = ZMQChannel.new(ZMQ::REP)
|
9
|
-
@port = @server.bind("tcp://*:*")
|
10
|
-
@client = ZMQChannel.new(ZMQ::REQ)
|
11
|
-
@client.connect("tcp://0.0.0.0:#{@port}")
|
12
|
-
end
|
13
|
-
|
14
|
-
after(:each) do
|
15
|
-
@client.close
|
16
|
-
@server.close
|
17
|
-
end
|
18
|
-
|
19
|
-
after(:all) do
|
20
|
-
ZMachine.context.destroy
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:data) { "foo" }
|
24
|
-
|
25
|
-
context '#bind' do
|
26
|
-
|
27
|
-
it 'binds a server socket' do
|
28
|
-
expect(@server).to be_bound
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
context '#connect' do
|
34
|
-
|
35
|
-
it 'connects to a server socket' do
|
36
|
-
expect(@client).to be_connected
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
context '#send/recv' do
|
42
|
-
|
43
|
-
it 'writes outbound buffers to the socket' do
|
44
|
-
@client.send_data([data.to_java_bytes])
|
45
|
-
expect(@client.write_outbound_data).to eq(true)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'receives data sent from the client' do
|
49
|
-
@client.send_data([data.to_java_bytes])
|
50
|
-
@client.write_outbound_data
|
51
|
-
received = String.from_java_bytes(@server.read_inbound_data.first)
|
52
|
-
expect(received).to eq(data)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'receives data sent from the server' do
|
56
|
-
@client.send_data([data.to_java_bytes])
|
57
|
-
@client.write_outbound_data
|
58
|
-
received = String.from_java_bytes(@server.read_inbound_data.first)
|
59
|
-
@server.send_data([data.to_java_bytes])
|
60
|
-
@server.write_outbound_data
|
61
|
-
received = String.from_java_bytes(@client.read_inbound_data.first)
|
62
|
-
expect(received).to eq(data)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'sends and receives multipart messages' do
|
66
|
-
parts = %w(foo bar baz)
|
67
|
-
@client.send_data(parts.map(&:to_java_bytes))
|
68
|
-
@client.write_outbound_data
|
69
|
-
received = @server.read_inbound_data.map do |part|
|
70
|
-
String.from_java_bytes(part)
|
71
|
-
end
|
72
|
-
expect(received).to eq(parts)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'queues data when ZMQ is MIA' do
|
76
|
-
socket = @client.socket
|
77
|
-
# https://github.com/jruby/jruby/wiki/Persistence#deprecating-proxy-caching
|
78
|
-
Java::OrgZeromq::ZMQ::Socket.__persistent__ = true
|
79
|
-
socket.stub(:send_byte_array) { socket.unstub(:send_byte_array); raise ZMQException.new(nil) }
|
80
|
-
@client.send_data([data.to_java_bytes])
|
81
|
-
expect(@client.can_send?).to eq(true)
|
82
|
-
@client.write_outbound_data
|
83
|
-
expect(@client.can_send?).to eq(false)
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
context '#close' do
|
89
|
-
|
90
|
-
it 'closes the client connection' do
|
91
|
-
@client.close
|
92
|
-
expect(@client).to be_closed
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'closes the server connection' do
|
96
|
-
@server.close
|
97
|
-
expect(@server).to be_closed
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'closes the connection after writing' do
|
101
|
-
@client.send_data([data.to_java_bytes])
|
102
|
-
@client.close_after_writing
|
103
|
-
@client.write_outbound_data
|
104
|
-
expect(@client).not_to be_connected
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'has no concept of a peer' do
|
110
|
-
expect{@client.peer}.to raise_error(RuntimeError)
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|