Search in sources :

Example 66 with ServerAddress

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

the class MongoNamespaceReplicaSetTests method testParsingWithPropertyPlaceHolder.

@Test
@SuppressWarnings("unchecked")
public void testParsingWithPropertyPlaceHolder() throws Exception {
    assertTrue(ctx.containsBean("manyReplicaSetMongo"));
    MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&manyReplicaSetMongo");
    List<ServerAddress> replicaSetSeeds = (List<ServerAddress>) ReflectionTestUtils.getField(mfb, "replicaSetSeeds");
    assertThat(replicaSetSeeds, is(notNullValue()));
    assertThat(replicaSetSeeds, hasSize(3));
    List<Integer> ports = new ArrayList<Integer>();
    for (ServerAddress replicaSetSeed : replicaSetSeeds) {
        ports.add(replicaSetSeed.getPort());
    }
    assertThat(ports, hasItems(27017, 27018, 27019));
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) ServerAddress(com.mongodb.ServerAddress) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 67 with ServerAddress

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

the class CursorReadingTaskUnitTests method stopRunningTask.

// DATAMONGO-1803
@Test
public void stopRunningTask() throws Throwable {
    when(cursor.getServerCursor()).thenReturn(new ServerCursor(10, new ServerAddress("mock")));
    runOnce(new MultithreadedStopRunning(task, cursor));
}
Also used : ServerCursor(com.mongodb.ServerCursor) ServerAddress(com.mongodb.ServerAddress) Test(org.junit.Test)

Example 68 with ServerAddress

use of com.mongodb.ServerAddress in project Network-depr by Mas281.

the class MongoDB method connect.

@Override
public void connect() {
    log("Attempting to connect to MongoDB database");
    disableMongoLogging();
    info = new DatabaseInfo(core);
    client = new MongoClient(new ServerAddress(info.getIp(), info.getPort()), Collections.singletonList(MongoCredential.createCredential(info.getUsername(), info.getDatabase(), info.getPassword().toCharArray())));
    database = client.getDatabase(info.getDatabase());
    createCollections();
    setupMorphia();
    log("Connected to MongoDB database");
}
Also used : MongoClient(com.mongodb.MongoClient) ServerAddress(com.mongodb.ServerAddress)

Example 69 with ServerAddress

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

the class ProjectionsBenchmark method setUp.

@Setup
public void setUp() {
    client = new MongoClient(new ServerAddress());
    template = new MongoTemplate(client, DB_NAME);
    source = new Person();
    source.firstname = "luke";
    source.lastname = "skywalker";
    source.address = new Address();
    source.address.street = "melenium falcon 1";
    source.address.city = "deathstar";
    template.save(source, COLLECTION_NAME);
    asPerson = template.query(Person.class).inCollection(COLLECTION_NAME);
    asDtoProjection = template.query(Person.class).inCollection(COLLECTION_NAME).as(DtoProjection.class);
    asClosedProjection = template.query(Person.class).inCollection(COLLECTION_NAME).as(ClosedProjection.class);
    asOpenProjection = template.query(Person.class).inCollection(COLLECTION_NAME).as(OpenProjection.class);
    asPersonWithFieldsRestriction = template.query(Person.class).inCollection(COLLECTION_NAME).matching(new BasicQuery(new Document(), fields));
    mongoCollection = client.getDatabase(DB_NAME).getCollection(COLLECTION_NAME);
}
Also used : MongoClient(com.mongodb.MongoClient) ServerAddress(com.mongodb.ServerAddress) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) ServerAddress(com.mongodb.ServerAddress) Document(org.bson.Document) Setup(org.openjdk.jmh.annotations.Setup)

Example 70 with ServerAddress

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

the class MappingMongoConverterBenchmark method setUp.

