use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.
the class MongoClientImplTest method testStartSession.
@Test
void testStartSession() {
ServerDescription serverDescription = ServerDescription.builder().address(new ServerAddress()).state(ServerConnectionState.CONNECTED).maxWireVersion(8).build();
MongoClientImpl mongoClient = createMongoClient();
Cluster cluster = mongoClient.getCluster();
when(cluster.getCurrentDescription()).thenReturn(new ClusterDescription(ClusterConnectionMode.SINGLE, ClusterType.STANDALONE, singletonList(serverDescription)));
ServerSessionPool serverSessionPool = mock(ServerSessionPool.class);
ClientSessionHelper clientSessionHelper = new ClientSessionHelper(mongoClient, serverSessionPool);
assertAll("Start Session Tests", () -> assertAll("check validation", () -> assertThrows(IllegalArgumentException.class, () -> mongoClient.startSession(null))), () -> {
Mono<ClientSession> expected = clientSessionHelper.createClientSessionMono(ClientSessionOptions.builder().build(), OPERATION_EXECUTOR);
assertPublisherIsTheSameAs(expected, mongoClient.startSession(), "Default");
}, () -> {
ClientSessionOptions options = ClientSessionOptions.builder().causallyConsistent(true).defaultTransactionOptions(TransactionOptions.builder().readConcern(ReadConcern.LINEARIZABLE).build()).build();
Mono<ClientSession> expected = clientSessionHelper.createClientSessionMono(options, OPERATION_EXECUTOR);
assertPublisherIsTheSameAs(expected, mongoClient.startSession(options), "with options");
});
}
use of com.mongodb.ServerAddress in project mongomvcc by igd-geo.
the class MongoDBVDatabase method connect.
@Override
public void connect(String name, String host, int port) throws VException {
Mongo mongo;
try {
mongo = new Mongo(new ServerAddress(host, port));
} catch (UnknownHostException e) {
throw new VException("Unknown host", e);
}
connectInternal(name, mongo);
}
use of com.mongodb.ServerAddress in project spring-boot by spring-projects.
the class MongoPropertiesClientSettingsBuilderCustomizer method applyHostAndPort.
private void applyHostAndPort(MongoClientSettings.Builder settings) {
if (getEmbeddedPort() != null) {
settings.applyConnectionString(new ConnectionString("mongodb://localhost:" + getEmbeddedPort()));
return;
}
if (hasCustomAddress()) {
String host = getOrDefault(this.properties.getHost(), "localhost");
int port = getOrDefault(this.properties.getPort(), MongoProperties.DEFAULT_PORT);
ServerAddress serverAddress = new ServerAddress(host, port);
settings.applyToClusterSettings((cluster) -> cluster.hosts(Collections.singletonList(serverAddress)));
return;
}
settings.applyConnectionString(new ConnectionString(this.properties.determineUri()));
}
use of com.mongodb.ServerAddress in project spring-boot by spring-projects.
the class MongoPropertiesClientSettingsBuilderCustomizerTests method portCanBeCustomized.
@Test
void portCanBeCustomized() {
this.properties.setPort(12345);
MongoClientSettings settings = customizeSettings();
List<ServerAddress> allAddresses = getAllAddresses(settings);
assertThat(allAddresses).hasSize(1);
assertServerAddress(allAddresses.get(0), "localhost", 12345);
}
use of com.mongodb.ServerAddress in project spring-boot by spring-projects.
the class MongoPropertiesClientSettingsBuilderCustomizerTests method noCustomAddressAndNoUriUsesDefaultUri.
@Test
void noCustomAddressAndNoUriUsesDefaultUri() {
MongoClientSettings settings = customizeSettings();
List<ServerAddress> allAddresses = getAllAddresses(settings);
assertThat(allAddresses).hasSize(1);
assertServerAddress(allAddresses.get(0), "localhost", 27017);
}
Aggregations