Search in sources :

Example 71 with MongoClientSettings

use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.

the class MongoClientNamespaceTests method clientWithUUidSettings.

// DATAMONGO-2427
@Test
public void clientWithUUidSettings() {
    assertThat(ctx.containsBean("client-with-uuid-settings")).isTrue();
    MongoClientFactoryBean factoryBean = ctx.getBean("&client-with-uuid-settings", MongoClientFactoryBean.class);
    MongoClientSettings settings = (MongoClientSettings) getField(factoryBean, "mongoClientSettings");
    assertThat(settings.getUuidRepresentation()).isEqualTo(UuidRepresentation.STANDARD);
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) MongoClientSettings(com.mongodb.MongoClientSettings) Test(org.junit.Test)

Example 72 with MongoClientSettings

use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.

the class MongoNamespaceTests method testMongoSingletonWithAttributes.

@Test
public void testMongoSingletonWithAttributes() throws Exception {
    assertThat(ctx.containsBean("defaultMongo")).isTrue();
    MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&defaultMongo");
    String host = (String) getField(mfb, "host");
    Integer port = (Integer) getField(mfb, "port");
    assertThat(host).isEqualTo("localhost");
    assertThat(port).isEqualTo(new Integer(27017));
    MongoClientSettings options = (MongoClientSettings) getField(mfb, "mongoClientSettings");
    assertThat(options).isNull();
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) MongoClientSettings(com.mongodb.MongoClientSettings) Test(org.junit.Test)

Example 73 with MongoClientSettings

use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.

the class MongoNamespaceTests method testMongoSingletonWithSslEnabled.

// DATAMONGO-764
@Test
public void testMongoSingletonWithSslEnabled() throws Exception {
    assertThat(ctx.containsBean("mongoSsl")).isTrue();
    MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&mongoSsl");
    MongoClientSettings options = (MongoClientSettings) getField(mfb, "mongoClientSettings");
    assertThat(options.getSslSettings().getContext().getSocketFactory() instanceof SSLSocketFactory).as("socketFactory should be a SSLSocketFactory").isTrue();
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) MongoClientSettings(com.mongodb.MongoClientSettings) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Test(org.junit.Test)

Example 74 with MongoClientSettings

use of com.mongodb.MongoClientSettings in project rocketmq-externals by apache.

the class MongoFactoryTest method getSettings.

private MongoClientSettings getSettings() {
    try {
        client = (MongoClientImpl) mongoClientFactory.createMongoClient(replicaSetConfig);
        Field field = MongoClientImpl.class.getDeclaredField("settings");
        field.setAccessible(true);
        return (MongoClientSettings) field.get(client);
    } catch (Exception e) {
    }
    return null;
}
Also used : Field(java.lang.reflect.Field) MongoClientSettings(com.mongodb.MongoClientSettings) MongoTimeoutException(com.mongodb.MongoTimeoutException)

Example 75 with MongoClientSettings

use of com.mongodb.MongoClientSettings in project pinpoint by naver.

the class MongoDriverConnectInterceptor3_7 method getHostList.

private List<String> getHostList(Object arg) {
    if (!(arg instanceof MongoClientSettings)) {
        return Collections.emptyList();
    }
    final MongoClientSettings mongoClientSettings = (MongoClientSettings) arg;
    List<ServerAddress> lists = mongoClientSettings.getClusterSettings().getHosts();
    final List<String> hostList = new ArrayList<>();
    for (ServerAddress sa : lists) {
        final String hostAddress = HostAndPort.toHostAndPortString(sa.getHost(), sa.getPort());
        hostList.add(hostAddress);
    }
    return hostList;
}
Also used : ServerAddress(com.mongodb.ServerAddress) ArrayList(java.util.ArrayList) MongoClientSettings(com.mongodb.MongoClientSettings)

Aggregations

MongoClientSettings (com.mongodb.MongoClientSettings)75 Test (org.junit.jupiter.api.Test)24 BsonString (org.bson.BsonString)21 Map (java.util.Map)20 Test (org.junit.Test)20 HashMap (java.util.HashMap)19 Document (org.bson.Document)19 BsonDocument (org.bson.BsonDocument)18 ServerAddress (com.mongodb.ServerAddress)17 AutoEncryptionSettings (com.mongodb.AutoEncryptionSettings)14 Before (org.junit.Before)14 MongoNamespace (com.mongodb.MongoNamespace)13 ClientEncryptionSettings (com.mongodb.ClientEncryptionSettings)12 ConnectionString (com.mongodb.ConnectionString)12 MongoClientFactoryBean (org.springframework.data.mongodb.core.MongoClientFactoryBean)10 Block (com.mongodb.Block)8 Fixture.getMongoClientSettingsBuilder (com.mongodb.client.Fixture.getMongoClientSettingsBuilder)8 SecureRandom (java.security.SecureRandom)8 TimeUnit (java.util.concurrent.TimeUnit)8 ClusterFixture.isServerlessTest (com.mongodb.ClusterFixture.isServerlessTest)7