Search in sources :

Example 21 with EndPoint

use of com.datastax.oss.driver.api.core.metadata.EndPoint in project java-driver by datastax.

the class ContactPointsTest method should_parse_host_and_port_and_resolve_all_a_records.

@Test
public void should_parse_host_and_port_and_resolve_all_a_records() throws UnknownHostException {
    int localhostARecordsCount = InetAddress.getAllByName("localhost").length;
    assumeTrue("This test assumes that localhost resolves to multiple A-records", localhostARecordsCount >= 2);
    Set<EndPoint> endPoints = ContactPoints.merge(Collections.emptySet(), ImmutableList.of("localhost:9042"), true);
    assertThat(endPoints).hasSize(localhostARecordsCount);
    assertLog(Level.INFO, "Contact point localhost:9042 resolves to multiple addresses, will use them all");
}
Also used : DefaultEndPoint(com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) DefaultEndPoint(com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) Test(org.junit.Test)

Example 22 with EndPoint

use of com.datastax.oss.driver.api.core.metadata.EndPoint in project java-driver by datastax.

the class ContactPointsTest method should_parse_ipv6_address_and_port_in_configuration.

@Test
public void should_parse_ipv6_address_and_port_in_configuration() {
    Set<EndPoint> endPoints = ContactPoints.merge(Collections.emptySet(), ImmutableList.of("0:0:0:0:0:0:0:1:9042", "::2:9042"), true);
    assertThat(endPoints).containsExactly(new DefaultEndPoint(new InetSocketAddress("::1", 9042)), new DefaultEndPoint(new InetSocketAddress("::2", 9042)));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DefaultEndPoint(com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint) DefaultEndPoint(com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) Test(org.junit.Test)

Example 23 with EndPoint

use of com.datastax.oss.driver.api.core.metadata.EndPoint in project java-driver by datastax.

the class ContactPointsTest method should_merge_programmatic_and_configuration.

@Test
public void should_merge_programmatic_and_configuration() {
    Set<EndPoint> endPoints = ContactPoints.merge(ImmutableSet.of(new DefaultEndPoint(new InetSocketAddress("127.0.0.1", 9042))), ImmutableList.of("127.0.0.2:9042"), true);
    assertThat(endPoints).containsOnly(new DefaultEndPoint(new InetSocketAddress("127.0.0.1", 9042)), new DefaultEndPoint(new InetSocketAddress("127.0.0.2", 9042)));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DefaultEndPoint(com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint) DefaultEndPoint(com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) Test(org.junit.Test)

Example 24 with EndPoint

use of com.datastax.oss.driver.api.core.metadata.EndPoint in project java-driver by datastax.

the class DefaultLoadBalancingPolicyIT method firstNonDefaultContactPoint.

private EndPoint firstNonDefaultContactPoint(Iterable<Node> nodes) {
    for (Node localNode : nodes) {
        EndPoint endPoint = localNode.getEndPoint();
        InetSocketAddress connectAddress = (InetSocketAddress) endPoint.resolve();
        if (!connectAddress.getAddress().getHostAddress().equals("127.0.0.1")) {
            return endPoint;
        }
    }
    fail("should have other nodes than the default contact point");
    // never reached
    return null;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Node(com.datastax.oss.driver.api.core.metadata.Node) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint)

Aggregations

EndPoint (com.datastax.oss.driver.api.core.metadata.EndPoint)24 InetSocketAddress (java.net.InetSocketAddress)14 DefaultEndPoint (com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint)11 Test (org.junit.Test)11 Node (com.datastax.oss.driver.api.core.metadata.Node)7 NonNull (edu.umd.cs.findbugs.annotations.NonNull)5 DriverChannel (com.datastax.oss.driver.internal.core.channel.DriverChannel)4 DefaultNode (com.datastax.oss.driver.internal.core.metadata.DefaultNode)4 CqlSession (com.datastax.oss.driver.api.core.CqlSession)3 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)3 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)3 Metadata (com.datastax.oss.driver.api.core.metadata.Metadata)3 ImmutableSet (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSet)3 SessionStateForNode (com.datastax.dse.driver.internal.core.insights.schema.SessionStateForNode)2 NodeStateListener (com.datastax.oss.driver.api.core.metadata.NodeStateListener)2 AdminResult (com.datastax.oss.driver.internal.core.adminrequest.AdminResult)2 AdminRow (com.datastax.oss.driver.internal.core.adminrequest.AdminRow)2 UnexpectedResponseException (com.datastax.oss.driver.internal.core.adminrequest.UnexpectedResponseException)2 ControlConnection (com.datastax.oss.driver.internal.core.control.ControlConnection)2 SniEndPoint (com.datastax.oss.driver.internal.core.metadata.SniEndPoint)2