com.mongodb.async.client.MongoClientSettings Java Examples

The following examples show how to use com.mongodb.async.client.MongoClientSettings. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MongoClientWrapperTest.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
private static void assertWithExpected(final DittoMongoClient mongoClient, final boolean sslEnabled,
        final boolean withCredentials) {

    final MongoClientSettings mongoClientSettings = mongoClient.getSettings();
    assertThat(mongoClientSettings.getClusterSettings().getHosts())
            .isEqualTo(Collections.singletonList(new ServerAddress(KNOWN_SERVER_ADDRESS)));

    final List<MongoCredential> expectedCredentials = withCredentials ? Collections.singletonList(
            MongoCredential.createCredential(KNOWN_USER, KNOWN_DB_NAME, KNOWN_PASSWORD.toCharArray())) :
            Collections.emptyList();
    assertThat(mongoClientSettings.getCredentialList()).isEqualTo(
            expectedCredentials);
    assertThat(mongoClientSettings.getSslSettings().isEnabled()).isEqualTo(sslEnabled);

    final MongoDatabase mongoDatabase = mongoClient.getDefaultDatabase();
    assertThat(mongoDatabase).isNotNull();
    assertThat(mongoDatabase.getName()).isEqualTo(KNOWN_DB_NAME);
}
 
Example #2
Source File: EmbeddedClient.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {

    final IMongodConfig mongodConfig = new MongodConfigBuilder()
            .version(Version.Main.PRODUCTION).build();

    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
            .defaultsWithLogger(Command.MongoD, logger)
            .processOutput(ProcessOutput.getDefaultInstanceSilent())
            .build();

    MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);

    MongodExecutable mongodExecutable = runtime.prepare(mongodConfig);
    mongod = mongodExecutable.start();

    // cluster configuration
    ClusterSettings clusterSettings = ClusterSettings.builder().hosts(Collections.singletonList(new ServerAddress(mongodConfig.net().getServerAddress().getHostName(), mongodConfig.net().getPort()))).build();
    // codec configuration
    CodecRegistry pojoCodecRegistry = fromRegistries(MongoClients.getDefaultCodecRegistry(),
            fromProviders(PojoCodecProvider.builder().automatic(true).build()));

    MongoClientSettings settings = MongoClientSettings.builder().clusterSettings(clusterSettings).codecRegistry(pojoCodecRegistry).writeConcern(WriteConcern.ACKNOWLEDGED).build();
    mongoClient = MongoClients.create(settings);
    mongoDatabase = mongoClient.getDatabase(databaseName);
}
 
Example #3
Source File: EmbeddedClient.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
    final IMongodConfig mongodConfig = new MongodConfigBuilder()
            .version(Version.Main.PRODUCTION).build();

    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
            .defaultsWithLogger(Command.MongoD, logger)
            .processOutput(ProcessOutput.getDefaultInstanceSilent())
            .build();

    MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);

    MongodExecutable mongodExecutable = runtime.prepare(mongodConfig);
    mongod = mongodExecutable.start();

    // cluster configuration
    ClusterSettings clusterSettings = ClusterSettings.builder().hosts(Collections.singletonList(new ServerAddress(mongodConfig.net().getServerAddress().getHostName(), mongodConfig.net().getPort()))).build();
    // codec configuration
    CodecRegistry pojoCodecRegistry = fromRegistries(MongoClients.getDefaultCodecRegistry(),
            fromProviders(PojoCodecProvider.builder().automatic(true).build()));

    MongoClientSettings settings = MongoClientSettings.builder().clusterSettings(clusterSettings).codecRegistry(pojoCodecRegistry).writeConcern(WriteConcern.ACKNOWLEDGED).build();
    mongoClient = MongoClients.create(settings);
    mongoDatabase = mongoClient.getDatabase(databaseName);
}
 
Example #4
Source File: ReactiveMongoClientTestConfiguration.java    From mongodb-aggregate-query-support with Apache License 2.0 5 votes vote down vote up
@Bean
public MongoClient mongoClient() throws IOException {
  ServerAddress serverAddress = getServerAddress();
  MongoClientSettings settings = MongoClientSettings.builder()
                                                    .clusterSettings(ClusterSettings.builder()
                                                                                    .hosts(singletonList(serverAddress))
                                                                                    .requiredClusterType(STANDALONE)
                                                                                    .build()).build();
  return MongoClients.create(settings);
}
 
Example #5
Source File: MongoClientImpl.java    From mongo-java-driver-rx with Apache License 2.0 4 votes vote down vote up
@Override
public MongoClientSettings getSettings() {
    return wrapped.getSettings();
}
 
Example #6
Source File: MongoClient.java    From mongo-java-driver-rx with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the settings that this client uses to connect to server.
 *
 * <p>Note: {@link MongoClientSettings} is immutable.</p>
 *
 * @return the settings
 */
MongoClientSettings getSettings();
 
Example #7
Source File: MongoClients.java    From mongo-java-driver-rx with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new client with the given client settings.
 *
 * @param settings the settings
 * @return the client
 */
public static MongoClient create(final MongoClientSettings settings) {
    return create(settings, new NoopObservableAdapter());
}
 
Example #8
Source File: MongoClients.java    From mongo-java-driver-rx with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new client with the given client settings.
 *
 * @param settings the settings
 * @param observableAdapter the {@link ObservableAdapter} to adapt all {@code Observables}
 * @return the client
 * @since 1.2
 */
public static MongoClient create(final MongoClientSettings settings, final ObservableAdapter observableAdapter) {
    return create(settings, observableAdapter, null);
}
 
Example #9
Source File: MongoClients.java    From mongo-java-driver-rx with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new client with the given client settings.
 *
 * <p>Note: Intended for driver and library authors to associate extra driver metadata with the connections.</p>
 *
 * @param settings the settings
 * @param observableAdapter the {@link ObservableAdapter} to adapt all {@code Observables}.
 * @param mongoDriverInformation any driver information to associate with the MongoClient
 * @return the client
 * @since 1.3
 */
public static MongoClient create(final MongoClientSettings settings, final ObservableAdapter observableAdapter,
                                 final MongoDriverInformation mongoDriverInformation) {
    return create(com.mongodb.async.client.MongoClients.create(settings, getMongoDriverInformation(mongoDriverInformation)),
            observableAdapter);
}