rubywmq 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ ################################################################################
2
+ # Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ################################################################################
16
+
17
+ # Load wmq that uses auto-load library.
18
+ #
19
+ # If it fails, then it is likely due to this platform not being supported
20
+ # by auto load facility in Ruby WMQ, so try to load client linked library
21
+ begin
22
+ require 'wmq/wmq'
23
+ rescue LoadError
24
+ require 'wmq/wmq_client'
25
+ end
@@ -0,0 +1,299 @@
1
+ # Shift include path to use locally built copy of rubywmq - For testing dev builds only
2
+ #$:.unshift '../lib'
3
+
4
+ require 'wmq/wmq'
5
+ require 'wmq/wmq_const_admin'
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 => 'REID') #, :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
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.1
3
+ specification_version: 1
4
+ name: rubywmq
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.3.0
7
+ date: 2007-01-19 00:00:00 -05:00
8
+ summary: Ruby interface into WebSphere MQ (MQSeries)
9
+ require_paths:
10
+ - lib
11
+ email: rubywmq@gmail.com
12
+ homepage: http://rubywmq.rubyforge.org
13
+ rubyforge_project: rubywmq
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Reid Morrison
31
+ files:
32
+ - examples/each_a.rb
33
+ - examples/each_b.rb
34
+ - examples/each_header.rb
35
+ - examples/files_to_q.rb
36
+ - examples/get_a.rb
37
+ - examples/get_client.rb
38
+ - examples/put1_a.rb
39
+ - examples/put1_b.rb
40
+ - examples/put1_c.rb
41
+ - examples/put_a.rb
42
+ - examples/put_b.rb
43
+ - examples/put_dlh.rb
44
+ - examples/put_dynamic_q.rb
45
+ - examples/put_rfh.rb
46
+ - examples/put_rfh2_a.rb
47
+ - examples/put_rfh2_b.rb
48
+ - examples/put_xmit_q.rb
49
+ - examples/request.rb
50
+ - examples/server.rb
51
+ - .document
52
+ - lib/wmq.rb
53
+ - ext/lib/wmq_temp.rb
54
+ - ext/decode_rfh.h
55
+ - ext/decode_rfh.c
56
+ - ext/wmq.h
57
+ - ext/wmq.c
58
+ - ext/wmq_message.c
59
+ - ext/wmq_mq_load.c
60
+ - ext/wmq_queue.c
61
+ - ext/wmq_queue_manager.c
62
+ - ext/extconf.rb
63
+ - ext/extconf_client.rb
64
+ - ext/build.bat
65
+ - ext/build.sh
66
+ - ext/generate/generate_const.rb
67
+ - ext/generate/generate_reason.rb
68
+ - ext/generate/generate_structs.rb
69
+ - ext/generate/wmq_structs.erb
70
+ - examples/files_to_q.cfg
71
+ - README
72
+ - LICENSE
73
+ test_files:
74
+ - tests/test.rb
75
+ rdoc_options: []
76
+
77
+ extra_rdoc_files:
78
+ - README
79
+ - LICENSE
80
+ executables: []
81
+
82
+ extensions:
83
+ - ext/extconf.rb
84
+ requirements:
85
+ - WebSphere MQ, v5.3 or greater
86
+ dependencies: []
87
+