ferocia-rubywmq 2.0.2 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +10 -0
  3. data/Gemfile.lock +36 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +36 -47
  6. data/Rakefile +12 -76
  7. data/examples/each_a.rb +2 -3
  8. data/examples/each_b.rb +4 -5
  9. data/examples/each_header.rb +5 -6
  10. data/examples/files_to_q.rb +7 -8
  11. data/examples/get_a.rb +3 -5
  12. data/examples/get_client.rb +9 -10
  13. data/examples/put1_a.rb +2 -3
  14. data/examples/put1_b.rb +4 -7
  15. data/examples/put1_c.rb +6 -6
  16. data/examples/put_a.rb +0 -2
  17. data/examples/put_b.rb +5 -7
  18. data/examples/put_dlh.rb +11 -12
  19. data/examples/put_dynamic_q.rb +7 -7
  20. data/examples/put_group_a.rb +3 -4
  21. data/examples/put_group_b.rb +7 -7
  22. data/examples/put_rfh.rb +13 -11
  23. data/examples/put_rfh2_a.rb +9 -10
  24. data/examples/put_rfh2_b.rb +9 -9
  25. data/examples/put_xmit_q.rb +63 -8
  26. data/examples/q_to_files.rb +6 -7
  27. data/examples/request.rb +20 -18
  28. data/examples/server.rb +19 -16
  29. data/ext/extconf.rb +36 -26
  30. data/ext/extconf_client.rb +3 -3
  31. data/ext/generate/generate_const.rb +30 -23
  32. data/ext/generate/generate_reason.rb +70 -72
  33. data/ext/generate/generate_structs.rb +20 -19
  34. data/ext/generate/wmq_structs.erb +67 -67
  35. data/ext/wmq.c +0 -16
  36. data/ext/wmq.h +0 -16
  37. data/ext/wmq_message.c +8 -24
  38. data/ext/wmq_mq_load.c +5 -17
  39. data/ext/wmq_queue.c +73 -90
  40. data/ext/wmq_queue_manager.c +78 -88
  41. data/lib/wmq.rb +17 -11
  42. data/lib/wmq/message.rb +36 -34
  43. data/lib/wmq/queue_manager.rb +30 -23
  44. data/lib/wmq/version.rb +1 -1
  45. data/rubywmq.gemspec +44 -0
  46. data/test/queue_manager_test.rb +334 -0
  47. data/test/test_helper.rb +14 -0
  48. metadata +23 -34
  49. data/tests/test.rb +0 -318
