Search in sources :

Example 1 with Tag

use of com.mongodb.Tag in project mongo-java-driver by mongodb.

the class ClusterDescriptionTest method setUp.

@Before
public void setUp() throws IOException {
    TagSet tags1 = new TagSet(asList(new Tag("foo", "1"), new Tag("bar", "2"), new Tag("baz", "1")));
    TagSet tags2 = new TagSet(asList(new Tag("foo", "1"), new Tag("bar", "2"), new Tag("baz", "2")));
    TagSet tags3 = new TagSet(asList(new Tag("foo", "1"), new Tag("bar", "3"), new Tag("baz", "3")));
    primary = builder().state(CONNECTED).address(new ServerAddress("localhost", 27017)).ok(true).type(REPLICA_SET_PRIMARY).tagSet(tags1).build();
    secondary = builder().state(CONNECTED).address(new ServerAddress("localhost", 27018)).ok(true).type(REPLICA_SET_SECONDARY).tagSet(tags2).build();
    otherSecondary = builder().state(CONNECTED).address(new ServerAddress("otherhost", 27019)).ok(true).type(REPLICA_SET_SECONDARY).tagSet(tags3).build();
    uninitiatedMember = builder().state(CONNECTED).address(new ServerAddress("localhost", 27020)).ok(true).type(REPLICA_SET_OTHER).build();
    notOkMember = builder().state(CONNECTED).address(new ServerAddress("localhost", 27021)).ok(false).build();
    List<ServerDescription> nodeList = asList(primary, secondary, otherSecondary, uninitiatedMember, notOkMember);
    cluster = new ClusterDescription(MULTIPLE, REPLICA_SET, nodeList);
}
Also used : TagSet(com.mongodb.TagSet) ServerAddress(com.mongodb.ServerAddress) Tag(com.mongodb.Tag) Before(org.junit.Before)

Example 2 with Tag

use of com.mongodb.Tag in project mongo-java-driver by mongodb.

the class ServerDescriptionTest method testBuilder.

@Test
public void testBuilder() throws UnknownHostException {
    IllegalArgumentException exception = new IllegalArgumentException();
    ServerDescription serverDescription = builder().address(new ServerAddress("localhost:27018")).type(ServerType.REPLICA_SET_PRIMARY).tagSet(new TagSet(new Tag("dc", "ny"))).setName("test").maxDocumentSize(100).roundTripTime(50000, java.util.concurrent.TimeUnit.NANOSECONDS).primary("localhost:27017").canonicalAddress("localhost:27018").hosts(new HashSet<String>(asList("localhost:27017", "localhost:27018", "localhost:27019", "localhost:27020"))).arbiters(new HashSet<String>(asList("localhost:27019"))).passives(new HashSet<String>(asList("localhost:27020"))).ok(true).state(CONNECTED).version(new ServerVersion(asList(2, 4, 1))).minWireVersion(1).maxWireVersion(2).electionId(new ObjectId("123412341234123412341234")).setVersion(new Integer(2)).lastWriteDate(new Date(1234L)).lastUpdateTimeNanos(40000L).exception(exception).build();
    assertEquals(new ServerAddress("localhost:27018"), serverDescription.getAddress());
    assertTrue(serverDescription.isOk());
    assertEquals(CONNECTED, serverDescription.getState());
    assertEquals(REPLICA_SET_PRIMARY, serverDescription.getType());
    assertTrue(serverDescription.isReplicaSetMember());
    assertFalse(serverDescription.isShardRouter());
    assertFalse(serverDescription.isStandAlone());
    assertTrue(serverDescription.isPrimary());
    assertFalse(serverDescription.isSecondary());
    assertEquals(50000, serverDescription.getRoundTripTimeNanos(), 0L);
    assertEquals(100, serverDescription.getMaxDocumentSize());
    assertEquals("localhost:27017", serverDescription.getPrimary());
    assertEquals("localhost:27018", serverDescription.getCanonicalAddress());
    assertEquals(new HashSet<String>(asList("localhost:27017", "localhost:27018", "localhost:27019", "localhost:27020")), serverDescription.getHosts());
    assertEquals(new TagSet(new Tag("dc", "ny")), serverDescription.getTagSet());
    assertEquals(new HashSet<String>(asList("localhost:27019")), serverDescription.getArbiters());
    assertEquals(new HashSet<String>(asList("localhost:27020")), serverDescription.getPassives());
    assertEquals("test", serverDescription.getSetName());
    assertEquals(new ServerVersion(asList(2, 4, 1)), serverDescription.getVersion());
    assertEquals(1, serverDescription.getMinWireVersion());
    assertEquals(2, serverDescription.getMaxWireVersion());
    assertEquals(new ObjectId("123412341234123412341234"), serverDescription.getElectionId());
    assertEquals(new Integer(2), serverDescription.getSetVersion());
    assertEquals(new Date(1234), serverDescription.getLastWriteDate());
    assertEquals(40000L, serverDescription.getLastUpdateTime(TimeUnit.NANOSECONDS));
    assertEquals(exception, serverDescription.getException());
}
Also used : ObjectId(org.bson.types.ObjectId) TagSet(com.mongodb.TagSet) ServerAddress(com.mongodb.ServerAddress) Tag(com.mongodb.Tag) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Tag

