use of com.datastax.oss.simulacron.server.BoundCluster in project java-driver by datastax.
the class ReactiveRetryIT method should_retry_at_application_level.
@Test
public void should_retry_at_application_level() {
// Given
CqlSession session = spy(SESSION_RULE.session());
BoundCluster cluster = SIMULACRON_RULE.cluster();
cluster.node(0).prime(when(QUERY_STRING).then(unavailable(ConsistencyLevel.ONE, 1, 0)));
cluster.node(1).prime(when(QUERY_STRING).then(unavailable(ConsistencyLevel.ONE, 1, 0)));
cluster.node(2).prime(when(QUERY_STRING).then(rows().row("col1", "Yay!")));
// When
ReactiveRow row = Flowable.defer(() -> session.executeReactive(QUERY_STRING)).retry((retry, error) -> {
assertThat(error).isInstanceOf(UnavailableException.class);
UnavailableException ue = (UnavailableException) error;
Node coordinator = ue.getCoordinator();
if (retry == 1) {
assertCoordinator(0, coordinator);
return true;
} else if (retry == 2) {
assertCoordinator(1, coordinator);
return true;
} else {
fail("Unexpected retry attempt");
return false;
}
}).blockingLast();
// Then
assertThat(row.getString(0)).isEqualTo("Yay!");
verify(session, times(3)).executeReactive(QUERY_STRING);
assertUnavailableMetric(0, 1L);
assertUnavailableMetric(1, 1L);
assertUnavailableMetric(2, 0L);
}
use of com.datastax.oss.simulacron.server.BoundCluster in project java-driver by datastax.
the class AllLoadBalancingPoliciesSimulacronIT method findNode.
private BoundNode findNode(Node node) {
BoundCluster simulacron = SIMULACRON_RULE.cluster();
SocketAddress toFind = node.getEndPoint().resolve();
for (BoundNode boundNode : simulacron.getNodes()) {
if (boundNode.getAddress().equals(toFind)) {
return boundNode;
}
}
throw new AssertionError("Could not find node: " + toFind);
}
use of com.datastax.oss.simulacron.server.BoundCluster in project java-driver by datastax.
the class ProtocolVersionMixedClusterIT method should_downgrade_if_peer_does_not_support_negotiated_version.
@Test
public void should_downgrade_if_peer_does_not_support_negotiated_version() {
DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withBoolean(DefaultDriverOption.METADATA_SCHEMA_ENABLED, false).build();
try (BoundCluster simulacron = mixedVersions("3.0.0", "2.2.0", "2.1.0");
BoundNode contactPoint = simulacron.node(0);
CqlSession session = (CqlSession) SessionUtils.baseBuilder().addContactPoint(contactPoint.inetSocketAddress()).withConfigLoader(loader).build()) {
InternalDriverContext context = (InternalDriverContext) session.getContext();
// General version should have been downgraded to V3
assertThat(context.getProtocolVersion()).isEqualTo(DefaultProtocolVersion.V3);
// But control connection should still be using protocol V4 since node0 supports V4
assertThat(context.getControlConnection().channel().protocolVersion()).isEqualTo(DefaultProtocolVersion.V4);
assertThat(queries(simulacron)).hasSize(4);
assertThat(protocolQueries(contactPoint, 4)).containsExactly(// Initial connection with protocol v4
"SELECT cluster_name FROM system.local", "SELECT * FROM system.local", "SELECT * FROM system.peers_v2", "SELECT * FROM system.peers");
}
}
use of com.datastax.oss.simulacron.server.BoundCluster in project java-driver by datastax.
the class ConnectIT method should_mark_unreachable_contact_points_as_local_and_schedule_reconnections.
/**
* Test for JAVA-2177. This ensures that even if the first attempted contact point is unreachable,
* its distance is set to LOCAL and reconnections are scheduled.
*/
@Test
public void should_mark_unreachable_contact_points_as_local_and_schedule_reconnections() {
// Reject connections only on one node
BoundCluster boundCluster = SIMULACRON_RULE.cluster();
boundCluster.node(0).rejectConnections(0, RejectScope.STOP);
try (CqlSession session = SessionUtils.newSession(SIMULACRON_RULE)) {
Map<UUID, Node> nodes = session.getMetadata().getNodes();
// Node states are updated asynchronously, so guard against race conditions
await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).untilAsserted(() -> {
// Before JAVA-2177, this would fail every other time because if the node was tried
// first for the initial connection, it was marked down and not passed to
// LBP.init(), and therefore stayed at distance IGNORED.
Node node0 = nodes.get(boundCluster.node(0).getHostId());
assertThat(node0.getState()).isEqualTo(NodeState.DOWN);
assertThat(node0.getDistance()).isEqualTo(NodeDistance.LOCAL);
assertThat(node0.getOpenConnections()).isEqualTo(0);
assertThat(node0.isReconnecting()).isTrue();
Node node1 = nodes.get(boundCluster.node(1).getHostId());
assertThat(node1.getState()).isEqualTo(NodeState.UP);
assertThat(node1.getDistance()).isEqualTo(NodeDistance.LOCAL);
// control + regular
assertThat(node1.getOpenConnections()).isEqualTo(2);
assertThat(node1.isReconnecting()).isFalse();
});
}
}
use of com.datastax.oss.simulacron.server.BoundCluster in project java-driver by datastax.
the class ProtocolVersionMixedClusterIT method should_keep_current_if_supported_by_all_peers.
@Test
public void should_keep_current_if_supported_by_all_peers() {
DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withBoolean(DefaultDriverOption.METADATA_SCHEMA_ENABLED, false).build();
try (BoundCluster simulacron = mixedVersions("3.0.0", "2.2.0", "3.11");
BoundNode contactPoint = simulacron.node(0);
CqlSession session = (CqlSession) SessionUtils.baseBuilder().addContactPoint(contactPoint.inetSocketAddress()).withConfigLoader(loader).build()) {
InternalDriverContext context = (InternalDriverContext) session.getContext();
assertThat(context.getProtocolVersion()).isEqualTo(DefaultProtocolVersion.V4);
assertThat(queries(simulacron)).hasSize(4);
assertThat(protocolQueries(contactPoint, 4)).containsExactly(// Initial connection with protocol v4
"SELECT cluster_name FROM system.local", "SELECT * FROM system.local", "SELECT * FROM system.peers_v2", "SELECT * FROM system.peers");
}
}
Aggregations