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);
}
}
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);
});
}
}
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);
}
}
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");
}
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)));
}
Aggregations