Search in sources :

Example 1 with EndPoint

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

the class QueryTraceIT method should_fetch_trace_when_tracing_enabled.

@Test
public void should_fetch_trace_when_tracing_enabled() {
    ExecutionInfo executionInfo = SESSION_RULE.session().execute(SimpleStatement.builder("SELECT release_version FROM system.local").setTracing().build()).getExecutionInfo();
    assertThat(executionInfo.getTracingId()).isNotNull();
    EndPoint contactPoint = CCM_RULE.getContactPoints().iterator().next();
    InetAddress nodeAddress = ((InetSocketAddress) contactPoint.resolve()).getAddress();
    boolean expectPorts = CCM_RULE.getCassandraVersion().nextStable().compareTo(Version.V4_0_0) >= 0 && !CCM_RULE.getDseVersion().isPresent();
    QueryTrace queryTrace = executionInfo.getQueryTrace();
    assertThat(queryTrace.getTracingId()).isEqualTo(executionInfo.getTracingId());
    assertThat(queryTrace.getRequestType()).isEqualTo("Execute CQL3 query");
    assertThat(queryTrace.getDurationMicros()).isPositive();
    assertThat(queryTrace.getCoordinatorAddress().getAddress()).isEqualTo(nodeAddress);
    if (expectPorts) {
        Row row = SESSION_RULE.session().execute("SELECT coordinator_port FROM system_traces.sessions WHERE session_id = " + queryTrace.getTracingId()).one();
        assertThat(row).isNotNull();
        int expectedPort = row.getInt(0);
        assertThat(queryTrace.getCoordinatorAddress().getPort()).isEqualTo(expectedPort);
    } else {
        assertThat(queryTrace.getCoordinatorAddress().getPort()).isEqualTo(0);
    }
    assertThat(queryTrace.getParameters()).containsEntry("consistency_level", "LOCAL_ONE").containsEntry("page_size", "5000").containsEntry("query", "SELECT release_version FROM system.local").containsEntry("serial_consistency_level", "SERIAL");
    assertThat(queryTrace.getStartedAt()).isPositive();
    // Don't want to get too deep into event testing because that could change across versions
    assertThat(queryTrace.getEvents()).isNotEmpty();
    InetSocketAddress sourceAddress0 = queryTrace.getEvents().get(0).getSourceAddress();
    assertThat(sourceAddress0).isNotNull();
    assertThat(sourceAddress0.getAddress()).isEqualTo(nodeAddress);
    if (expectPorts) {
        Row row = SESSION_RULE.session().execute("SELECT source_port FROM system_traces.events WHERE session_id = " + queryTrace.getTracingId() + " LIMIT 1").one();
        assertThat(row).isNotNull();
        int expectedPort = row.getInt(0);
        assertThat(sourceAddress0.getPort()).isEqualTo(expectedPort);
    } else {
        assertThat(sourceAddress0.getPort()).isEqualTo(0);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) Row(com.datastax.oss.driver.api.core.cql.Row) InetAddress(java.net.InetAddress) QueryTrace(com.datastax.oss.driver.api.core.cql.QueryTrace) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) Test(org.junit.Test)

Example 2 with EndPoint

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

the class DefaultLoadBalancingPolicyIT method should_apply_node_filter.