@@ -1,318 +0,0 @@
1
- # Allow test to be run in-place without requiring a gem install
2
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
-
4
- require 'rubygems'
5
- require 'wmq'
6
- require 'test/unit'
7
- class TestTest < Test::Unit::TestCase
8
-
9
- def setup
10
- puts '****** setup: start ******'
11
- @queue_manager = WMQ::QueueManager.new(:q_mgr_name => 'TEST') #, :connection_name=>'localhost(1414)')
12
- @queue_manager.connect
13
-
14
- # Create Queue and clear any messages from the queue
15
- @in_queue = WMQ::Queue.new(:queue_manager=>@queue_manager,
16
- :mode=>:input,
17
- :dynamic_q_name=>'UNIT.TEST.*',
18
- :q_name=>'SYSTEM.DEFAULT.MODEL.QUEUE',
19
- :fail_if_exists=>false)
20
- @in_queue.open
21
- @in_queue.each { |message| }
22
-
23
- # Open same queue for Output. Queue should be created by now
24
- @out_queue = WMQ::Queue.new(:queue_manager=>@queue_manager,
25
- :mode=>:output,
26
- :q_name=>@in_queue.name)
27
- @out_queue.open
28
- puts '****** setup: end ******'
29
- end
30
-
31
- def teardown
32
- puts '****** teardown: start ******'
33
- @out_queue.close
34
- @in_queue.close
35
- @queue_manager.disconnect
36
- puts '****** teardown: end ******'
37
- end
38
-
39
- def test_exceptions
40
- puts '****** test_exceptions: start ******'
41
- assert_raise(TypeError) { WMQ::QueueManager.new(1) }
42
- assert_nothing_raised { WMQ::QueueManager.new(:exception_on_error=>nil) }
43
- assert_raise(TypeError) { WMQ::QueueManager.new(:exception_on_error=>1) }
44
- assert_raise(TypeError) { WMQ::QueueManager.new(:q_mgr_name=>2).connect }
45
- assert_raise(WMQ::WMQException) { WMQ::QueueManager.new(:q_mgr_name=>'bad').connect }
46
- puts '****** test_exceptions: end ******'
47
- end
48
-
49
- def test_queue_manager
50
- puts '****** test_queue_manager ******'
51
- assert_equal(Object, WMQ::QueueManager.superclass)
52
- assert_equal(WMQ::QueueManager, @queue_manager.class)
53
- end
54
-
55
- def test_1
56
- puts '****** test_1 ******'
57
- assert_equal(@out_queue.put(:data=>'Hello World'), true)
58
- message = WMQ::Message.new
59
- assert_equal(@in_queue.get(:message=>message), true)
60
- assert_equal(message.data, 'Hello World')
61
- end
62
-
63
- def test_dynamic_buffer
64
- puts '****** test_dynamic_buffer ******'
65
- # Clear out queue of any messages
66
- @in_queue.each { |message| }
67
-
68
- test_sizes = [0, 1, 100, 101, 102, 500, 65534, 65535, 65536, 65537, 1*1024*1024, 4*1024*1024]
69
- test_sizes.each do |size|
70
- str = '0123456789ABCDEF' * (size/16) + '0123456789ABCDEF'[0,size%16]
71
- assert_equal(str.length, size)
72
- assert_equal(@out_queue.put(:data=>str), true)
73
- end
74
-
75
- # First test the browse mechanism
76
- counter = 0
77
- @queue_manager.open_queue(:mode=>:browse, :q_name=>@in_queue.name) do |browse_queue|
78
- browse_queue.each do |message|
79
- size = test_sizes[counter]
80
- assert_equal(size, message.data.length)
81
- str = '0123456789ABCDEF' * (size/16) + '0123456789ABCDEF'[0,size%16]
82
- assert_equal(str, message.data)
83
- counter = counter + 1
84
- end
85
- end
86
- assert_equal(test_sizes.size, counter)
87
-
88
- # Now retrieve the messages destructively
89
- message = WMQ::Message.new
90
- test_sizes.each do |size|
91
- assert_equal(true, @in_queue.get(:message=>message, :match=>WMQ::MQMO_NONE))
92
- assert_equal(size, message.data.length)
93
- str = '0123456789ABCDEF' * (size/16) + '0123456789ABCDEF'[0,size%16]
94
- assert_equal(str, message.data)
95
- end
96
- end
97
-
98
- def test_q_name_hash
99
- puts '****** test_q_name_hash ******'
100
- @queue_manager.open_queue(:mode=>:output,
101
- :q_name=>{:q_name=>@in_queue.name,
102
- :q_mgr_name=>@queue_manager.name}
103
- ) do |test_queue|
104
- assert_equal(true, test_queue.put(:data=>'Hello World'))
105
- message = WMQ::Message.new
106
- assert_equal(true, @in_queue.get(:message=>message))
107
- assert_equal('Hello World', message.data)
108
- end
109
- end
110
-
111
- def test_execute
112
- puts '****** test_execute ******'
113
- array = @queue_manager.inquire_q(:q_name=>@in_queue.name, :q_type=>WMQ::MQQT_LOCAL, :current_q_depth=>nil)
114
- assert_equal(1, array.size)
115
- assert_equal(@in_queue.name, array[0][:q_name])
116
-
117
- assert_equal(true, @queue_manager.inquire_process(:process_name=>'*').size>0)
118
- assert_raise(WMQ::WMQException) { @queue_manager.inquire_q(:q_name=>'BADQUEUENAME*') }
119
- assert_equal(1, @queue_manager.ping_q_mgr.size)
120
- end
121
-
122
- def test_mqsc
123
- puts '****** test_mqsc ******'
124
- array = @queue_manager.mqsc("dis ql(#{@in_queue.name})")
125
- assert_equal(1, array.size)
126
- assert_equal(true, array[0].include?("QUEUE(#{@in_queue.name})"))
127
- end
128
-
129
- def test_put1
130
- puts '****** test_put1 ******'
131
- data = 'Some Test Data'
132
- assert_equal(true,@queue_manager.put(:q_name=>@in_queue.name, :data=>data))
133
-
134
- message = WMQ::Message.new
135
- assert_equal(true, @in_queue.get(:message=>message))
136
- assert_equal(data, message.data)
137
- end
138
-
139
- def verify_header(header, format)
140
- verify_multiple_headers([header], format)
141
- end
142
-
143
- def verify_multiple_headers(headers, format)
144
- data = 'Some Test Data'
145
- message = WMQ::Message.new
146
- message.data = data
147
- message.descriptor[:format] = format
148
- message.headers = headers
149
- #assert_equal(true,@queue_manager.put(:q_name=>@in_queue.name, :message=>message))
150
- assert_equal(true,@out_queue.put(:message=>message))
151
-
152
- message = WMQ::Message.new
153
- assert_equal(true, @in_queue.get(:message=>message))
154
- assert_equal(data, message.data)
155
- assert_equal(headers.size, message.headers.size)
156
- count = 0
157
- headers.each do |header|
158
- reply_header = message.headers[count]
159
- header.each_pair{|key, value| assert_equal(value, reply_header[key])}
160
- count = count + 1
161
- end
162
- end
163
-
164
- def test_dlh
165
- puts '****** test_dlh ******'
166
- dlh = {:header_type =>:dead_letter_header,
167
- :reason => WMQ::MQRC_UNKNOWN_REMOTE_Q_MGR,
168
- :dest_q_name =>'ORIGINAL_QUEUE_NAME',
169
- :dest_q_mgr_name =>'BAD_Q_MGR',
170
- :put_appl_name =>'TestApp.exe',
171
- }
172
-
173
- verify_header(dlh, WMQ::MQFMT_DEAD_LETTER_HEADER)
174
- # Untested keys:
175
- #:put_date=>"",
176
- #:put_time=>"",
177
- #:encoding=>0,
178
- #:coded_char_set_id=>437,
179
- #:put_appl_type=>0,
180
-
181
- # Test again, but use QueueManager#put this time
182
- data = 'Some Test Data'
183
- message = WMQ::Message.new
184
- message.data = data
185
- message.descriptor[:format] = WMQ::MQFMT_STRING
186
- message.headers << dlh
187
- assert_equal(true,@queue_manager.put(:q_name=>@in_queue.name, :message=>message))
188
-
189
- message = WMQ::Message.new
190
- assert_equal(true, @in_queue.get(:message=>message))
191
- assert_equal(data, message.data)
192
- assert_equal(1, message.headers.size)
193
- reply_header = message.headers[0]
194
-
195
- dlh.each_pair{|key, value| assert_equal(value, reply_header[key])}
196
- end
197
-
198
- def test_cics
199
- puts '****** test_cics ******'
200
- cics = {:header_type =>:cics,
201
- :reason =>WMQ::MQRC_UNKNOWN_REMOTE_Q_MGR,
202
- :facility =>'TOKEN123',
203
- :reply_to_format =>WMQ::MQFMT_STRING,
204
- }
205
- verify_header(cics, WMQ::MQFMT_NONE)
206
- end
207
-
208
- def test_ims
209
- puts '****** test_ims ******'
210
- ims = {:header_type =>:ims,
211
- :l_term_override =>'LTERM',
212
- :reply_to_format =>WMQ::MQFMT_STRING,
213
- }
214
- verify_header(ims, WMQ::MQFMT_STRING)
215
- end
216
-
217
- def test_transmission_header
218
- puts '****** test_transmission_header ******'
219
- xqh = {:header_type =>:xmit_q_header,
220
- :remote_q_name =>'SOME_REMOTE_QUEUE',
221
- :remote_q_mgr_name=>'SOME_REMOTE_Q_MGR',
222
- :msg_type =>WMQ::MQMT_REQUEST,
223
- :msg_id =>'my message Id',
224
- }
225
- verify_header(xqh, WMQ::MQFMT_STRING)
226
- end
227
-
228
- def test_rf_header
229
- puts '****** test_rf_header ******'
230
- rfh = {:header_type =>:rf_header,
231
- :name_value => {' name s' => ' v a "l" u e 1 ',
232
- 'n a m e 2 ' => 'v a l u e 2',
233
- '' => ['"', '""', '"""', '""""', ''],
234
- 'name3'=>['"value3"', '', '"',' value 43"']},
235
- }
236
- verify_header(rfh, WMQ::MQFMT_STRING)
237
- end
238
-
239
- def test_rf_header_2
240
- puts '****** test_rf_header_2 ******'
241
- rfh2 = {:header_type =>:rf_header_2,
242
- :xml => ['<hello>to the world</hello>',
243
- '<another>xml like string</another>'],
244
- }
245
- verify_header(rfh2, WMQ::MQFMT_STRING)
246
- end
247
-
248
- def test_multiple_headers
249
- puts '****** test_multiple_headers ******'
250
- headers = [{:header_type => :rf_header_2,
251
- :xml => ['<hello>to the world</hello>',
252
- '<another>xml like string</another>'],},
253
-
254
- {:header_type => :rf_header,
255
- :name_value => {' name s' => ' v a l u e 1 ',
256
- 'n a m e 2 ' => 'v a l u e 2',
257
- 'name3'=>['value3', '', 'value 43']} },
258
-
259
- {:header_type => :ims,
260
- :l_term_override => 'LTERM',
261
- :reply_to_format => WMQ::MQFMT_STRING},
262
-
263
- {:header_type => :rf_header,
264
- :name_value => {' name s' => ' v a l u e 1 ',
265
- 'n a m e 2 ' => 'v a l u e 2',
266
- 'name3'=>['value3', '', 'value 43']} },
267
-
268
- {:header_type => :cics,
269
- :reason => WMQ::MQRC_UNKNOWN_REMOTE_Q_MGR,
270
- :facility => 'TOKEN123',
271
- :reply_to_format => WMQ::MQFMT_STRING},
272
-
273
- {:header_type => :rf_header_2,
274
- :xml => ['<hello>to the world</hello>', '<another>xml like string</another>'],},
275
-
276
- {:header_type => :xmit_q_header,
277
- :remote_q_name => 'SOME_REMOTE_QUEUE',
278
- :remote_q_mgr_name=> 'SOME_REMOTE_Q_MGR',
279
- :msg_type => WMQ::MQMT_REQUEST,
280
- :msg_id => 'my message Id'},
281
- ]
282
- verify_multiple_headers(headers, WMQ::MQFMT_STRING)
283
- end
284
-
285
- def test_xmit_multiple_headers
286
- puts '****** test_xmit_q_header with ims header ******'
287
- headers = [{:header_type => :xmit_q_header,
288
- :remote_q_name => 'SOME_REMOTE_QUEUE',
289
- :remote_q_mgr_name=> 'SOME_REMOTE_Q_MGR',
290
- :msg_type => WMQ::MQMT_REQUEST,
291
- :msg_id => 'my message Id'},
292
-
293
- {:header_type => :ims,
294
- :l_term_override => 'LTERM',
295
- :reply_to_format => WMQ::MQFMT_STRING},
296
- ]
297
- verify_multiple_headers(headers, WMQ::MQFMT_STRING)
298
- end
299
-
300
- def test_message_grouping
301
- puts '****** test_message_grouping ******'
302
- # Clear out queue of any messages
303
- @in_queue.each { |message| }
304
-
305
- msg = WMQ::Message.new
306
- msg.data = 'First'
307
- msg.descriptor[:msg_flags] = WMQ::MQMF_MSG_IN_GROUP
308
- assert_equal(@out_queue.put(:message=>msg, :options => WMQ::MQPMO_LOGICAL_ORDER), true)
309
-
310
- msg.data = 'Second'
311
- assert_equal(@out_queue.put(:message=>msg, :options => WMQ::MQPMO_LOGICAL_ORDER), true)
312
-
313
- msg.data = 'Last'
314
- msg.descriptor[:msg_flags] = WMQ::MQMF_LAST_MSG_IN_GROUP
315
- assert_equal(@out_queue.put(:message=>msg, :options => WMQ::MQPMO_LOGICAL_ORDER), true)
316
- end
317
-
318
- end