Search in sources :

Example 6 with DefaultEndPoint

use of com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint in project java-driver by datastax.

the class DefaultSessionPoolsTest method mockLocalNode.

private static DefaultNode mockLocalNode(int i) {
    DefaultNode node = mock(DefaultNode.class);
    when(node.getHostId()).thenReturn(UUID.randomUUID());
    DefaultEndPoint endPoint = TestNodeFactory.newEndPoint(i);
    when(node.getEndPoint()).thenReturn(endPoint);
    when(node.getBroadcastRpcAddress()).thenReturn(Optional.of(endPoint.resolve()));
    when(node.getDistance()).thenReturn(NodeDistance.LOCAL);
    when(node.toString()).thenReturn("node" + i);
    return node;
}
Also used : DefaultNode(com.datastax.oss.driver.internal.core.metadata.DefaultNode) DefaultEndPoint(com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint)

Example 7 with DefaultEndPoint

use of com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint in project java-driver by datastax.

the class ContactPoints method merge.

public static Set<EndPoint> merge(Set<EndPoint> programmaticContactPoints, List<String> configContactPoints, boolean resolve) {
    Set<EndPoint> result = Sets.newHashSet(programmaticContactPoints);
    for (String spec : configContactPoints) {
        for (InetSocketAddress address : extract(spec, resolve)) {
            DefaultEndPoint endPoint = new DefaultEndPoint(address);
            boolean wasNew = result.add(endPoint);
            if (!wasNew) {
                LOG.warn("Duplicate contact point {}", address);
            }
        }
    }
    return ImmutableSet.copyOf(result);
}
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)

Example 8 with DefaultEndPoint

use of com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint 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 9 with DefaultEndPoint

use of com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint 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)

Aggregations

DefaultEndPoint (com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint)9 EndPoint (com.datastax.oss.driver.api.core.metadata.EndPoint)7 InetSocketAddress (java.net.InetSocketAddress)7 Test (org.junit.Test)6 DriverChannel (com.datastax.oss.driver.internal.core.channel.DriverChannel)1 DefaultNode (com.datastax.oss.driver.internal.core.metadata.DefaultNode)1 Channel (io.netty.channel.Channel)1 DefaultChannelPromise (io.netty.channel.DefaultChannelPromise)1 EventLoop (io.netty.channel.EventLoop)1