@Setup
public void setUp() throws Exception {
    client = new MongoClient(new ServerAddress());
    this.mappingContext = new MongoMappingContext();
    this.mappingContext.setInitialEntitySet(Collections.singleton(Customer.class));
    this.mappingContext.afterPropertiesSet();
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(new SimpleMongoDbFactory(client, DB_NAME));
    this.converter = new MappingMongoConverter(dbRefResolver, mappingContext);
    this.converter.setCustomConversions(new MongoCustomConversions(Collections.emptyList()));
    this.converter.afterPropertiesSet();
    // just a flat document
    this.documentWith2Properties = new Document("firstname", "Dave").append("lastname", "Matthews");
    // document with a nested one
    Document address = new Document("zipCode", "ABCDE").append("city", "Some Place");
    this.documentWith2PropertiesAnd1Nested = // 
    new Document("firstname", "Dave").append("lastname", // 
    "Matthews").append("address", address);
    // object equivalent of documentWith2PropertiesAnd1Nested
    this.objectWith2PropertiesAnd1Nested = new Customer("Dave", "Matthews", new Address("zipCode", "City"));
    // a bit more challenging object with list & map conversion.
    objectWithFlatAndComplexPropertiesPlusListAndMap = new SlightlyMoreComplexObject();
    objectWithFlatAndComplexPropertiesPlusListAndMap.id = UUID.randomUUID().toString();
    objectWithFlatAndComplexPropertiesPlusListAndMap.addressList = Arrays.asList(new Address("zip-1", "city-1"), new Address("zip-2", "city-2"));
    objectWithFlatAndComplexPropertiesPlusListAndMap.customer = objectWith2PropertiesAnd1Nested;
    objectWithFlatAndComplexPropertiesPlusListAndMap.customerMap = new LinkedHashMap<>();
    objectWithFlatAndComplexPropertiesPlusListAndMap.customerMap.put("dave", objectWith2PropertiesAnd1Nested);
    objectWithFlatAndComplexPropertiesPlusListAndMap.customerMap.put("deborah", new Customer("Deborah Anne", "Dyer", new Address("?", "london")));
    objectWithFlatAndComplexPropertiesPlusListAndMap.customerMap.put("eddie", new Customer("Eddie", "Vedder", new Address("??", "Seattle")));
    objectWithFlatAndComplexPropertiesPlusListAndMap.intOne = Integer.MIN_VALUE;
    objectWithFlatAndComplexPropertiesPlusListAndMap.intTwo = Integer.MAX_VALUE;
    objectWithFlatAndComplexPropertiesPlusListAndMap.location = new Point(-33.865143, 151.209900);
    objectWithFlatAndComplexPropertiesPlusListAndMap.renamedField = "supercalifragilisticexpialidocious";
    objectWithFlatAndComplexPropertiesPlusListAndMap.stringOne = "¯\\_(ツ)_/¯";
    objectWithFlatAndComplexPropertiesPlusListAndMap.stringTwo = " (╯°□°)╯︵ ┻━┻";
    // JSON equivalent of objectWithFlatAndComplexPropertiesPlusListAndMap
    documentWithFlatAndComplexPropertiesPlusListAndMap = Document.parse("{ \"_id\" : \"517f6aee-e9e0-44f0-88ed-f3694a019f27\", \"intOne\" : -2147483648, \"intTwo\" : 2147483647, \"stringOne\" : \"¯\\\\_(ツ)_/¯\", \"stringTwo\" : \" (╯°□°)╯︵ ┻━┻\", \"explicit-field-name\" : \"supercalifragilisticexpialidocious\", \"location\" : { \"x\" : -33.865143, \"y\" : 151.2099 }, \"objectWith2PropertiesAnd1Nested\" : { \"firstname\" : \"Dave\", \"lastname\" : \"Matthews\", \"address\" : { \"zipCode\" : \"zipCode\", \"city\" : \"City\" } }, \"addressList\" : [{ \"zipCode\" : \"zip-1\", \"city\" : \"city-1\" }, { \"zipCode\" : \"zip-2\", \"city\" : \"city-2\" }], \"customerMap\" : { \"dave\" : { \"firstname\" : \"Dave\", \"lastname\" : \"Matthews\", \"address\" : { \"zipCode\" : \"zipCode\", \"city\" : \"City\" } }, \"deborah\" : { \"firstname\" : \"Deborah Anne\", \"lastname\" : \"Dyer\", \"address\" : { \"zipCode\" : \"?\", \"city\" : \"london\" } }, \"eddie\" : { \"firstname\" : \"Eddie\", \"lastname\" : \"Vedder\", \"address\" : { \"zipCode\" : \"??\", \"city\" : \"Seattle\" } } }, \"_class\" : \"org.springframework.data.mongodb.core.convert.MappingMongoConverterBenchmark$SlightlyMoreComplexObject\" }");
}
Also used : ServerAddress(com.mongodb.ServerAddress) ServerAddress(com.mongodb.ServerAddress) Point(org.springframework.data.geo.Point) Document(org.bson.Document) MongoClient(com.mongodb.MongoClient) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

ServerAddress (com.mongodb.ServerAddress)72 Test (org.junit.Test)27 MongoClient (com.mongodb.MongoClient)21 ArrayList (java.util.ArrayList)13 MongoCredential (com.mongodb.MongoCredential)10 Before (org.junit.Before)9 Document (org.bson.Document)5 TagSet (com.mongodb.TagSet)4 ClusterDescription (com.mongodb.connection.ClusterDescription)4 ClusterSettings (com.mongodb.connection.ClusterSettings)4 MongoClient (com.mongodb.reactivestreams.client.MongoClient)4 UnknownHostException (java.net.UnknownHostException)4 List (java.util.List)4 Tag (com.mongodb.Tag)3 MongoDatabase (com.mongodb.client.MongoDatabase)3 ServerDescription (com.mongodb.connection.ServerDescription)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3 ChunkInfo (org.apache.drill.exec.store.mongo.common.ChunkInfo)3 BsonDocument (org.bson.BsonDocument)3