stomper 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,139 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ module Stomper
4
+ describe Transaction do
5
+ before(:each) do
6
+ @mock_client = mock("client")
7
+ end
8
+
9
+ describe "initialization with blocks" do
10
+ before(:each) do
11
+ @mock_client.should_receive(:begin).once.with(an_instance_of(String)).and_return(nil)
12
+ @mock_client.should_receive(:send).once.with("/queue/test/1","a message", an_instance_of(Hash)).and_return(nil)
13
+ @mock_client.should_receive(:commit).once.with(an_instance_of(String)).and_return(nil)
14
+ end
15
+
16
+
17
+ it "should provide a DSL when a block with no arguments is given" do
18
+ lambda do
19
+ Transaction.new(@mock_client) do
20
+ send("/queue/test/1", "a message")
21
+ end
22
+ end.should_not raise_error
23
+ end
24
+
25
+ it "should yield itself when a block with arguments is given" do
26
+ lambda do
27
+ Transaction.new(@mock_client) do |t|
28
+ t.send("/queue/test/1", "a message")
29
+ end
30
+ end.should_not raise_error
31
+ end
32
+ end
33
+
34
+ describe "explicitly named" do
35
+ before(:each) do
36
+ @transaction_name = "tx-test"
37
+ @mock_client.should_receive(:begin).once.with(@transaction_name).and_return(nil)
38
+ @mock_client.should_receive(:send).once.with("/queue/test/1","test message", hash_including("transaction" => @transaction_name)).and_return(nil)
39
+ @mock_client.should_receive(:commit).once.with(@transaction_name).and_return(nil)
40
+ end
41
+
42
+ it "should use the given transaction ID as the transaction header in stomp messages" do
43
+ Transaction.new(@mock_client, @transaction_name) do |t|
44
+ t.send("/queue/test/1", "test message")
45
+ end
46
+ end
47
+ end
48
+
49
+ describe "aborting failed transactions" do
50
+ before(:each) do
51
+ @transaction_name = "tx-test-2"
52
+ @mock_client.should_receive(:begin).once.with(@transaction_name).and_return(nil)
53
+ @mock_client.should_receive(:send).once.with("/queue/test/1","test message", hash_including("transaction" => @transaction_name)).and_return(nil)
54
+ end
55
+
56
+ it "should abort when an exception is raised" do
57
+ @mock_client.should_receive(:abort).once.with(@transaction_name).and_return(nil)
58
+ @mock_client.should_not_receive(:commit)
59
+ lambda do
60
+ Transaction.new(@mock_client, @transaction_name) do |t|
61
+ t.send("/queue/test/1", "test message")
62
+ raise "Never to be completed!"
63
+ end
64
+ end.should raise_error(TransactionAborted)
65
+ end
66
+
67
+ it "should abort and raise an error when explicitly aborted" do
68
+ @mock_client.should_receive(:abort).once.with(@transaction_name).and_return(nil)
69
+ @mock_client.should_not_receive(:commit)
70
+ lambda do
71
+ Transaction.new(@mock_client, @transaction_name) do |t|
72
+ t.send("/queue/test/1", "test message")
73
+ t.abort
74
+ # This should never be reached.
75
+ t.commit
76
+ end
77
+ end.should raise_error(TransactionAborted)
78
+ end
79
+
80
+ it "should not raise an exception when explicitly aborted after a commit" do
81
+ @mock_client.should_not_receive(:abort)
82
+ @mock_client.should_receive(:commit).once.with(@transaction_name).and_return(nil)
83
+ lambda do
84
+ Transaction.new(@mock_client, @transaction_name) do |t|
85
+ t.send("/queue/test/1", "test message")
86
+ t.commit
87
+ t.abort
88
+ end
89
+ end.should_not raise_error(TransactionAborted)
90
+ end
91
+ end
92
+
93
+ describe "nested transactions" do
94
+ before(:each) do
95
+ @transaction_name = "tx-test-3"
96
+ @inner_transaction_name = "#{@transaction_name}-inner"
97
+ @inner_inner_transaction_name = "#{@transaction_name}-inner-inner"
98
+ @mock_client.should_receive(:begin).with(@transaction_name).once.and_return(nil)
99
+ @mock_client.should_receive(:begin).with(@inner_transaction_name).once.and_return(nil)
100
+ @mock_client.should_receive(:send).with("/queue/test/1","test message", hash_including("transaction" => @transaction_name)).once.and_return(nil)
101
+ @mock_client.should_receive(:send).with("/queue/test/2","inner message", hash_including("transaction" => @inner_transaction_name)).once.and_return(nil)
102
+ end
103
+ it "no transaction should succeed when an inner one fails" do
104
+ @mock_client.should_receive(:abort).once.with(@transaction_name).and_return(nil)
105
+ @mock_client.should_receive(:abort).once.with(@inner_transaction_name).and_return(nil)
106
+ @mock_client.should_not_receive(:commit)
107
+ lambda do
108
+ Transaction.new(@mock_client, @transaction_name) do |t|
109
+ t.send("/queue/test/1", "test message")
110
+ t.transaction(@inner_transaction_name) do |nt|
111
+ nt.send("/queue/test/2", "inner message")
112
+ raise "failure"
113
+ end
114
+ end
115
+ end.should raise_error(TransactionAborted)
116
+ end
117
+ it "no transaction should succeed when an inner one is explicitly aborted" do
118
+ @mock_client.should_receive(:begin).with(@inner_inner_transaction_name).once.and_return(nil)
119
+ @mock_client.should_receive(:send).with("/queue/test/3","inner-inner message", hash_including("transaction" => @inner_inner_transaction_name)).once.and_return(nil)
120
+ @mock_client.should_receive(:abort).once.with(@transaction_name).and_return(nil)
121
+ @mock_client.should_receive(:abort).once.with(@inner_transaction_name).and_return(nil)
122
+ @mock_client.should_receive(:abort).once.with(@inner_inner_transaction_name).and_return(nil)
123
+ @mock_client.should_not_receive(:commit)
124
+ lambda do
125
+ Transaction.new(@mock_client, @transaction_name) do |t|
126
+ t.send("/queue/test/1", "test message")
127
+ t.transaction(@inner_transaction_name) do |nt|
128
+ nt.send("/queue/test/2", "inner message")
129
+ nt.transaction(@inner_inner_transaction_name) do |nnt|
130
+ nnt.send("/queue/test/3", "inner-inner message")
131
+ nnt.abort
132
+ end
133
+ end
134
+ end
135
+ end.should raise_error(TransactionAborted)
136
+ end
137
+ end
138
+ end
139
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stomper
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
+ platform: ruby
11
+ authors:
12
+ - Ian D. Eccles
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-04 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Ruby client for the stomp messaging protocol derived from the original stomp gem
22
+ email:
23
+ - ian.eccles@gmali.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ - CHANGELOG
31
+ - LICENSE
32
+ - AUTHORS
33
+ files:
34
+ - lib/stomper/subscription.rb
35
+ - lib/stomper/frames.rb
36
+ - lib/stomper/transaction.rb
37
+ - lib/stomper/subscriptions.rb
38
+ - lib/stomper/frames/send.rb
39
+ - lib/stomper/frames/receipt.rb
40
+ - lib/stomper/frames/ack.rb
41
+ - lib/stomper/frames/client_frame.rb
42
+ - lib/stomper/frames/disconnect.rb
43
+ - lib/stomper/frames/message.rb
44
+ - lib/stomper/frames/error.rb
45
+ - lib/stomper/frames/connected.rb
46
+ - lib/stomper/frames/server_frame.rb
47
+ - lib/stomper/frames/begin.rb
48
+ - lib/stomper/frames/unsubscribe.rb
49
+ - lib/stomper/frames/connect.rb
50
+ - lib/stomper/frames/headers.rb
51
+ - lib/stomper/frames/abort.rb
52
+ - lib/stomper/frames/commit.rb
53
+ - lib/stomper/frames/subscribe.rb
54
+ - lib/stomper/client.rb
55
+ - lib/stomper/connection.rb
56
+ - lib/stomper.rb
57
+ - spec/subscriptions_spec.rb
58
+ - spec/spec_helper.rb
59
+ - spec/shared_connection_examples.rb
60
+ - spec/spec.opts
61
+ - spec/frames/server_frame_spec.rb
62
+ - spec/frames/client_frame_spec.rb
63
+ - spec/frames/headers_spec.rb
64
+ - spec/connection_spec.rb
65
+ - spec/subscription_spec.rb
66
+ - spec/client_spec.rb
67
+ - spec/transaction_spec.rb
68
+ - README.rdoc
69
+ - CHANGELOG
70
+ - LICENSE
71
+ - AUTHORS
72
+ has_rdoc: true
73
+ homepage: http://github.com/iande/stomper
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options:
78
+ - --quiet
79
+ - --title
80
+ - stomper documentation
81
+ - --opname
82
+ - index.html
83
+ - --line-numbers
84
+ - --main
85
+ - README.rdoc
86
+ - --inline-source
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 1.3.6
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Ruby client for the stomp messaging protocol derived from the original stomp gem
110
+ test_files:
111
+ - spec/subscriptions_spec.rb
112
+ - spec/spec_helper.rb
113
+ - spec/shared_connection_examples.rb
114
+ - spec/spec.opts
115
+ - spec/frames/server_frame_spec.rb
116
+ - spec/frames/client_frame_spec.rb
117
+ - spec/frames/headers_spec.rb
118
+ - spec/connection_spec.rb
119
+ - spec/subscription_spec.rb
120
+ - spec/client_spec.rb
121
+ - spec/transaction_spec.rb