use of com.mongodb.Tag in project mongo-java-driver by mongodb.

the class ServerDescriptionTest method testHasTags.

@Test
public void testHasTags() throws UnknownHostException {
    ServerDescription serverDescription = builder().address(new ServerAddress()).type(ServerType.SHARD_ROUTER).ok(false).state(CONNECTED).build();
    assertFalse(serverDescription.hasTags(new TagSet(asList(new Tag("dc", "ny")))));
    serverDescription = builder().address(new ServerAddress()).type(ServerType.SHARD_ROUTER).ok(true).state(CONNECTED).build();
    assertTrue(serverDescription.hasTags(new TagSet(asList(new Tag("dc", "ny")))));
    serverDescription = builder().address(new ServerAddress()).type(ServerType.STANDALONE).ok(true).state(CONNECTED).build();
    assertTrue(serverDescription.hasTags(new TagSet(asList(new Tag("dc", "ny")))));
    serverDescription = builder().address(new ServerAddress()).type(REPLICA_SET_PRIMARY).ok(true).state(CONNECTED).build();
    assertTrue(serverDescription.hasTags(new TagSet()));
    serverDescription = builder().address(new ServerAddress()).type(REPLICA_SET_PRIMARY).ok(true).tagSet(new TagSet(asList(new Tag("dc", "ca")))).state(CONNECTED).build();
    assertFalse(serverDescription.hasTags(new TagSet(asList(new Tag("dc", "ny")))));
    serverDescription = builder().address(new ServerAddress()).type(REPLICA_SET_PRIMARY).ok(true).tagSet(new TagSet(asList(new Tag("rack", "1")))).state(CONNECTED).build();
    assertFalse(serverDescription.hasTags(new TagSet(asList(new Tag("rack", "2")))));
    serverDescription = builder().address(new ServerAddress()).type(REPLICA_SET_PRIMARY).ok(true).tagSet(new TagSet(asList(new Tag("rack", "1")))).state(CONNECTED).build();
    assertTrue(serverDescription.hasTags(new TagSet(asList(new Tag("rack", "1")))));
}
Also used : TagSet(com.mongodb.TagSet) ServerAddress(com.mongodb.ServerAddress) Tag(com.mongodb.Tag) Test(org.junit.Test)

Example 4 with Tag

use of com.mongodb.Tag in project presto by prestodb.

the class MongoClientConfig method buildTags.

private List<Tag> buildTags(Iterable<String> tags) {
    ImmutableList.Builder<Tag> builder = ImmutableList.builder();
    for (String tag : tags) {
        List<String> values = TAG_SPLITTER.splitToList(tag);
        checkArgument(values.size() == 2, "Invalid Tag format. Requires tagName:tagValue");
        builder.add(new Tag(values.get(0), values.get(1)));
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Tag(com.mongodb.Tag)

Aggregations

Tag (com.mongodb.Tag)4 ServerAddress (com.mongodb.ServerAddress)3 TagSet (com.mongodb.TagSet)3 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 ObjectId (org.bson.types.ObjectId)1 Before (org.junit.Before)1