use of com.mongodb.connection.ConnectionId in project mongo-java-driver by mongodb.
the class InternalStreamConnectionInitializer method applyGetLastErrorResult.
private InternalConnectionInitializationDescription applyGetLastErrorResult(final BsonDocument getLastErrorResult, final InternalConnectionInitializationDescription description) {
ConnectionDescription connectionDescription = description.getConnectionDescription();
ConnectionId connectionId;
if (getLastErrorResult.containsKey("connectionId")) {
connectionId = connectionDescription.getConnectionId().withServerValue(getLastErrorResult.getNumber("connectionId").intValue());
} else {
connectionId = connectionDescription.getConnectionId();
}
return description.withConnectionDescription(connectionDescription.withConnectionId(connectionId));
}
use of com.mongodb.connection.ConnectionId in project mongo-java-driver by mongodb.
the class AsynchronousClusterEventListenerTest method testEventsPublished.
@Test
public void testEventsPublished() throws InterruptedException {
AllClusterEventListener targetListener = new AllClusterEventListener();
ClusterId clusterId = new ClusterId();
ServerId serverId = new ServerId(clusterId, new ServerAddress());
ConnectionId connectionId = new ConnectionId(serverId);
AsynchronousClusterEventListener listener = AsynchronousClusterEventListener.startNew(clusterId, targetListener, targetListener, targetListener);
ClusterOpeningEvent clusterOpeningEvent = new ClusterOpeningEvent(clusterId);
listener.clusterOpening(clusterOpeningEvent);
assertEquals(clusterOpeningEvent, targetListener.take());
ClusterDescriptionChangedEvent clusterDescriptionChangedEvent = new ClusterDescriptionChangedEvent(clusterId, new ClusterDescription(ClusterConnectionMode.SINGLE, ClusterType.STANDALONE, Collections.emptyList()), new ClusterDescription(ClusterConnectionMode.SINGLE, ClusterType.STANDALONE, Collections.emptyList()));
listener.clusterDescriptionChanged(clusterDescriptionChangedEvent);
assertEquals(clusterDescriptionChangedEvent, targetListener.take());
ServerHeartbeatStartedEvent serverHeartbeatStartedEvent = new ServerHeartbeatStartedEvent(connectionId);
listener.serverHearbeatStarted(serverHeartbeatStartedEvent);
assertEquals(serverHeartbeatStartedEvent, targetListener.take());
ServerHeartbeatSucceededEvent serverHeartbeatSucceededEvent = new ServerHeartbeatSucceededEvent(connectionId, new BsonDocument(), 1, true);
listener.serverHeartbeatSucceeded(serverHeartbeatSucceededEvent);
assertEquals(serverHeartbeatSucceededEvent, targetListener.take());
ServerHeartbeatFailedEvent serverHeartbeatFailedEvent = new ServerHeartbeatFailedEvent(connectionId, 1, true, new IOException());
listener.serverHeartbeatFailed(serverHeartbeatFailedEvent);
assertEquals(serverHeartbeatFailedEvent, targetListener.take());
ServerOpeningEvent serverOpeningEvent = new ServerOpeningEvent(serverId);
listener.serverOpening(serverOpeningEvent);
assertEquals(serverOpeningEvent, targetListener.take());
ServerDescriptionChangedEvent serverDescriptionChangedEvent = new ServerDescriptionChangedEvent(serverId, ServerDescription.builder().address(new ServerAddress()).type(UNKNOWN).state(CONNECTING).build(), ServerDescription.builder().address(new ServerAddress()).type(STANDALONE).state(CONNECTED).build());
listener.serverDescriptionChanged(serverDescriptionChangedEvent);
assertEquals(serverDescriptionChangedEvent, targetListener.take());
ServerClosedEvent serverClosedEvent = new ServerClosedEvent(serverId);
listener.serverClosed(serverClosedEvent);
assertEquals(serverClosedEvent, targetListener.take());
ClusterClosedEvent clusterClosedEvent = new ClusterClosedEvent(clusterId);
listener.clusterClosed(clusterClosedEvent);
assertEquals(clusterClosedEvent, targetListener.take());
// The thread should die after publishing the ClusterClosedEvent
listener.getPublishingThread().join(5000);
}
use of com.mongodb.connection.ConnectionId in project mongo-java-driver by mongodb.
the class InternalStreamConnectionInitializer method createInitializationDescription.
private InternalConnectionInitializationDescription createInitializationDescription(final BsonDocument helloResult, final InternalConnection internalConnection, final long startTime) {
ConnectionId connectionId = internalConnection.getDescription().getConnectionId();
ConnectionDescription connectionDescription = createConnectionDescription(clusterConnectionMode, connectionId, helloResult);
ServerDescription serverDescription = createServerDescription(internalConnection.getDescription().getServerAddress(), helloResult, System.nanoTime() - startTime);
return new InternalConnectionInitializationDescription(connectionDescription, serverDescription);
}
use of com.mongodb.connection.ConnectionId in project mongo-java-driver by mongodb.
the class DescriptionHelper method createConnectionDescription.
static ConnectionDescription createConnectionDescription(final ClusterConnectionMode clusterConnectionMode, final ConnectionId connectionId, final BsonDocument helloResult) {
ConnectionDescription connectionDescription = new ConnectionDescription(connectionId, getMaxWireVersion(helloResult), getServerType(helloResult), getMaxWriteBatchSize(helloResult), getMaxBsonObjectSize(helloResult), getMaxMessageSizeBytes(helloResult), getCompressors(helloResult), helloResult.getArray("saslSupportedMechs", null));
if (helloResult.containsKey("connectionId")) {
ConnectionId newConnectionId = connectionDescription.getConnectionId().withServerValue(helloResult.getNumber("connectionId").intValue());
connectionDescription = connectionDescription.withConnectionId(newConnectionId);
}
if (clusterConnectionMode == ClusterConnectionMode.LOAD_BALANCED) {
ObjectId serviceId = getServiceId(helloResult);
if (serviceId != null) {
connectionDescription = connectionDescription.withServiceId(serviceId);
} else {
throw new MongoClientException("Driver attempted to initialize in load balancing mode, but the server does not support " + "this mode");
}
}
return connectionDescription;
}
use of com.mongodb.connection.ConnectionId in project mongo-java-driver by mongodb.
the class X509AuthenticatorNoUserNameTest method before.
@Before
public void before() {
connection = new TestInternalConnection(new ServerId(new ClusterId(), new ServerAddress("localhost", 27017)));
connectionDescriptionThreeTwo = new ConnectionDescription(new ConnectionId(new ServerId(new ClusterId(), new ServerAddress())), 4, ServerType.STANDALONE, 1000, 16000, 48000, Collections.<String>emptyList());
connectionDescriptionThreeFour = new ConnectionDescription(new ConnectionId(new ServerId(new ClusterId(), new ServerAddress())), 5, ServerType.STANDALONE, 1000, 16000, 48000, Collections.<String>emptyList());
}
Aggregations