1
1
/*
2
- * Copyright (c) 2008-2015 MongoDB, Inc.
2
+ * Copyright (c) 2008-2016 MongoDB, Inc.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the 'License');
5
5
* you may not use this file except in compliance with the License.
@@ -142,6 +142,7 @@ class MongoClientOptionsSpecification extends Specification {
142
142
def ' should build with set options' () {
143
143
given :
144
144
def encoderFactory = new MyDBEncoderFactory ()
145
+ def socketFactory = SSLSocketFactory . getDefault()
145
146
def options = MongoClientOptions . builder()
146
147
.description(' test' )
147
148
.applicationName(' appName' )
@@ -157,6 +158,7 @@ class MongoClientOptionsSpecification extends Specification {
157
158
.maxConnectionLifeTime(400 )
158
159
.threadsAllowedToBlockForConnectionMultiplier(2 )
159
160
.socketKeepAlive(true )
161
+ .socketFactory(socketFactory)
160
162
.sslEnabled(true )
161
163
.sslInvalidHostNameAllowed(true )
162
164
.dbDecoderFactory(LazyDBDecoder . FACTORY )
@@ -185,6 +187,7 @@ class MongoClientOptionsSpecification extends Specification {
185
187
options. getSocketTimeout() == 700
186
188
options. getThreadsAllowedToBlockForConnectionMultiplier() == 2
187
189
options. isSocketKeepAlive()
190
+ options. socketFactory == socketFactory
188
191
options. isSslEnabled()
189
192
options. isSslInvalidHostNameAllowed()
190
193
options. getDbDecoderFactory() == LazyDBDecoder . FACTORY
@@ -212,23 +215,25 @@ class MongoClientOptionsSpecification extends Specification {
212
215
}
213
216
214
217
@IgnoreIf ({ System .getProperty(' java.version' ).startsWith(' 1.6.' ) })
215
- def ' should set sslEnabled based on socketFactory ' () {
216
- given :
218
+ def ' should get socketFactory based on sslEnabled ' () {
219
+ when :
217
220
MongoClientOptions.Builder builder = MongoClientOptions . builder()
218
- SocketFactory socketFactory = SSLSocketFactory . getDefault()
219
221
220
- when :
221
- builder. socketFactory(socketFactory)
222
222
then :
223
- builder. build(). getSocketFactory() == socketFactory
224
- builder. sslEnabled(false )
225
- builder. build(). getSocketFactory() != null
226
- ! (builder. build(). getSocketFactory() instanceof SSLSocketFactory )
223
+ builder. build(). getSocketFactory() == MongoClientOptions . DEFAULT_SOCKET_FACTORY
227
224
228
225
when :
229
226
builder. sslEnabled(true )
227
+
230
228
then :
231
- builder. build(). getSocketFactory() instanceof SSLSocketFactory
229
+ builder. build(). getSocketFactory() == MongoClientOptions . DEFAULT_SSL_SOCKET_FACTORY
230
+
231
+ when :
232
+ def socketFactory = Mock (SocketFactory )
233
+ builder. socketFactory(socketFactory)
234
+
235
+ then :
236
+ builder. build(). getSocketFactory() == socketFactory
232
237
}
233
238
234
239
def ' should be easy to create new options from existing' () {
@@ -493,48 +498,44 @@ class MongoClientOptionsSpecification extends Specification {
493
498
494
499
def ' builder should copy all values from the existing MongoClientOptions' () {
495
500
given :
496
- def options = Mock (MongoClientOptions )
497
-
498
-
499
- when :
500
- MongoClientOptions . builder(options)
501
-
502
- then :
503
- 1 * options. isAlwaysUseMBeans()
504
- 1 * options. getCodecRegistry()
505
- 1 * options. getConnectionsPerHost()
506
- 1 * options. getConnectTimeout()
507
- 1 * options. isCursorFinalizerEnabled()
508
- 1 * options. getDbDecoderFactory()
509
- 1 * options. getDbEncoderFactory()
510
- 1 * options. getDescription()
511
- 1 * options. getApplicationName()
512
- 1 * options. getHeartbeatConnectTimeout()
513
- 1 * options. getHeartbeatFrequency()
514
- 1 * options. getHeartbeatSocketTimeout()
515
- 1 * options. getLocalThreshold()
516
- 1 * options. getMaxConnectionIdleTime()
517
- 1 * options. getMaxConnectionLifeTime()
518
- 1 * options. getMaxWaitTime()
519
- 1 * options. getMinConnectionsPerHost()
520
- 1 * options. getMinHeartbeatFrequency()
521
- 1 * options. getReadPreference()
522
- 1 * options. getRequiredReplicaSetName()
523
- 1 * options. getServerSelectionTimeout()
524
- 1 * options. getSocketFactory()
525
- 1 * options. isSocketKeepAlive()
526
- 1 * options. getSocketTimeout()
527
- 1 * options. isSslEnabled()
528
- 1 * options. isSslInvalidHostNameAllowed()
529
- 1 * options. getThreadsAllowedToBlockForConnectionMultiplier()
530
- 1 * options. getWriteConcern()
531
- 1 * options. getReadConcern()
532
- 1 * options. getCommandListeners() >> Collections . unmodifiableList(Collections . emptyList())
533
- 1 * options. getClusterListeners() >> Collections . unmodifiableList(Collections . emptyList())
534
- 1 * options. getServerListeners() >> Collections . unmodifiableList(Collections . emptyList())
535
- 1 * options. getServerMonitorListeners() >> Collections . unmodifiableList(Collections . emptyList())
536
-
537
- 0 * options. _ // Ensure no other interactions
501
+ def options = MongoClientOptions . builder()
502
+ .description(' test' )
503
+ .applicationName(' appName' )
504
+ .readPreference(ReadPreference . secondary())
505
+ .writeConcern(WriteConcern . JOURNALED )
506
+ .minConnectionsPerHost(30 )
507
+ .connectionsPerHost(500 )
508
+ .connectTimeout(100 )
509
+ .socketTimeout(700 )
510
+ .serverSelectionTimeout(150 )
511
+ .maxWaitTime(200 )
512
+ .maxConnectionIdleTime(300 )
513
+ .maxConnectionLifeTime(400 )
514
+ .threadsAllowedToBlockForConnectionMultiplier(2 )
515
+ .socketKeepAlive(true )
516
+ .sslEnabled(true )
517
+ .sslInvalidHostNameAllowed(true )
518
+ .socketFactory(SSLSocketFactory . getDefault())
519
+ .dbDecoderFactory(LazyDBDecoder . FACTORY )
520
+ .heartbeatFrequency(5 )
521
+ .minHeartbeatFrequency(11 )
522
+ .heartbeatConnectTimeout(15 )
523
+ .heartbeatSocketTimeout(20 )
524
+ .localThreshold(25 )
525
+ .requiredReplicaSetName(' test' )
526
+ .cursorFinalizerEnabled(false )
527
+ .dbEncoderFactory(new MyDBEncoderFactory ())
528
+ .addCommandListener(Mock (CommandListener ))
529
+ .addClusterListener(Mock (ClusterListener ))
530
+ .addServerListener(Mock (ServerListener ))
531
+ .addServerMonitorListener(Mock (ServerMonitorListener ))
532
+ .build()
533
+
534
+ when :
535
+ def copy = MongoClientOptions . builder(options). build()
536
+
537
+ then :
538
+ copy == options
538
539
}
539
540
540
541
def ' should only have the following fields in the builder' () {
0 commit comments