use of com.mongodb.internal.inject.SameObjectProvider in project mongo-java-driver by mongodb.
the class AbstractConnectionPoolTest method setUp.
@Before
public void setUp() {
assumeFalse(skipTest);
ConnectionPoolSettings.Builder settingsBuilder = ConnectionPoolSettings.builder();
BsonDocument poolOptions = definition.getDocument("poolOptions", new BsonDocument());
if (poolOptions.containsKey("maxPoolSize")) {
settingsBuilder.maxSize(poolOptions.getNumber("maxPoolSize").intValue());
}
if (poolOptions.containsKey("minPoolSize")) {
settingsBuilder.minSize(poolOptions.getNumber("minPoolSize").intValue());
}
if (poolOptions.containsKey("maxIdleTimeMS")) {
settingsBuilder.maxConnectionIdleTime(poolOptions.getNumber("maxIdleTimeMS").intValue(), TimeUnit.MILLISECONDS);
}
if (poolOptions.containsKey("waitQueueTimeoutMS")) {
settingsBuilder.maxWaitTime(poolOptions.getNumber("waitQueueTimeoutMS").intValue(), TimeUnit.MILLISECONDS);
}
if (poolOptions.containsKey("backgroundThreadIntervalMS")) {
long intervalMillis = poolOptions.getNumber("backgroundThreadIntervalMS").longValue();
assertFalse(intervalMillis == 0);
if (intervalMillis < 0) {
settingsBuilder.maintenanceInitialDelay(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
} else {
/* Using frequency/period instead of an interval as required by the specification is incorrect, for example,
* because it opens up a possibility to run the background thread non-stop if runs are as long as or longer than the period.
* Nevertheless, I am reusing what we already have in the driver instead of clogging up the implementation. */
settingsBuilder.maintenanceFrequency(poolOptions.getNumber("backgroundThreadIntervalMS").longValue(), TimeUnit.MILLISECONDS);
}
}
if (poolOptions.containsKey("maxConnecting")) {
settingsBuilder.maxConnecting(poolOptions.getInt32("maxConnecting").intValue());
}
listener = new TestConnectionPoolListener();
settingsBuilder.addConnectionPoolListener(listener);
settings = settingsBuilder.build();
InternalConnectionPoolSettings internalSettings = InternalConnectionPoolSettings.builder().prestartAsyncWorkManager(PRESTART_POOL_ASYNC_WORK_MANAGER_FILE_NAMES.contains(fileName)).build();
Style style = Style.of(definition.getString("style").getValue());
switch(style) {
case UNIT:
{
ServerId serverId = new ServerId(new ClusterId(), new ServerAddress("host1"));
pool = new DefaultConnectionPool(serverId, new TestInternalConnectionFactory(), settings, internalSettings, SameObjectProvider.initialized(mock(SdamServerDescriptionManager.class)));
break;
}
case INTEGRATION:
{
ServerId serverId = new ServerId(new ClusterId(), ClusterFixture.getPrimary());
ClusterConnectionMode connectionMode = ClusterConnectionMode.MULTIPLE;
SameObjectProvider<SdamServerDescriptionManager> sdamProvider = SameObjectProvider.uninitialized();
pool = new ConnectionIdAdjustingConnectionPool(new DefaultConnectionPool(serverId, new InternalStreamConnectionFactory(connectionMode, createStreamFactory(SocketSettings.builder().build(), ClusterFixture.getSslSettings()), ClusterFixture.getCredentialWithCache(), poolOptions.getString("appName", new BsonString(fileName + ": " + description)).getValue(), MongoDriverInformation.builder().build(), Collections.emptyList(), new TestCommandListener(), ClusterFixture.getServerApi()), settings, internalSettings, sdamProvider));
sdamProvider.initialize(new DefaultSdamServerDescriptionManager(mockedCluster(), serverId, mock(ServerListener.class), mock(ServerMonitor.class), pool, connectionMode));
setFailPoint();
break;
}
default:
{
throw new AssertionError(format("Style %s is not implemented", style));
}
}
if (internalSettings.isPrestartAsyncWorkManager()) {
waitForPoolAsyncWorkManagerStart();
}
}
Aggregations