zmachine 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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