onstomp 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.yardopts +2 -1
- data/Rakefile +147 -0
- data/extra_doc/API.md +491 -0
- data/extra_doc/API.md.erb +33 -0
- data/extra_doc/DeveloperNarrative.md +123 -0
- data/extra_doc/UserNarrative.md +511 -0
- data/lib/onstomp.rb +5 -5
- data/lib/onstomp/client.rb +6 -1
- data/lib/onstomp/components/frame.rb +6 -6
- data/lib/onstomp/components/frame_headers.rb +18 -18
- data/lib/onstomp/components/scopes/transaction_scope.rb +11 -11
- data/lib/onstomp/components/subscription.rb +2 -2
- data/lib/onstomp/components/threaded_processor.rb +1 -1
- data/lib/onstomp/components/uri.rb +1 -1
- data/lib/onstomp/connections/base.rb +5 -5
- data/lib/onstomp/connections/heartbeating.rb +2 -2
- data/lib/onstomp/connections/serializers/stomp_1.rb +6 -6
- data/lib/onstomp/connections/serializers/stomp_1_1.rb +2 -2
- data/lib/onstomp/connections/stomp_1_0.rb +1 -1
- data/lib/onstomp/connections/stomp_1_1.rb +1 -1
- data/lib/onstomp/failover.rb +4 -0
- data/lib/onstomp/failover/buffers.rb +1 -0
- data/lib/onstomp/failover/buffers/receipts.rb +101 -0
- data/lib/onstomp/failover/buffers/written.rb +2 -2
- data/lib/onstomp/failover/client.rb +15 -12
- data/lib/onstomp/failover/failover_configurable.rb +3 -3
- data/lib/onstomp/failover/pools/base.rb +1 -1
- data/lib/onstomp/failover/uri.rb +41 -16
- data/lib/onstomp/interfaces/client_configurable.rb +1 -1
- data/lib/onstomp/interfaces/client_events.rb +30 -11
- data/lib/onstomp/interfaces/connection_events.rb +5 -1
- data/lib/onstomp/interfaces/event_manager.rb +2 -2
- data/lib/onstomp/interfaces/frame_methods.rb +169 -8
- data/lib/onstomp/interfaces/uri_configurable.rb +3 -3
- data/lib/onstomp/open-uri/client_extensions.rb +4 -4
- data/lib/onstomp/version.rb +2 -2
- data/onstomp.gemspec +0 -1
- data/spec/onstomp/components/threaded_processor_spec.rb +21 -0
- data/spec/onstomp/connections/base_spec.rb +15 -0
- data/spec/onstomp/failover/buffers/receipts_spec.rb +189 -0
- data/spec/onstomp/failover/buffers/written_spec.rb +167 -1
- data/spec/onstomp/failover/client_spec.rb +70 -1
- data/spec/onstomp/failover/failover_events_spec.rb +1 -2
- data/spec/onstomp/failover/uri_spec.rb +37 -4
- data/spec/onstomp/full_stacks/failover_spec.rb +76 -25
- data/spec/onstomp/full_stacks/onstomp_spec.rb +52 -8
- data/spec/onstomp/full_stacks/onstomp_ssh_spec.rb +83 -0
- data/spec/onstomp/full_stacks/test_broker.rb +45 -29
- metadata +11 -15
- data/DeveloperNarrative.md +0 -15
- data/UserNarrative.md +0 -8
@@ -61,8 +61,7 @@ module OnStomp::Failover
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
[:connect_failure, :
|
65
|
-
:lost, :connected].each do |ev|
|
64
|
+
[:connect_failure, :lost, :connected].each do |ev|
|
66
65
|
it "should have an event :on_failover_#{ev}" do
|
67
66
|
triggered = false
|
68
67
|
events.send(:"on_failover_#{ev}") { |*_| triggered = true }
|
@@ -4,16 +4,49 @@ require 'spec_helper'
|
|
4
4
|
module OnStomp::Failover
|
5
5
|
describe URI, :failover => true do
|
6
6
|
describe "parsing failover: URIs" do
|
7
|
-
|
8
|
-
|
7
|
+
def parse_failover_uri str
|
8
|
+
OnStomp::Failover::URI::FAILOVER.parse str
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should parse failover:(uri1,uri2...)?failoverParam1=..." do
|
12
|
+
uri = parse_failover_uri 'failover:(stomp://host.domain.tld,stomp+ssl:///?param=value¶m2=value2,stomp://user:pass@other.host.tld)?param=blah¶m2=testing'
|
13
|
+
uri.query.should == 'param=blah¶m2=testing'
|
14
|
+
uri.failover_uris.map { |u| u.scheme }.should == ['stomp', 'stomp+ssl', 'stomp']
|
15
|
+
uri.failover_uris.map { |u| u.host }.should == ['host.domain.tld', nil, 'other.host.tld']
|
16
|
+
uri.failover_uris.map { |u| u.query }.should == [nil, 'param=value¶m2=value2', nil]
|
17
|
+
uri.to_s.should == "failover:(stomp://host.domain.tld,stomp+ssl:///?param=value¶m2=value2,stomp://user:pass@other.host.tld)?param=blah¶m2=testing"
|
18
|
+
end
|
19
|
+
it "should parse failover://(uri1,uri2...)?failoverParam1=..." do
|
20
|
+
uri = parse_failover_uri 'failover://(stomp://host.domain.tld,stomp+ssl:///?param=value¶m2=value2,stomp://user:pass@other.host.tld)?param=blah¶m2=testing'
|
9
21
|
uri.query.should == 'param=blah¶m2=testing'
|
10
22
|
uri.failover_uris.map { |u| u.scheme }.should == ['stomp', 'stomp+ssl', 'stomp']
|
11
23
|
uri.failover_uris.map { |u| u.host }.should == ['host.domain.tld', nil, 'other.host.tld']
|
12
24
|
uri.failover_uris.map { |u| u.query }.should == [nil, 'param=value¶m2=value2', nil]
|
25
|
+
uri.to_s.should == "failover:(stomp://host.domain.tld,stomp+ssl:///?param=value¶m2=value2,stomp://user:pass@other.host.tld)?param=blah¶m2=testing"
|
26
|
+
end
|
27
|
+
it "should parse failover://uri1,uri2,..." do
|
28
|
+
uri = parse_failover_uri 'failover://stomp://host.domain.tld,stomp+ssl:///?param=value¶m2=value2,stomp://user:pass@other.host.tld'
|
29
|
+
uri.query.should be_nil
|
30
|
+
uri.failover_uris.map { |u| u.scheme }.should == ['stomp', 'stomp+ssl', 'stomp']
|
31
|
+
uri.failover_uris.map { |u| u.host }.should == ['host.domain.tld', nil, 'other.host.tld']
|
32
|
+
uri.failover_uris.map { |u| u.query }.should == [nil, 'param=value¶m2=value2', nil]
|
33
|
+
uri.to_s.should == "failover:(stomp://host.domain.tld,stomp+ssl:///?param=value¶m2=value2,stomp://user:pass@other.host.tld)"
|
34
|
+
end
|
35
|
+
it "should parse an array of failover URIs" do
|
36
|
+
uris = [ "stomp://host.domain.tld",
|
37
|
+
::URI.parse("stomp://user:pass@other.host.tld"),
|
38
|
+
"stomp+ssl:///?param=value¶m2=value2"]
|
39
|
+
uri = parse_failover_uri uris
|
40
|
+
uri.query.should be_nil
|
41
|
+
uri.failover_uris.map { |u| u.scheme }.should == ['stomp', 'stomp', 'stomp+ssl']
|
42
|
+
uri.failover_uris.map { |u| u.host }.should == ['host.domain.tld', 'other.host.tld', nil]
|
43
|
+
uri.failover_uris.map { |u| u.query }.should == [nil, nil, 'param=value¶m2=value2']
|
44
|
+
uri.to_s.should == "failover:(stomp://host.domain.tld,stomp://user:pass@other.host.tld,stomp+ssl:///?param=value¶m2=value2)"
|
13
45
|
end
|
14
|
-
it "should raise an error if the
|
46
|
+
it "should raise an error if it doesn't match the regex and isn't an array" do
|
15
47
|
lambda {
|
16
|
-
|
48
|
+
# The regex is pretty lax...
|
49
|
+
parse_failover_uri "failover:"
|
17
50
|
}.should raise_error(OnStomp::Failover::InvalidFailoverURIError)
|
18
51
|
end
|
19
52
|
end
|
@@ -3,53 +3,104 @@ require 'spec_helper'
|
|
3
3
|
require File.expand_path('../test_broker', __FILE__)
|
4
4
|
|
5
5
|
describe OnStomp::Failover, "full stack test", :fullstack => true, :failover => true do
|
6
|
-
let(:
|
7
|
-
TestBroker.new
|
6
|
+
let(:brokers) {
|
7
|
+
[TestBroker.new(10102),
|
8
|
+
TestBroker.new(10103)]
|
8
9
|
}
|
9
10
|
before(:each) do
|
10
|
-
|
11
|
+
brokers.each &:start
|
11
12
|
end
|
12
13
|
after(:each) do
|
13
|
-
|
14
|
+
brokers.each &:stop
|
14
15
|
end
|
15
16
|
|
16
|
-
describe "failing over" do
|
17
|
-
|
17
|
+
describe "failing over with a Written buffer" do
|
18
|
+
# We wrote [stomp://localhost:10102]: CONNECT / {:"accept-version"=>"1.0,1.1", :host=>"localhost", :"heart-beat"=>"0,0", :login=>"", :passcode=>""}
|
19
|
+
# We wrote [stomp://localhost:10102]: SEND / {:"x-onstomp-real-client"=>"2156558740", :destination=>"/queue/onstomp/failover/test", :"content-length"=>"22"}
|
20
|
+
# We wrote [stomp://localhost:10102]: BEGIN / {:"x-onstomp-real-client"=>"2156558740", :transaction=>"t-1234"}
|
21
|
+
# We wrote [stomp://localhost:10102]: SEND / {:transaction=>"t-1234", :"x-onstomp-real-client"=>"2156558740", :destination=>"/queue/onstomp/failover/test", :"content-length"=>"15"}
|
22
|
+
# We wrote [stomp://localhost:10102]: SUBSCRIBE / {:id=>"1", :"x-onstomp-real-client"=>"2156558740", :ack=>"auto", :destination=>"/queue/onstomp/failover/test"}
|
23
|
+
# We wrote [stomp://localhost:10102]: SEND / {:"x-onstomp-real-client"=>"2156558740", :destination=>"/queue/onstomp/failover/test", :"content-length"=>"18"}
|
24
|
+
# We wrote [stomp://localhost:10103]: CONNECT / {:"accept-version"=>"1.0,1.1", :host=>"localhost", :"heart-beat"=>"0,0", :login=>"", :passcode=>""}
|
25
|
+
# We wrote [stomp://localhost:10103]: DISCONNECT / {:"x-onstomp-real-client"=>"2156556660"}
|
26
|
+
# Received: ["CONNECT", "SEND", "BEGIN", "SEND", "SUBSCRIBE"]We wrote [stomp://localhost:10103]: BEGIN / {:"x-onstomp-real-client"=>"2156558740", :transaction=>"t-1234", :"x-onstomp-failover-replay"=>"1"}
|
27
|
+
#
|
28
|
+
# Transmitted: ["CONNECTED"]
|
29
|
+
# Received: ["CONNECT", "DISCONNECT"]
|
30
|
+
# Transmitted: ["CONNECTED"]
|
31
|
+
#
|
32
|
+
it "should failover" do
|
33
|
+
# Occasionally generates: ["CONNECT", "DISCONNECT", "BEGIN", "SEND", "SUBSCRIBE", "SEND", "COMMIT"]
|
18
34
|
committed = false
|
35
|
+
brokers.first.kill_on_command 'SUBSCRIBE'
|
19
36
|
killed = false
|
20
37
|
|
21
|
-
client = OnStomp::Failover::Client.new('failover:(stomp
|
22
|
-
client.
|
23
|
-
|
38
|
+
client = OnStomp::Failover::Client.new('failover:(stomp://localhost:10102,stomp://localhost:10103)')
|
39
|
+
client.on_subscribe do |s, rc|
|
40
|
+
# This frame will almost always get written to the first broker before the hangup occurs
|
41
|
+
client.send '/queue/onstomp/failover/test', 'are you receiving?',
|
42
|
+
:'x-onstomp-real-client' => rc.uri
|
43
|
+
end
|
44
|
+
|
45
|
+
client.connect
|
46
|
+
client.send '/queue/onstomp/failover/test', '4-3-2-1 Earth Below Me',
|
47
|
+
:'x-onstomp-real-client' => client.active_client.uri
|
48
|
+
client.begin 't-1234', :'x-onstomp-real-client' => client.active_client.uri
|
49
|
+
client.send '/queue/onstomp/failover/test', 'hello major tom',
|
50
|
+
:transaction => 't-1234', :'x-onstomp-real-client' => client.active_client.uri
|
51
|
+
client.subscribe('/queue/onstomp/failover/test', :'x-onstomp-real-client' => client.active_client.uri) do |m|
|
52
|
+
end
|
53
|
+
Thread.pass while client.connected?
|
54
|
+
|
55
|
+
client.send '/queue/onstomp/failover/test', 'Are you receiving?',
|
56
|
+
:'x-onstomp-real-client' => client.active_client.uri
|
57
|
+
sub = client.subscribe('/queue/onstomp/failover/test2', :'x-onstomp-real-client' => client.active_client.uri) do |m|
|
24
58
|
end
|
59
|
+
client.unsubscribe sub, :'x-onstomp-real-client' => client.active_client.uri
|
60
|
+
client.commit 't-1234', :'x-onstomp-real-client' => client.active_client.uri
|
61
|
+
|
62
|
+
client.disconnect :'x-onstomp-real-client' => client.active_client.uri
|
63
|
+
brokers.each(&:join)
|
64
|
+
brokers.first.frames_received.map(&:command).should == ["CONNECT", "SEND", "BEGIN", "SEND", "SUBSCRIBE"]
|
65
|
+
brokers.last.frames_received.map(&:command).should == ["CONNECT", "BEGIN", "SEND", "SUBSCRIBE", "SEND", "COMMIT", "SEND", "DISCONNECT"]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
describe "failing over with a Receipts buffer" do
|
69
|
+
it "should failover" do
|
70
|
+
committed = false
|
71
|
+
killed = false
|
72
|
+
brokers.first.kill_on_command 'SUBSCRIBE'
|
73
|
+
|
74
|
+
client = OnStomp::Failover::Client.new('failover:(stomp://localhost:10102,stomp://localhost:10103)',
|
75
|
+
:buffer => OnStomp::Failover::Buffers::Receipts)
|
25
76
|
client.on_subscribe do |s, rc|
|
26
|
-
broker
|
27
|
-
|
77
|
+
# This frame will get written, but the broker will hang up before
|
78
|
+
# a RECEIPT is given, so it will get repeated
|
28
79
|
client.send '/queue/onstomp/failover/test', 'are you receiving?',
|
29
|
-
:'x-onstomp-real-client' => rc.
|
80
|
+
:'x-onstomp-real-client' => rc.uri
|
30
81
|
end
|
31
82
|
|
32
83
|
client.connect
|
33
84
|
client.send '/queue/onstomp/failover/test', '4-3-2-1 Earth Below Me',
|
34
|
-
:'x-onstomp-real-client' => client.active_client.
|
35
|
-
client.begin 't-1234', :'x-onstomp-real-client' => client.active_client.
|
85
|
+
:'x-onstomp-real-client' => client.active_client.uri
|
86
|
+
client.begin 't-1234', :'x-onstomp-real-client' => client.active_client.uri
|
36
87
|
client.send '/queue/onstomp/failover/test', 'hello major tom',
|
37
|
-
:transaction => 't-1234', :'x-onstomp-real-client' => client.active_client.
|
38
|
-
client.subscribe('/queue/onstomp/failover/test', :'x-onstomp-real-client' => client.active_client.
|
88
|
+
:transaction => 't-1234', :'x-onstomp-real-client' => client.active_client.uri
|
89
|
+
client.subscribe('/queue/onstomp/failover/test', :'x-onstomp-real-client' => client.active_client.uri) do |m|
|
39
90
|
end
|
40
91
|
Thread.pass while client.connected?
|
41
92
|
|
42
93
|
client.send '/queue/onstomp/failover/test', 'Are you receiving?',
|
43
|
-
:'x-onstomp-real-client' => client.active_client.
|
44
|
-
sub = client.subscribe('/queue/onstomp/failover/test2', :'x-onstomp-real-client' => client.active_client.
|
94
|
+
:'x-onstomp-real-client' => client.active_client.uri
|
95
|
+
sub = client.subscribe('/queue/onstomp/failover/test2', :'x-onstomp-real-client' => client.active_client.uri) do |m|
|
45
96
|
end
|
46
|
-
client.unsubscribe sub, :'x-onstomp-real-client' => client.active_client.
|
47
|
-
client.commit 't-1234', :'x-onstomp-real-client' => client.active_client.
|
48
|
-
|
49
|
-
client.disconnect :'x-onstomp-real-client' => client.active_client.
|
50
|
-
|
51
|
-
|
52
|
-
|
97
|
+
client.unsubscribe sub, :'x-onstomp-real-client' => client.active_client.uri
|
98
|
+
client.commit 't-1234', :'x-onstomp-real-client' => client.active_client.uri
|
99
|
+
|
100
|
+
client.disconnect :'x-onstomp-real-client' => client.active_client.uri
|
101
|
+
brokers.each(&:join)
|
102
|
+
brokers.first.frames_received.map(&:command).should == ["CONNECT", "SEND", "BEGIN", "SEND", "SUBSCRIBE"]
|
103
|
+
brokers.last.frames_received.map(&:command).should == ["CONNECT", "SEND", "BEGIN", "SEND", "SUBSCRIBE", "SEND", "SEND", "COMMIT", "SEND", "DISCONNECT"]
|
53
104
|
end
|
54
105
|
end
|
55
106
|
end
|
@@ -2,14 +2,58 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
require File.expand_path('../test_broker', __FILE__)
|
4
4
|
|
5
|
-
describe OnStomp::Client, "full stack test", :fullstack => true do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
describe OnStomp::Client, "full stack test (stomp+ssl:)", :fullstack => true do
|
6
|
+
describe "STOMP 1.0" do
|
7
|
+
let(:broker) {
|
8
|
+
TestBroker.new 10101
|
9
|
+
}
|
10
|
+
before(:each) do
|
11
|
+
broker.start
|
12
|
+
end
|
13
|
+
after(:each) do
|
14
|
+
broker.stop
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "connecting" do
|
18
|
+
it "should connect to the broker given a CA path" do
|
19
|
+
client = OnStomp::Client.new('stomp://localhost:10101')
|
20
|
+
client.connect
|
21
|
+
client.send '/queue/test', 'my message body', {
|
22
|
+
"this:is\na \\fun\\ header" => 'blather matter'
|
23
|
+
}
|
24
|
+
client.send '/queue/test', "\x01\x02\x03\x04\x05\x06".encode('BINARY'),
|
25
|
+
:'content-type' => 'application/octet-stream'
|
26
|
+
client.disconnect
|
27
|
+
broker.join
|
28
|
+
end
|
29
|
+
end
|
11
30
|
end
|
12
|
-
|
13
|
-
broker
|
31
|
+
describe "STOMP 1.1" do
|
32
|
+
let(:broker) {
|
33
|
+
TestBroker.new(10101).tap do |b|
|
34
|
+
b.session_class = TestBroker::Session11
|
35
|
+
end
|
36
|
+
}
|
37
|
+
before(:each) do
|
38
|
+
broker.start
|
39
|
+
end
|
40
|
+
after(:each) do
|
41
|
+
broker.stop
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "connecting" do
|
45
|
+
it "should connect to the broker given a CA path" do
|
46
|
+
client = OnStomp::Client.new('stomp://localhost:10101')
|
47
|
+
client.connect
|
48
|
+
client.send '/queue/test', 'my message body', {
|
49
|
+
"this:is\na \\fun\\ header" => 'blather matter'
|
50
|
+
}
|
51
|
+
client.send '/queue/test', "\x01\x02\x03\x04\x05\x06".encode('BINARY'),
|
52
|
+
:'content-type' => 'application/octet-stream'
|
53
|
+
client.disconnect
|
54
|
+
broker.join
|
55
|
+
end
|
56
|
+
end
|
14
57
|
end
|
58
|
+
|
15
59
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require File.expand_path('../test_broker', __FILE__)
|
4
|
+
|
5
|
+
describe OnStomp::Client, "full stack test (stomp+ssl:)", :fullstack => true do
|
6
|
+
describe "STOMP 1.0" do
|
7
|
+
let(:broker) {
|
8
|
+
TestSSLBroker.new 10103
|
9
|
+
}
|
10
|
+
before(:each) do
|
11
|
+
broker.start
|
12
|
+
end
|
13
|
+
after(:each) do
|
14
|
+
broker.stop
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "connecting with SSL options" do
|
18
|
+
it "should connect to the broker given a CA path" do
|
19
|
+
client = OnStomp::Client.new('stomp+ssl://localhost:10103', :ssl => {
|
20
|
+
:ca_file => File.expand_path('../ssl/demoCA/cacert.pem', __FILE__),
|
21
|
+
:post_connection_check => 'My Broker'
|
22
|
+
})
|
23
|
+
client.connect
|
24
|
+
client.send '/queue/test', 'my message body', {
|
25
|
+
"this:is\na \\fun\\ header" => 'blather matter'
|
26
|
+
}
|
27
|
+
client.send '/queue/test', "\x01\x02\x03\x04\x05\x06".encode('BINARY'),
|
28
|
+
:'content-type' => 'application/octet-stream'
|
29
|
+
client.disconnect
|
30
|
+
broker.join
|
31
|
+
end
|
32
|
+
it "should fail when post connection check does not match CN" do
|
33
|
+
client = OnStomp::Client.new('stomp+ssl://localhost:10103', :ssl => {
|
34
|
+
:ca_file => File.expand_path('../ssl/demoCA/cacert.pem', __FILE__),
|
35
|
+
:post_connection_check => 'Sweet Brokerage'
|
36
|
+
})
|
37
|
+
lambda {
|
38
|
+
client.connect
|
39
|
+
}.should raise_error('hostname was not match with the server certificate')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
describe "STOMP 1.1" do
|
44
|
+
let(:broker) {
|
45
|
+
TestSSLBroker.new(10103).tap do |b|
|
46
|
+
b.session_class = TestBroker::Session11
|
47
|
+
end
|
48
|
+
}
|
49
|
+
before(:each) do
|
50
|
+
broker.start
|
51
|
+
end
|
52
|
+
after(:each) do
|
53
|
+
broker.stop
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "connecting with SSL options" do
|
57
|
+
it "should connect to the broker given a CA path" do
|
58
|
+
client = OnStomp::Client.new('stomp+ssl://localhost:10103', :ssl => {
|
59
|
+
:ca_file => File.expand_path('../ssl/demoCA/cacert.pem', __FILE__),
|
60
|
+
:post_connection_check => 'My Broker'
|
61
|
+
})
|
62
|
+
client.connect
|
63
|
+
client.send '/queue/test', 'my message body', {
|
64
|
+
"this:is\na \\fun\\ header" => 'blather matter'
|
65
|
+
}
|
66
|
+
client.send '/queue/test', "\x01\x02\x03\x04\x05\x06".encode('BINARY'),
|
67
|
+
:'content-type' => 'application/octet-stream'
|
68
|
+
client.disconnect
|
69
|
+
broker.join
|
70
|
+
end
|
71
|
+
it "should fail when post connection check does not match CN" do
|
72
|
+
client = OnStomp::Client.new('stomp+ssl://localhost:10103', :ssl => {
|
73
|
+
:ca_file => File.expand_path('../ssl/demoCA/cacert.pem', __FILE__),
|
74
|
+
:post_connection_check => 'Sweet Brokerage'
|
75
|
+
})
|
76
|
+
lambda {
|
77
|
+
client.connect
|
78
|
+
}.should raise_error('hostname was not match with the server certificate')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -5,9 +5,13 @@
|
|
5
5
|
class TestBroker
|
6
6
|
class StopThread < StandardError; end
|
7
7
|
|
8
|
-
attr_reader :messages, :sessions
|
8
|
+
attr_reader :messages, :sessions, :mau_dib
|
9
|
+
attr_reader :frames_received, :frames_transmitted
|
10
|
+
attr_accessor :session_class
|
9
11
|
|
10
12
|
def initialize(port=61613)
|
13
|
+
@frames_received = []
|
14
|
+
@frames_transmitted = []
|
11
15
|
@sessions = []
|
12
16
|
@messages = Hash.new { |h,k| h[k] = [] }
|
13
17
|
@subscribes = Hash.new { |h,k| h[k] = [] }
|
@@ -21,14 +25,9 @@ class TestBroker
|
|
21
25
|
end
|
22
26
|
@session_class = Session10
|
23
27
|
end
|
24
|
-
|
25
|
-
def
|
26
|
-
@
|
27
|
-
@sessions.each do |s|
|
28
|
-
s.kill
|
29
|
-
end
|
30
|
-
@sessions.clear
|
31
|
-
end
|
28
|
+
|
29
|
+
def kill_on_command command
|
30
|
+
@mau_dib = command
|
32
31
|
end
|
33
32
|
|
34
33
|
def enqueue_message s
|
@@ -88,14 +87,15 @@ class TestBroker
|
|
88
87
|
@listener = Thread.new do
|
89
88
|
begin
|
90
89
|
loop do
|
91
|
-
|
90
|
+
sock = @socket.accept
|
92
91
|
@session_mutex.synchronize do
|
93
|
-
@sessions <<
|
92
|
+
@sessions << @session_class.new(self, sock)
|
94
93
|
end
|
95
94
|
end
|
96
95
|
rescue StopThread
|
97
96
|
rescue Exception
|
98
97
|
$stdout.puts "Listener failed: #{$!}"
|
98
|
+
$stdout.puts $!.backtrace
|
99
99
|
stop
|
100
100
|
end
|
101
101
|
end
|
@@ -123,17 +123,11 @@ class TestBroker
|
|
123
123
|
@socket = sock
|
124
124
|
init_events
|
125
125
|
init_connection
|
126
|
-
|
127
|
-
connect_frame = connected_frame = nil
|
126
|
+
connect_frame = nil
|
128
127
|
@connection.io_process_read do |f|
|
129
128
|
connect_frame ||= f
|
130
129
|
end until connect_frame
|
131
|
-
|
132
|
-
transmit OnStomp::Components::Frame.new('CONNECTED')
|
133
|
-
@connection.io_process_write do |f|
|
134
|
-
connected_frame ||= f
|
135
|
-
end until connected_frame
|
136
|
-
@processor.start
|
130
|
+
reply_to_connect connect_frame
|
137
131
|
end
|
138
132
|
|
139
133
|
def init_connection
|
@@ -141,6 +135,15 @@ class TestBroker
|
|
141
135
|
@processor = OnStomp::Components::ThreadedProcessor.new self
|
142
136
|
end
|
143
137
|
|
138
|
+
def reply_to_connect connect_frame
|
139
|
+
connected_frame = nil
|
140
|
+
transmit OnStomp::Components::Frame.new('CONNECTED')
|
141
|
+
@connection.io_process_write do |f|
|
142
|
+
connected_frame ||= f
|
143
|
+
end until connected_frame
|
144
|
+
@processor.start
|
145
|
+
end
|
146
|
+
|
144
147
|
def connected?
|
145
148
|
@connection.connected?
|
146
149
|
end
|
@@ -165,7 +168,15 @@ class TestBroker
|
|
165
168
|
@connection.close
|
166
169
|
end
|
167
170
|
|
171
|
+
after_transmitting do |f,_|
|
172
|
+
@server.frames_transmitted << f
|
173
|
+
end
|
174
|
+
|
168
175
|
before_receiving do |f,_|
|
176
|
+
@server.frames_received << f
|
177
|
+
if @server.mau_dib && f.command == @server.mau_dib
|
178
|
+
kill
|
179
|
+
end
|
169
180
|
if f.header? :receipt
|
170
181
|
transmit OnStomp::Components::Frame.new('RECEIPT',
|
171
182
|
:'receipt-id' => f[:receipt])
|
@@ -213,10 +224,19 @@ class TestBroker
|
|
213
224
|
def init_events
|
214
225
|
super
|
215
226
|
end
|
216
|
-
|
217
|
-
def
|
218
|
-
|
219
|
-
|
227
|
+
|
228
|
+
def heartbeats; [3000, 10000]; end
|
229
|
+
|
230
|
+
def reply_to_connect connect_frame
|
231
|
+
connected_frame = nil
|
232
|
+
transmit OnStomp::Components::Frame.new('CONNECTED',
|
233
|
+
:version => '1.1', :'heart-beat' => heartbeats)
|
234
|
+
@connection.io_process_write do |f|
|
235
|
+
connected_frame ||= f
|
236
|
+
end until connected_frame
|
237
|
+
@connection = OnStomp::Connections::Stomp_1_1.new(@connection.socket, self)
|
238
|
+
@connection.configure connect_frame, {}
|
239
|
+
@processor.start
|
220
240
|
end
|
221
241
|
end
|
222
242
|
|
@@ -233,8 +253,8 @@ class TestSSLBroker < TestBroker
|
|
233
253
|
}
|
234
254
|
|
235
255
|
def initialize(port=61612, certs=:default)
|
236
|
-
|
237
|
-
@tcp_socket =
|
256
|
+
super(port)
|
257
|
+
@tcp_socket = @socket
|
238
258
|
@ssl_context = OpenSSL::SSL::SSLContext.new
|
239
259
|
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
240
260
|
cert_files = SSL_CERT_FILES[certs]
|
@@ -243,9 +263,5 @@ class TestSSLBroker < TestBroker
|
|
243
263
|
@socket = OpenSSL::SSL::SSLServer.new(@tcp_socket, @ssl_context)
|
244
264
|
@socket.start_immediately = true
|
245
265
|
@session = nil
|
246
|
-
@version = '1.1'
|
247
|
-
@session_class = StompSession
|
248
|
-
@sent_frames = []
|
249
|
-
@received_frames = []
|
250
266
|
end
|
251
267
|
end
|