use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.
the class TestClusterableServerFactory method getBuilder.
private ServerDescription.Builder getBuilder(final ServerAddress serverAddress, final ServerType serverType, final List<ServerAddress> hosts, final List<ServerAddress> passives, final boolean ok, final String setName, final ObjectId electionId, final ServerAddress trueAddress) {
Set<String> hostsSet = new HashSet<String>();
for (ServerAddress cur : hosts) {
hostsSet.add(cur.toString());
}
Set<String> passivesSet = new HashSet<String>();
for (ServerAddress cur : passives) {
passivesSet.add(cur.toString());
}
return ServerDescription.builder().address(serverAddress).type(serverType).ok(ok).state(CONNECTED).canonicalAddress(trueAddress == null ? serverAddress.toString() : trueAddress.toString()).hosts(hostsSet).passives(passivesSet).setName(setName).electionId(electionId).setVersion(1);
}
use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.
the class CompositeServerSelectorTest method shouldPassOnClusterDescriptionWithCorrectServersAndSettings.
@Test
public void shouldPassOnClusterDescriptionWithCorrectServersAndSettings() {
TestServerSelector firstSelector = new TestServerSelector();
TestServerSelector secondSelector = new TestServerSelector();
CompositeServerSelector composedSelector = new CompositeServerSelector(asList(firstSelector, secondSelector));
composedSelector.select(new ClusterDescription(MULTIPLE, REPLICA_SET, asList(first, second, third), ClusterSettings.builder().hosts(asList(new ServerAddress())).build(), ServerSettings.builder().build()));
assertTrue(secondSelector.clusterDescription.getServerDescriptions().isEmpty());
assertNotNull(secondSelector.clusterDescription.getClusterSettings());
assertNotNull(secondSelector.clusterDescription.getServerSettings());
}
use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.
the class LatencyMinimizingServerSelectorTest method testLatencyDifferentialMinimization.
@Test
public void testLatencyDifferentialMinimization() throws UnknownHostException {
LatencyMinimizingServerSelector selector = new LatencyMinimizingServerSelector(20, TimeUnit.MILLISECONDS);
ServerDescription primary = ServerDescription.builder().state(CONNECTED).address(new ServerAddress()).ok(true).type(ServerType.REPLICA_SET_PRIMARY).roundTripTime(10, TimeUnit.MILLISECONDS).build();
ServerDescription secondaryOne = ServerDescription.builder().state(CONNECTED).address(new ServerAddress("localhost:27018")).ok(true).type(ServerType.REPLICA_SET_SECONDARY).roundTripTime(15, TimeUnit.MILLISECONDS).build();
ServerDescription secondaryTwo = ServerDescription.builder().state(CONNECTED).address(new ServerAddress("localhost:27019")).ok(true).type(ServerType.REPLICA_SET_SECONDARY).roundTripTime(31, TimeUnit.MILLISECONDS).build();
ServerDescription secondaryThree = ServerDescription.builder().state(CONNECTED).address(new ServerAddress("localhost:27020")).ok(true).type(ServerType.REPLICA_SET_SECONDARY).roundTripTime(30, TimeUnit.MILLISECONDS).build();
assertEquals(Arrays.asList(primary, secondaryOne, secondaryThree), selector.select(new ClusterDescription(MULTIPLE, REPLICA_SET, Arrays.asList(primary, secondaryOne, secondaryTwo, secondaryThree))));
}
use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.
the class ServerAddressSelectorTest method testAll.
@Test
public void testAll() throws UnknownHostException {
ServerAddressSelector selector = new ServerAddressSelector(new ServerAddress("localhost:27018"));
assertTrue(selector.toString().startsWith("ServerAddressSelector"));
assertEquals(selector.getServerAddress(), selector.getServerAddress());
ServerDescription primary = ServerDescription.builder().state(CONNECTED).address(new ServerAddress()).ok(true).type(ServerType.REPLICA_SET_PRIMARY).build();
ServerDescription secondary = ServerDescription.builder().state(CONNECTED).address(new ServerAddress("localhost:27018")).ok(true).type(ServerType.REPLICA_SET_SECONDARY).build();
assertEquals(Arrays.asList(secondary), selector.select(new ClusterDescription(MULTIPLE, REPLICA_SET, Arrays.asList(primary, secondary))));
}
use of com.mongodb.ServerAddress in project spring-boot by spring-projects.
the class MongoClientFactoryTests method portCanBeCustomized.
@Test
public void portCanBeCustomized() {
MongoProperties properties = new MongoProperties();
properties.setPort(12345);
MongoClient client = createMongoClient(properties);
List<ServerAddress> allAddresses = extractServerAddresses(client);
assertThat(allAddresses).hasSize(1);
assertServerAddress(allAddresses.get(0), "localhost", 12345);
}
Aggregations