19
19
package com.mongodb
20
20
21
21
import spock.lang.Specification
22
- import spock.lang.Subject
23
22
24
23
import javax.management.ObjectName
25
24
import java.lang.management.ManagementFactory
@@ -30,14 +29,12 @@ class JMXConnectionPoolListenerSpecification extends Specification {
30
29
private static final String CLUSTER_ID = ' 42'
31
30
private static final ServerAddress SERVER_ADDRESS = new ServerAddress ()
32
31
33
- @Subject
34
- private final JMXConnectionPoolListener jmxListener = new JMXConnectionPoolListener ()
35
-
36
32
private final openEvent = new ConnectionPoolOpenedEvent (CLUSTER_ID , SERVER_ADDRESS ,
37
33
ConnectionPoolSettings . builder(). maxSize(5 ). maxWaitTime(1 , SECONDS ). build())
38
34
39
35
def ' statistics should reflect values from the provider' () {
40
36
given :
37
+ def jmxListener = new JMXConnectionPoolListener (null )
41
38
def event = new ConnectionEvent (CLUSTER_ID , SERVER_ADDRESS )
42
39
43
40
when :
@@ -70,6 +67,7 @@ class JMXConnectionPoolListenerSpecification extends Specification {
70
67
71
68
def ' should remove MBean' () {
72
69
given :
70
+ def jmxListener = new JMXConnectionPoolListener (null )
73
71
jmxListener. connectionPoolOpened(openEvent);
74
72
75
73
when :
@@ -82,6 +80,7 @@ class JMXConnectionPoolListenerSpecification extends Specification {
82
80
83
81
def ' should create a valid ObjectName for hostname' () {
84
82
given :
83
+ def jmxListener = new JMXConnectionPoolListener (null )
85
84
String beanName = jmxListener. getMBeanObjectName(CLUSTER_ID , new ServerAddress (' localhost' ));
86
85
87
86
when :
@@ -93,6 +92,7 @@ class JMXConnectionPoolListenerSpecification extends Specification {
93
92
94
93
def ' should create a valid ObjectName for ipv4 addresses' () {
95
94
given :
95
+ def jmxListener = new JMXConnectionPoolListener (null )
96
96
String beanName = jmxListener. getMBeanObjectName(CLUSTER_ID , new ServerAddress (' 127.0.0.1' ))
97
97
98
98
when :
@@ -104,6 +104,7 @@ class JMXConnectionPoolListenerSpecification extends Specification {
104
104
105
105
def ' should create a valid ObjectName for ipv6 address' () {
106
106
given :
107
+ def jmxListener = new JMXConnectionPoolListener (null )
107
108
String beanName = jmxListener. getMBeanObjectName(CLUSTER_ID , new ServerAddress (' [::1]' ))
108
109
109
110
when :
@@ -115,6 +116,7 @@ class JMXConnectionPoolListenerSpecification extends Specification {
115
116
116
117
def ' should create a valid ObjectName when cluster id has a :' () {
117
118
given :
119
+ def jmxListener = new JMXConnectionPoolListener (null )
118
120
String beanName = jmxListener. getMBeanObjectName(' kd:dk' , new ServerAddress ())
119
121
120
122
when :
@@ -123,4 +125,30 @@ class JMXConnectionPoolListenerSpecification extends Specification {
123
125
then :
124
126
objectName. toString() == ' org.mongodb.driver:type=ConnectionPool,clusterId=kd%3Adk,host=127.0.0.1,port=27017'
125
127
}
128
+
129
+ def ' should include a non-null cluster description in the object name' () {
130
+ given :
131
+ def jmxListener = new JMXConnectionPoolListener (' cluster description 1' )
132
+ String beanName = jmxListener. getMBeanObjectName(' 1' , new ServerAddress ())
133
+
134
+ when :
135
+ ObjectName objectName = new ObjectName (beanName)
136
+
137
+ then :
138
+ objectName. toString() ==
139
+ ' org.mongodb.driver:type=ConnectionPool,clusterId=1,host=127.0.0.1,port=27017,description=cluster description 1'
140
+ }
141
+
142
+ def ' should replace colon in cluster description' () {
143
+ given :
144
+ def jmxListener = new JMXConnectionPoolListener (' description: 1' )
145
+ String beanName = jmxListener. getMBeanObjectName(' 1' , new ServerAddress ())
146
+
147
+ when :
148
+ ObjectName objectName = new ObjectName (beanName)
149
+
150
+ then :
151
+ objectName. toString() ==
152
+ ' org.mongodb.driver:type=ConnectionPool,clusterId=1,host=127.0.0.1,port=27017,description=description%3A 1'
153
+ }
126
154
}
0 commit comments