rjack-jms 1.0.0-java → 1.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,2 +1,8 @@
1
+ === 1.1.0 (2011-3-10)
2
+ * Added JMSConnector and ConnectListener for JMS (re-)connect.
3
+ * Added SessionExecutor, SessionStateFactory, SessionTask for client
4
+ session thread pool support.
5
+ * slf4j (and dev: logback) dependency for logging in above.
6
+
1
7
  === 1.0.0 (2011-2-5)
2
8
  * Initial release.
data/Manifest.txt CHANGED
@@ -6,5 +6,8 @@ Rakefile
6
6
  pom.xml
7
7
  lib/rjack-jms/base.rb
8
8
  lib/rjack-jms.rb
9
- test/test_jms.rb
10
- lib/rjack-jms/rjack-jms-1.0.0.jar
9
+ test/mocks.rb
10
+ test/setup.rb
11
+ test/test_executor.rb
12
+ test/test_jms_connector.rb
13
+ lib/rjack-jms/rjack-jms-1.1.0.jar
data/README.rdoc CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  == Description
7
7
 
8
- Java Messaging Service utilities, with gem packaging.
8
+ Java Messaging Service (JMS) utilities, with gem packaging.
9
9
 
10
10
  == License
11
11
 
data/Rakefile CHANGED
@@ -14,11 +14,13 @@ t = TarPit.new( 'rjack-jms', JMS::VERSION,
14
14
 
15
15
  t.specify do |h|
16
16
  h.developer( "David Kellum", "dek-oss@gravitext.com" )
17
+ h.extra_deps += [ [ 'rjack-slf4j', '>= 1.5.8', '< 1.7' ],
18
+ [ 'rjack-jms-spec', '~> 1.1.1' ] ]
19
+ h.rdoc_locations << "dekellum@rubyforge.org:/var/www/gforge-projects/rjack/jms"
17
20
 
18
- h.extra_deps += [ [ 'rjack-jms-spec', '~> 1.1.1' ] ]
19
-
20
- h.rubyforge_name = "rjack"
21
- h.remote_rdoc_dir = "jms"
21
+ h.testlib = :minitest
22
+ h.extra_dev_deps += [ [ 'rjack-logback', '>= 0.9.18', '< 2.0' ],
23
+ [ 'minitest', '>= 1.7.1', '< 2.1' ] ]
22
24
  end
23
25
 
24
26
  file 'Manifest.txt' => [ "lib/#{t.name}/base.rb" ]
data/lib/rjack-jms.rb CHANGED
@@ -17,12 +17,21 @@
17
17
  require 'rjack-jms/base'
18
18
 
19
19
  require 'rjack-jms-spec'
20
+ require 'rjack-slf4j'
21
+
22
+ require 'java'
20
23
 
21
24
  module RJack
22
25
  module JMS
23
26
  require "rjack-jms/rjack-jms-#{VERSION}.jar"
24
27
 
28
+ import 'rjack.jms.ConnectListener'
29
+ import 'rjack.jms.JMSConnector'
25
30
  import 'rjack.jms.JMSContext'
26
-
31
+ import 'rjack.jms.JMSRuntimeException'
32
+ import 'rjack.jms.SessionExecutor'
33
+ import 'rjack.jms.SessionState'
34
+ import 'rjack.jms.SessionStateFactory'
35
+ import 'rjack.jms.SessionTask'
27
36
  end
28
37
  end
@@ -16,6 +16,6 @@
16
16
 
17
17
  module RJack
18
18
  module JMS
19
- VERSION = '1.0.0'
19
+ VERSION = '1.1.0'
20
20
  end
21
21
  end
Binary file
data/pom.xml CHANGED
@@ -4,7 +4,7 @@
4
4
  <groupId>rjack</groupId>
5
5
  <artifactId>rjack-jms</artifactId>
6
6
  <packaging>jar</packaging>
7
- <version>1.0.0</version>
7
+ <version>1.1.0</version>
8
8
  <name>Java Message Service Utilizes</name>
9
9
 
10
10
  <developers>
@@ -48,6 +48,13 @@
48
48
  <version>[1.1.1,1.2)</version>
49
49
  </dependency>
50
50
 
51
+ <dependency>
52
+ <groupId>org.slf4j</groupId>
53
+ <artifactId>slf4j-api</artifactId>
54
+ <version>[1.6.1,1.7)</version>
55
+ <scope>compile</scope>
56
+ </dependency>
57
+
51
58
  </dependencies>
52
59
 
53
60
  <build>
data/test/mocks.rb ADDED
@@ -0,0 +1,90 @@
1
+ #--
2
+ # Copyright (c) 2011 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You may
6
+ # 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
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ # Base class for mocks, keeps a called list
18
+ class TrackingMock
19
+ attr_reader :called
20
+
21
+ def initialize
22
+ @called = []
23
+ end
24
+
25
+ def method_missing( name, *args )
26
+ called << name
27
+ end
28
+ end
29
+
30
+ class Connection < TrackingMock
31
+ include javax.jms.Connection
32
+
33
+ attr_accessor :exception_listener
34
+ end
35
+
36
+ class Context < TrackingMock
37
+ include RJack::JMS::JMSContext
38
+
39
+ def create_connection
40
+ called << :create_connection
41
+ Connection.new
42
+ end
43
+
44
+ def create_session( *args )
45
+ called << :create_session
46
+ TrackingMock.new
47
+ end
48
+
49
+ end
50
+
51
+ class Listener < TrackingMock
52
+ include RJack::JMS::ConnectListener
53
+ end
54
+
55
+ class TestSessionStateFactory < TrackingMock
56
+ include RJack::JMS::SessionStateFactory
57
+
58
+ attr_reader :last_session
59
+ attr_reader :session_count
60
+
61
+ def create_session_state( *args )
62
+ called << :create_session_state
63
+ @session_count ||= 0
64
+ @session_count += 1
65
+ @last_session = TestSessionState.new( *args )
66
+ end
67
+
68
+ end
69
+
70
+ class TestSessionState < RJack::JMS::SessionState
71
+ def close
72
+ super
73
+ @closed = true
74
+ end
75
+
76
+ def closed?
77
+ @closed
78
+ end
79
+ end
80
+
81
+ class TestSessionTask < RJack::JMS::SessionTask
82
+ def initialize( &block )
83
+ super()
84
+ @block = block
85
+ end
86
+
87
+ def runTask( state )
88
+ @block.call( state )
89
+ end
90
+ end
data/test/setup.rb ADDED
@@ -0,0 +1,50 @@
1
+ #--
2
+ # Copyright (c) 2011 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You may
6
+ # 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
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ #### General test setup: LOAD_PATH, logging, console output ####
18
+
19
+ test_dir = File.dirname( __FILE__ )
20
+ ldir = File.join( test_dir, "..", "lib" )
21
+ $LOAD_PATH.unshift( ldir ) unless $LOAD_PATH.include?( ldir )
22
+
23
+ $LOAD_PATH.unshift( test_dir ) unless $LOAD_PATH.include?( test_dir )
24
+
25
+ require 'rubygems'
26
+ require 'rjack-logback'
27
+
28
+ require 'rjack-jms'
29
+
30
+ require 'minitest/unit'
31
+ require 'minitest/autorun'
32
+
33
+ RJack::Logback.config_console( :stderr => true )
34
+
35
+ if ARGV.include?( '-v' ) || ARGV.include?( '-verbose' )
36
+
37
+ RJack::Logback.root.level = RJack::Logback::DEBUG
38
+ RJack::Logback[ 'rjack.jms.JMSConnector' ].level = RJack::Logback::INFO
39
+
40
+ # Make test output logging compatible: no partial lines.
41
+ class TestOut
42
+ def print( *a ); $stdout.puts( *a ); end
43
+ def puts( *a ); $stdout.puts( *a ); end
44
+ end
45
+ MiniTest::Unit.output = TestOut.new
46
+
47
+ else
48
+ #Squelch test logging
49
+ RJack::Logback[ 'rjack.jms' ].level = RJack::Logback::ERROR
50
+ end
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env jruby
2
+ #.hashdot.profile += jruby-shortlived
3
+ #--
4
+ # Copyright (c) 2011 David Kellum
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
7
+ # may not use this file except in compliance with the License. You
8
+ # may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
+ # implied. See the License for the specific language governing
16
+ # permissions and limitations under the License.
17
+ #++
18
+
19
+ require File.join( File.dirname( __FILE__ ), "setup" )
20
+
21
+ require 'mocks'
22
+
23
+ class TestExecutor < MiniTest::Unit::TestCase
24
+ include RJack::JMS
25
+
26
+ import 'javax.jms.JMSException'
27
+
28
+ def setup
29
+ @connector = JMSConnector.new( @context = Context.new )
30
+ @session_factory = TestSessionStateFactory.new
31
+ @executor = SessionExecutor.new( @connector,
32
+ @session_factory,
33
+ 3, #queue length
34
+ 1 ) #threads
35
+ @connector.start
36
+ end
37
+
38
+ def teardown
39
+ shutdown
40
+ @connector.stop
41
+ @connector = nil
42
+ end
43
+
44
+ def shutdown
45
+ if @executor
46
+ @executor.shutdown
47
+ @executor.awaitTermination( 3, java.util.concurrent.TimeUnit::SECONDS )
48
+ @executor = nil
49
+ end
50
+ end
51
+
52
+ def test_start_shutdown
53
+ end
54
+
55
+ def test_execute
56
+ ran = false
57
+
58
+ task = TestSessionTask.new do |session_state|
59
+ ran = true
60
+ assert_kind_of( TestSessionState, session_state )
61
+ end
62
+
63
+ @executor.execute( task )
64
+
65
+ shutdown
66
+ assert( ran, "Test task should have run by now" )
67
+
68
+ sleep 0.1 #FIXME: awaitTerminate can return before SessionThread.close
69
+ assert( @session_factory.last_session.closed?,
70
+ "SessionState should be closed" )
71
+ end
72
+
73
+ def test_execute_many
74
+
75
+ runs = 0
76
+ 5.times { @executor.execute( TestSessionTask.new { runs += 1 } ) }
77
+
78
+ shutdown
79
+ assert_equal( 5, runs, "All 5 tasks should have run" )
80
+
81
+ sleep 0.1 #FIXME: awaitTerminate can return before SessionThread.close
82
+ assert( @session_factory.last_session.closed?,
83
+ "SessionState should be closed" )
84
+ assert_equal( 1, @session_factory.session_count,
85
+ "Should run all in one session." )
86
+ end
87
+
88
+ def test_jms_exception
89
+ task = TestSessionTask.new { raise JMSException.new( "test" ) }
90
+ @executor.execute( task )
91
+
92
+ ran = false
93
+ @executor.execute( TestSessionTask.new { ran = true } )
94
+
95
+ shutdown
96
+ assert( ran, "Test task should have run by now" )
97
+ assert_equal( 2, @session_factory.session_count,
98
+ "Two sessions given first task failure." )
99
+ end
100
+
101
+ end
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env jruby
2
+ #.hashdot.profile += jruby-shortlived
3
+ #--
4
+ # Copyright (c) 2011 David Kellum
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
7
+ # may not use this file except in compliance with the License. You
8
+ # may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
+ # implied. See the License for the specific language governing
16
+ # permissions and limitations under the License.
17
+ #++
18
+
19
+ require File.join( File.dirname( __FILE__ ), "setup" )
20
+
21
+ require 'mocks'
22
+
23
+ class TestJMSConnector < MiniTest::Unit::TestCase
24
+ include RJack::JMS
25
+
26
+ import 'javax.jms.JMSException'
27
+ import 'javax.naming.NamingException'
28
+
29
+ def setup
30
+ @connector = JMSConnector.new( @context = Context.new )
31
+ end
32
+
33
+ def test_start_stop
34
+ @connector.start
35
+ # May or may not actually run in time before stop.
36
+ # But shouldn't deadlock.
37
+ @connector.stop
38
+ end
39
+
40
+ def test_start_await_stop
41
+ @connector.add_connect_listener( listener = Listener.new )
42
+ @connector.start
43
+
44
+ con = @connector.await_connection
45
+ assert_kind_of( Connection, con )
46
+ assert_includes( listener.called, :onConnect )
47
+ assert_includes( con.called, :start )
48
+
49
+ @connector.stop
50
+ assert_includes( @context.called, :close )
51
+ end
52
+
53
+ def test_on_exception
54
+ @connector.start
55
+
56
+ con = @connector.await_connection
57
+ assert_includes( con.called, :start )
58
+
59
+ con.exception_listener.on_exception( JMSException.new( "test" ) )
60
+
61
+ con2 = @connector.await_connection
62
+ assert_includes( con.called, :close ) # closed in connection loop
63
+
64
+ refute_equal( con, con2 )
65
+ assert_includes( con2.called, :start )
66
+
67
+ @connector.stop
68
+ assert_includes( @context.called, :close )
69
+ end
70
+
71
+ def test_failed_listener
72
+ @connector.add_connect_listener( listener = Listener.new )
73
+
74
+ def listener.on_connect( *args )
75
+ raise NamingException.new( "test" )
76
+ end
77
+
78
+ assert_raises( NativeException, NamingException ) do
79
+ @connector.connect_loop
80
+ end
81
+
82
+ assert_includes( @context.called, :close )
83
+ end
84
+
85
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjack-jms
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 0
8
- - 0
9
- version: 1.0.0
4
+ prerelease:
5
+ version: 1.1.0
10
6
  platform: java
11
7
  authors:
12
8
  - David Kellum
@@ -14,38 +10,74 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-02-05 00:00:00 -08:00
13
+ date: 2011-03-10 00:00:00 -08:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
21
- name: rjack-jms-spec
17
+ name: rjack-slf4j
22
18
  prerelease: false
23
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.5.8
25
+ - - <
26
+ - !ruby/object:Gem::Version
27
+ version: "1.7"
28
+ type: :runtime
29
+ version_requirements: *id001
30
+ - !ruby/object:Gem::Dependency
31
+ name: rjack-jms-spec
32
+ prerelease: false
33
+ requirement: &id002 !ruby/object:Gem::Requirement
34
+ none: false
24
35
  requirements:
25
36
  - - ~>
26
37
  - !ruby/object:Gem::Version
27
- segments:
28
- - 1
29
- - 1
30
- - 1
31
38
  version: 1.1.1
32
39
  type: :runtime
33
- version_requirements: *id001
40
+ version_requirements: *id002
41
+ - !ruby/object:Gem::Dependency
42
+ name: rjack-logback
43
+ prerelease: false
44
+ requirement: &id003 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.9.18
50
+ - - <
51
+ - !ruby/object:Gem::Version
52
+ version: "2.0"
53
+ type: :development
54
+ version_requirements: *id003
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ prerelease: false
58
+ requirement: &id004 !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.7.1
64
+ - - <
65
+ - !ruby/object:Gem::Version
66
+ version: "2.1"
67
+ type: :development
68
+ version_requirements: *id004
34
69
  - !ruby/object:Gem::Dependency
35
70
  name: rjack-tarpit
36
71
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
72
+ requirement: &id005 !ruby/object:Gem::Requirement
73
+ none: false
38
74
  requirements:
39
75
  - - ~>
40
76
  - !ruby/object:Gem::Version
41
- segments:
42
- - 1
43
- - 3
44
- - 0
45
77
  version: 1.3.0
46
78
  type: :development
47
- version_requirements: *id002
48
- description: Java Messaging Service utilities, with gem packaging.
79
+ version_requirements: *id005
80
+ description: Java Messaging Service (JMS) utilities, with gem packaging.
49
81
  email:
50
82
  - dek-oss@gravitext.com
51
83
  executables: []
@@ -66,8 +98,11 @@ files:
66
98
  - pom.xml
67
99
  - lib/rjack-jms/base.rb
68
100
  - lib/rjack-jms.rb
69
- - test/test_jms.rb
70
- - lib/rjack-jms/rjack-jms-1.0.0.jar
101
+ - test/mocks.rb
102
+ - test/setup.rb
103
+ - test/test_executor.rb
104
+ - test/test_jms_connector.rb
105
+ - lib/rjack-jms/rjack-jms-1.1.0.jar
71
106
  has_rdoc: true
72
107
  homepage: http://rjack.rubyforge.org
73
108
  licenses: []
@@ -79,25 +114,24 @@ rdoc_options:
79
114
  require_paths:
80
115
  - lib
81
116
  required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
82
118
  requirements:
83
119
  - - ">="
84
120
  - !ruby/object:Gem::Version
85
- segments:
86
- - 0
87
121
  version: "0"
88
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
89
124
  requirements:
90
125
  - - ">="
91
126
  - !ruby/object:Gem::Version
92
- segments:
93
- - 0
94
127
  version: "0"
95
128
  requirements: []
96
129
 
97
- rubyforge_project: rjack
98
- rubygems_version: 1.3.6
130
+ rubyforge_project: rjack-jms
131
+ rubygems_version: 1.5.1
99
132
  signing_key:
100
133
  specification_version: 3
101
- summary: Java Messaging Service utilities, with gem packaging.
134
+ summary: Java Messaging Service (JMS) utilities, with gem packaging.
102
135
  test_files:
103
- - test/test_jms.rb
136
+ - test/test_jms_connector.rb
137
+ - test/test_executor.rb
Binary file
data/test/test_jms.rb DELETED
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env jruby
2
- #.hashdot.profile += jruby-shortlived
3
- #--
4
- # Copyright (c) 2011 David Kellum
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License"); you
7
- # may not use this file except in compliance with the License. You
8
- # may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
- # implied. See the License for the specific language governing
16
- # permissions and limitations under the License.
17
- #++
18
-
19
- $LOAD_PATH.unshift File.join( File.dirname(__FILE__), "..", "lib" )
20
-
21
- require 'java'
22
- require 'rubygems'
23
-
24
- require 'rjack-jms'
25
-
26
- require 'test/unit'
27
-
28
- class TestJMS < Test::Unit::TestCase
29
-
30
- def test_load
31
- assert( true ) #FIXME: Just asserting that the load works for now
32
- end
33
- end