@Test
public void should_apply_node_filter() {
    Set<Node> localNodes = new HashSet<>();
    for (Node node : SESSION_RULE.session().getMetadata().getNodes().values()) {
        if (node.getDatacenter().equals(LOCAL_DC)) {
            localNodes.add(node);
        }
    }
    assertThat(localNodes.size()).isEqualTo(4);
    // Pick a random node to exclude -- just ensure that it's not the default contact point since
    // we assert 0 connections at the end of this test (the filter is not applied to contact
    // points).
    EndPoint ignoredEndPoint = firstNonDefaultContactPoint(localNodes);
    // Open a separate session with a filter
    try (CqlSession session = SessionUtils.newSession(CCM_RULE, SESSION_RULE.keyspace(), null, null, node -> !node.getEndPoint().equals(ignoredEndPoint))) {
        // No routing information => should round-robin on white-listed nodes
        SimpleStatement statement = SimpleStatement.newInstance("SELECT * FROM test.foo WHERE k = 1");
        for (int i = 0; i < 12; i++) {
            ResultSet rs = session.execute(statement);
            Node coordinator = rs.getExecutionInfo().getCoordinator();
            assertThat(coordinator.getEndPoint()).isNotEqualTo(ignoredEndPoint);
        }
        assertThat(session.getMetadata().findNode(ignoredEndPoint)).hasValueSatisfying(ignoredNode -> {
            assertThat(ignoredNode.getOpenConnections()).isEqualTo(0);
        });
    }
}
Also used : SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) Node(com.datastax.oss.driver.api.core.metadata.Node) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) CqlSession(com.datastax.oss.driver.api.core.CqlSession) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with EndPoint

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

the class NodeStateIT method should_signal_non_contact_points_as_added.

@Test
public void should_signal_non_contact_points_as_added() {
    // Since we need to observe the behavior of non-contact points, build a dedicated session with
    // just one contact point.
    Iterator<EndPoint> contactPoints = simulacron.getContactPoints().iterator();
    EndPoint endPoint1 = contactPoints.next();
    EndPoint endPoint2 = contactPoints.next();
    NodeStateListener localNodeStateListener = mock(NodeStateListener.class);
    DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withDuration(DefaultDriverOption.RECONNECTION_BASE_DELAY, Duration.ofHours(1)).withDuration(DefaultDriverOption.RECONNECTION_MAX_DELAY, Duration.ofHours(1)).withInt(DefaultDriverOption.CONNECTION_POOL_LOCAL_SIZE, 0).build();
    try (CqlSession localSession = (CqlSession) SessionUtils.baseBuilder().addContactEndPoint(endPoint1).withNodeStateListener(localNodeStateListener).withConfigLoader(loader).build()) {
        Metadata metadata = localSession.getMetadata();
        Node localMetadataNode1 = metadata.findNode(endPoint1).orElseThrow(AssertionError::new);
        Node localMetadataNode2 = metadata.findNode(endPoint2).orElseThrow(AssertionError::new);
        // Successful contact point goes to up directly
        verify(localNodeStateListener, timeout(500)).onUp(localMetadataNode1);
        // Non-contact point only added since we don't have a connection or events for it yet
        verify(localNodeStateListener, timeout(500)).onAdd(localMetadataNode2);
    }
}
Also used : NodeStateListener(com.datastax.oss.driver.api.core.metadata.NodeStateListener) DefaultNode(com.datastax.oss.driver.internal.core.metadata.DefaultNode) Node(com.datastax.oss.driver.api.core.metadata.Node) BoundNode(com.datastax.oss.simulacron.server.BoundNode) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) DefaultEndPoint(com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 4 with EndPoint

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

the class ContactPointsTest method should_warn_if_duplicate_between_programmatic_and_configuration.

@Test
public void should_warn_if_duplicate_between_programmatic_and_configuration() {
    Set<EndPoint> endPoints = ContactPoints.merge(ImmutableSet.of(new DefaultEndPoint(new InetSocketAddress("127.0.0.1", 9042))), ImmutableList.of("127.0.0.1:9042"), true);
    assertThat(endPoints).containsOnly(new DefaultEndPoint(new InetSocketAddress("127.0.0.1", 9042)));
    assertLog(Level.WARN, "Duplicate contact point /127.0.0.1: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 5 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_in_configuration_and_create_unresolved.

@Test
public void should_parse_host_and_port_in_configuration_and_create_unresolved() {
    Set<EndPoint> endPoints = ContactPoints.merge(Collections.emptySet(), ImmutableList.of("localhost:9042"), false);
    assertThat(endPoints).containsExactly(new DefaultEndPoint(InetSocketAddress.createUnresolved("localhost", 9042)));
}
Also used : 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

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