File tree Expand file tree Collapse file tree 6 files changed +77
-0
lines changed
main/com/mongodb/connection
test/unit/com/mongodb/connection Expand file tree Collapse file tree 6 files changed +77
-0
lines changed Original file line number Diff line number Diff line change @@ -268,6 +268,19 @@ public Builder addClusterListener(final ClusterListener clusterListener) {
268
268
return this ;
269
269
}
270
270
271
+ /**
272
+ * Sets the cluster listeners.
273
+ *
274
+ * @param clusterListeners list of cluster listeners
275
+ * @return this
276
+ * @since 4.5
277
+ */
278
+ public Builder clusterListenerList (final List <ClusterListener > clusterListeners ) {
279
+ notNull ("clusterListeners" , clusterListeners );
280
+ this .clusterListeners = new ArrayList <>(clusterListeners );
281
+ return this ;
282
+ }
283
+
271
284
/**
272
285
* Takes the settings from the given {@code ConnectionString} and applies them to the builder
273
286
*
Original file line number Diff line number Diff line change @@ -215,6 +215,19 @@ public Builder addConnectionPoolListener(final ConnectionPoolListener connection
215
215
return this ;
216
216
}
217
217
218
+ /**
219
+ * Sets the connection pool listeners.
220
+ *
221
+ * @param connectionPoolListeners list of connection pool listeners
222
+ * @return this
223
+ * @since 4.5
224
+ */
225
+ public Builder connectionPoolListenerList (final List <ConnectionPoolListener > connectionPoolListeners ) {
226
+ notNull ("connectionPoolListeners" , connectionPoolListeners );
227
+ this .connectionPoolListeners = new ArrayList <>(connectionPoolListeners );
228
+ return this ;
229
+ }
230
+
218
231
/**
219
232
* The maximum number of connections a pool may be establishing concurrently.
220
233
*
Original file line number Diff line number Diff line change @@ -130,6 +130,19 @@ public Builder addServerListener(final ServerListener serverListener) {
130
130
return this ;
131
131
}
132
132
133
+ /**
134
+ * Sets the server listeners.
135
+ *
136
+ * @param serverListeners list of server listeners
137
+ * @return this
138
+ * @since 4.5
139
+ */
140
+ public Builder serverListenerList (final List <ServerListener > serverListeners ) {
141
+ notNull ("serverListeners" , serverListeners );
142
+ this .serverListeners = new ArrayList <>(serverListeners );
143
+ return this ;
144
+ }
145
+
133
146
/**
134
147
* Adds a server monitor listener.
135
148
*
@@ -143,6 +156,19 @@ public Builder addServerMonitorListener(final ServerMonitorListener serverMonito
143
156
return this ;
144
157
}
145
158
159
+ /**
160
+ * Sets the server monitor listeners.
161
+ *
162
+ * @param serverMonitorListeners list of server monitor listeners
163
+ * @return this
164
+ * @since 4.5
165
+ */
166
+ public Builder serverMonitorListenerList (final List <ServerMonitorListener > serverMonitorListeners ) {
167
+ notNull ("serverMonitorListeners" , serverMonitorListeners );
168
+ this .serverMonitorListeners = new ArrayList <>(serverMonitorListeners );
169
+ return this ;
170
+ }
171
+
146
172
/**
147
173
* Takes the settings from the given {@code ConnectionString} and applies them to the builder
148
174
*
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ class ClusterSettingsSpecification extends Specification {
48
48
when :
49
49
def listenerOne = Mock (ClusterListener )
50
50
def listenerTwo = Mock (ClusterListener )
51
+ def listenerThree = Mock (ClusterListener )
51
52
def settings = ClusterSettings . builder()
52
53
.hosts(hosts)
53
54
.mode(ClusterConnectionMode . MULTIPLE )
@@ -68,6 +69,12 @@ class ClusterSettingsSpecification extends Specification {
68
69
settings. serverSelector == serverSelector
69
70
settings. getServerSelectionTimeout(TimeUnit . MILLISECONDS ) == 1000
70
71
settings. clusterListeners == [listenerOne, listenerTwo]
72
+
73
+ when :
74
+ settings = ClusterSettings . builder(settings). clusterListenerList([listenerThree]). build()
75
+
76
+ then :
77
+ settings. clusterListeners == [listenerThree]
71
78
}
72
79
73
80
def ' should apply settings' () {
Original file line number Diff line number Diff line change @@ -170,6 +170,7 @@ class ConnectionPoolSettingsSpecification extends Specification {
170
170
171
171
def ' should apply settings' () {
172
172
given :
173
+ def connectionPoolListener = Mock (ConnectionPoolListener )
173
174
def defaultSettings = ConnectionPoolSettings . builder(). build()
174
175
def customSettings = ConnectionPoolSettings
175
176
.builder()
@@ -187,6 +188,12 @@ class ConnectionPoolSettingsSpecification extends Specification {
187
188
expect :
188
189
ConnectionPoolSettings . builder(). applySettings(customSettings). build() == customSettings
189
190
ConnectionPoolSettings . builder(customSettings). applySettings(defaultSettings). build() == defaultSettings
191
+
192
+ when :
193
+ customSettings = ConnectionPoolSettings . builder(customSettings). connectionPoolListenerList([connectionPoolListener]). build()
194
+
195
+ then :
196
+ customSettings. connectionPoolListeners == [connectionPoolListener]
190
197
}
191
198
192
199
def ' toString should be overridden' () {
Original file line number Diff line number Diff line change @@ -40,8 +40,10 @@ class ServerSettingsSpecification extends Specification {
40
40
given :
41
41
def serverListenerOne = new ServerListenerAdapter () { }
42
42
def serverListenerTwo = new ServerListenerAdapter () { }
43
+ def serverListenerThree = new ServerListenerAdapter () { }
43
44
def serverMonitorListenerOne = new ServerMonitorListenerAdapter () { }
44
45
def serverMonitorListenerTwo = new ServerMonitorListenerAdapter () { }
46
+ def serverMonitorListenerThree = new ServerMonitorListenerAdapter () { }
45
47
46
48
when :
47
49
def settings = ServerSettings . builder()
@@ -59,6 +61,15 @@ class ServerSettingsSpecification extends Specification {
59
61
settings. getMinHeartbeatFrequency(MILLISECONDS ) == 1000
60
62
settings. serverListeners == [serverListenerOne, serverListenerTwo]
61
63
settings. serverMonitorListeners == [serverMonitorListenerOne, serverMonitorListenerTwo]
64
+
65
+ when :
66
+ settings = ServerSettings . builder()
67
+ .serverListenerList([serverListenerThree])
68
+ .serverMonitorListenerList([serverMonitorListenerThree]). build()
69
+
70
+ then :
71
+ settings. serverListeners == [serverListenerThree]
72
+ settings. serverMonitorListeners == [serverMonitorListenerThree]
62
73
}
63
74
64
75
def ' when connection string is applied to builder, all properties should be set' () {
You can’t perform that action at this time.
0 commit comments