use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.
the class NativeAuthenticatorUnitTest method before.
@Before
public void before() {
connection = new TestInternalConnection(new ServerId(new ClusterId(), new ServerAddress("localhost", 27017)));
connectionDescription = new ConnectionDescription(new ServerId(new ClusterId(), new ServerAddress()));
credential = MongoCredential.createMongoCRCredential("台北", "database", "Táiběi".toCharArray());
subject = new NativeAuthenticator(this.credential);
}
use of com.mongodb.ServerAddress 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());
}
use of com.mongodb.ServerAddress 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")))));
}
use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.
the class ServerDescriptionTest method testObjectOverridesWithUnequalException.
@Test
public void testObjectOverridesWithUnequalException() throws UnknownHostException {
ServerDescription.Builder builder1 = builder().state(CONNECTING).address(new ServerAddress()).exception(new IllegalArgumentException("This is illegal"));
ServerDescription.Builder builder2 = builder().state(CONNECTING).address(new ServerAddress()).exception(new IllegalArgumentException("This is also illegal"));
ServerDescription.Builder builder3 = builder().state(CONNECTING).address(new ServerAddress()).exception(new IllegalStateException("This is illegal"));
ServerDescription.Builder builder4 = builder().state(CONNECTING).address(new ServerAddress());
assertThat(builder1.build(), not(builder2.build()));
assertThat(builder1.build().hashCode(), not(builder2.build().hashCode()));
assertThat(builder1.build(), not(builder3.build()));
assertThat(builder1.build().hashCode(), not(builder3.build().hashCode()));
assertThat(builder1.build(), not(builder4.build()));
assertThat(builder1.build().hashCode(), not(builder4.build().hashCode()));
assertThat(builder4.build(), not(builder3.build()));
assertThat(builder4.build().hashCode(), not(builder3.build().hashCode()));
}
use of com.mongodb.ServerAddress in project presto by prestodb.
the class MongoClientConfig method buildSeeds.
private List<ServerAddress> buildSeeds(Iterable<String> hostPorts) {
ImmutableList.Builder<ServerAddress> builder = ImmutableList.builder();
for (String hostPort : hostPorts) {
List<String> values = PORT_SPLITTER.splitToList(hostPort);
checkArgument(values.size() == 1 || values.size() == 2, "Invalid ServerAddress format. Requires host[:port]");
try {
if (values.size() == 1) {
builder.add(new ServerAddress(values.get(0)));
} else {
builder.add(new ServerAddress(values.get(0), Integer.parseInt(values.get(1))));
}
} catch (NumberFormatException e) {
throw Throwables.propagate(e);
}
}
return builder.build();
}
Aggregations