jmx4r 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require "rubygems"
6
6
 
7
7
  dir = File.dirname(__FILE__)
8
8
  lib = File.join(dir, "lib", "jmx4r.rb")
9
- version = "0.1.0"
9
+ version = "0.1.1"
10
10
 
11
11
  task :default => [:test]
12
12
 
data/lib/dynamic_mbean.rb CHANGED
@@ -252,7 +252,7 @@ module JMX
252
252
 
253
253
  def getAttributes(attributes)
254
254
  attrs = javax.management.AttributeList.new
255
- attributes.each { |attribute| send("jmx_get_"+attribute.downcase) }
255
+ attributes.each { |attribute| attrs.add(getAttribute(attribute)) }
256
256
  attrs
257
257
  end
258
258
 
data/lib/jmx4r.rb CHANGED
@@ -148,7 +148,7 @@ module JMX
148
148
  # [:command] the pattern matches the command line of the local
149
149
  # JVM process including the MBean server.
150
150
  # (command lines are listed on the connection dialog
151
- # in JConsole).
151
+ # in JConsole).
152
152
  # No default.
153
153
  # this feature needs a JDK (>=5) installed on the local
154
154
  # system.
@@ -24,10 +24,11 @@ class TestDynamicMBean < Test::Unit::TestCase
24
24
 
25
25
  def test_attribute_types
26
26
  mbean = AttributeTypesMBean.new
27
- mbeanServer = ManagementFactory.platform_mbean_server
28
- mbeanServer.register_mbean mbean, ObjectName.new("jmx4r:name=AttributeTypesMBean")
27
+ object_name = ObjectName.new "jmx4r:name=AttributeTypesMBean"
28
+ mbean_server = ManagementFactory.platform_mbean_server
29
+ mbean_server.register_mbean mbean, object_name
29
30
 
30
- mbean = JMX::MBean.find_by_name "jmx4r:name=AttributeTypesMBean", :connection => mbeanServer
31
+ mbean = JMX::MBean.find_by_name object_name.to_s, :connection => mbean_server
31
32
  mbean.string_attr = "test"
32
33
  assert_equal("test", mbean.string_attr)
33
34
 
@@ -57,6 +58,8 @@ class TestDynamicMBean < Test::Unit::TestCase
57
58
 
58
59
  mbean.boolean_attr = true
59
60
  assert_equal(true, mbean.boolean_attr)
61
+
62
+ mbean_server.unregister_mbean object_name
60
63
  end
61
64
 
62
65
  class OperationInvocationMBean < JMX::DynamicMBean
@@ -70,11 +73,14 @@ class TestDynamicMBean < Test::Unit::TestCase
70
73
 
71
74
  def test_operation_invocation
72
75
  mbean = OperationInvocationMBean.new
73
- mbeanServer = ManagementFactory.platform_mbean_server
74
- mbeanServer.register_mbean mbean, ObjectName.new("jmx4r:name=OperationInvocationMBean")
76
+ object_name = ObjectName.new "jmx4r:name=OperationInvocationMBean"
77
+ mbean_server = ManagementFactory.platform_mbean_server
78
+ mbean_server.register_mbean mbean, object_name
75
79
 
76
- mbean = JMX::MBean.find_by_name "jmx4r:name=OperationInvocationMBean", :connection => mbeanServer
80
+ mbean = JMX::MBean.find_by_name object_name.to_s, :connection => mbean_server
77
81
  assert_equal("oof", mbean.reverse("foo"))
82
+
83
+ mbean_server.unregister_mbean object_name
78
84
  end
79
85
 
80
86
  class Foo < JMX::DynamicMBean
@@ -101,10 +107,12 @@ class TestDynamicMBean < Test::Unit::TestCase
101
107
 
102
108
  def test_separate_dynamic_beans_have_separate_operations_and_attributes
103
109
  mbean_server = ManagementFactory.platform_mbean_server
104
- mbean_server.register_mbean Foo.new, ObjectName.new("jmx4r:name=foo")
105
- mbean_server.register_mbean Bar.new, ObjectName.new("jmx4r:name=bar")
110
+ foo_object_name = ObjectName.new "jmx4r:name=foo"
111
+ bar_object_name = ObjectName.new "jmx4r:name=bar"
112
+ mbean_server.register_mbean Foo.new, foo_object_name
113
+ mbean_server.register_mbean Bar.new, bar_object_name
106
114
 
107
- foo_mbean = JMX::MBean.find_by_name "jmx4r:name=foo", :connection => mbean_server
115
+ foo_mbean = JMX::MBean.find_by_name foo_object_name.to_s, :connection => mbean_server
108
116
  assert_equal "foo test", foo_mbean.foo("test")
109
117
  assert_raise(NoMethodError){
110
118
  foo_mbean.bar("test")
@@ -114,7 +122,7 @@ class TestDynamicMBean < Test::Unit::TestCase
114
122
  assert_raise(NoMethodError){
115
123
  foo_mbean.bar_attr = "test"
116
124
  }
117
- bar_mbean = JMX::MBean.find_by_name "jmx4r:name=bar", :connection => mbean_server
125
+ bar_mbean = JMX::MBean.find_by_name bar_object_name.to_s, :connection => mbean_server
118
126
  assert_equal "bar test", bar_mbean.bar("test")
119
127
  assert_raise(NoMethodError) {
120
128
  bar_mbean.foo("test")
@@ -124,5 +132,24 @@ class TestDynamicMBean < Test::Unit::TestCase
124
132
  assert_raise(NoMethodError){
125
133
  bar_mbean.foo_attr = "test"
126
134
  }
135
+
136
+ mbean_server.unregister_mbean foo_object_name
137
+ mbean_server.unregister_mbean bar_object_name
138
+ end
139
+
140
+ def test_get_attributes
141
+ foo = Foo.new
142
+ foo.foo_attr = "value"
143
+
144
+ object_name = ObjectName.new "jmx4r:name=baz"
145
+ mbean_server = ManagementFactory.platform_mbean_server
146
+ mbean_server.register_mbean foo, object_name
147
+
148
+ foo_mbean = JMX::MBean.find_by_name object_name.to_s, :connection => mbean_server
149
+ attrs = mbean_server.get_attributes object_name, ["foo_attr"].to_java(:string)
150
+ assert_equal foo.foo_attr, attrs[0]
151
+
152
+ mbean_server.unregister_mbean object_name
153
+
127
154
  end
128
155
  end
metadata CHANGED
@@ -68,17 +68,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  version:
69
69
  extensions: []
70
70
 
71
- rubygems_version: 1.3.3
71
+ rubygems_version: 1.3.5
72
72
  requirements: []
73
73
 
74
74
  authors:
75
75
  - Jeff Mesnil
76
- date: 2009-10-21 22:00:00 +00:00
76
+ date: 2010-07-27 22:00:00 +00:00
77
77
  platform: ruby
78
78
  test_files:
79
79
  - test/ts_all.rb
80
80
  version: !ruby/object:Gem::Version
81
- version: 0.1.0
81
+ version: 0.1.1
82
82
  require_paths:
83
83
  - lib
84
84
  dependencies: []