use of com.datastax.oss.simulacron.server.BoundNode in project java-driver by datastax.
the class NodeStateIT method should_mark_unreachable_contact_point_down.
@Test
public void should_mark_unreachable_contact_point_down() {
// This time we connect with two valid contact points, but is unresponsive, it should be marked
// down
Iterator<BoundNode> simulacronNodes = simulacron.cluster().getNodes().iterator();
BoundNode localSimulacronNode1 = simulacronNodes.next();
BoundNode localSimulacronNode2 = simulacronNodes.next();
InetSocketAddress address1 = localSimulacronNode1.inetSocketAddress();
InetSocketAddress address2 = localSimulacronNode2.inetSocketAddress();
NodeStateListener localNodeStateListener = mock(NodeStateListener.class);
localSimulacronNode2.stop();
try {
// Since contact points are shuffled, we have a 50% chance that our bad contact point will be
// hit first. So we retry the scenario a few times if needed.
DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withDuration(DefaultDriverOption.RECONNECTION_BASE_DELAY, Duration.ofHours(1)).withDuration(DefaultDriverOption.RECONNECTION_MAX_DELAY, Duration.ofHours(1)).build();
for (int i = 0; i < 10; i++) {
try (CqlSession localSession = (CqlSession) SessionUtils.baseBuilder().addContactPoint(address1).addContactPoint(address2).withNodeStateListener(localNodeStateListener).withConfigLoader(loader).build()) {
Metadata metadata = localSession.getMetadata();
Node localMetadataNode1 = metadata.findNode(address1).orElseThrow(AssertionError::new);
Node localMetadataNode2 = metadata.findNode(address2).orElseThrow(AssertionError::new);
if (localMetadataNode2.getState() == NodeState.DOWN) {
// Stopped node was tried first and marked down, that's our target scenario
verify(localNodeStateListener, timeout(500)).onDown(localMetadataNode2);
verify(localNodeStateListener, timeout(500)).onUp(localMetadataNode1);
verify(localNodeStateListener, timeout(500)).onSessionReady(localSession);
verifyNoMoreInteractions(localNodeStateListener);
return;
} else {
// Stopped node was not tried
assertThat(localMetadataNode2).isUnknown();
verify(localNodeStateListener, timeout(500)).onUp(localMetadataNode1);
verifyNoMoreInteractions(localNodeStateListener);
}
}
reset(localNodeStateListener);
}
fail("Couldn't get the driver to try stopped node first (tried 5 times)");
} finally {
localSimulacronNode2.acceptConnections();
}
}
use of com.datastax.oss.simulacron.server.BoundNode in project java-driver by datastax.
the class NodeStateIT method should_force_immediate_reconnection_when_up_topology_event.
@Test
public void should_force_immediate_reconnection_when_up_topology_event() throws InterruptedException {
// This test requires a longer reconnection interval, so create a separate driver instance
DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withDuration(DefaultDriverOption.RECONNECTION_BASE_DELAY, Duration.ofHours(1)).withDuration(DefaultDriverOption.RECONNECTION_MAX_DELAY, Duration.ofHours(1)).build();
NodeStateListener localNodeStateListener = mock(NodeStateListener.class);
try (CqlSession session = SessionUtils.newSession(simulacron, null, localNodeStateListener, null, null, loader)) {
BoundNode localSimulacronNode = simulacron.cluster().getNodes().iterator().next();
assertThat(localSimulacronNode).isNotNull();
DefaultNode localMetadataNode = (DefaultNode) session.getMetadata().findNode(localSimulacronNode.inetSocketAddress()).orElseThrow(AssertionError::new);
// UP fired a first time as part of the init process
verify(localNodeStateListener, timeout(500)).onUp(localMetadataNode);
localSimulacronNode.stop();
await().alias("Node going down").pollInterval(500, TimeUnit.MILLISECONDS).untilAsserted(() -> assertThat(localMetadataNode).isDown().hasOpenConnections(0).isReconnecting());
verify(localNodeStateListener, timeout(500)).onDown(localMetadataNode);
expect(NodeStateEvent.changed(NodeState.UP, NodeState.DOWN, localMetadataNode));
localSimulacronNode.acceptConnections();
((InternalDriverContext) session.getContext()).getEventBus().fire(TopologyEvent.suggestUp(localMetadataNode.getBroadcastRpcAddress().get()));
await().alias("Node coming back up").pollInterval(500, TimeUnit.MILLISECONDS).untilAsserted(() -> assertThat(localMetadataNode).isUp().isNotReconnecting());
verify(localNodeStateListener, timeout(500).times(2)).onUp(localMetadataNode);
expect(NodeStateEvent.changed(NodeState.DOWN, NodeState.UP, localMetadataNode));
}
}
use of com.datastax.oss.simulacron.server.BoundNode 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");
}
}
use of com.datastax.oss.simulacron.server.BoundNode in project java-driver by datastax.
the class AllLoadBalancingPoliciesSimulacronIT method degradeLocalDc.
private List<Node> degradeLocalDc(CqlSession session) {
// stop 1 replica and 2 non-replicas in dc1
List<Node> localReplicas = replicasInDc(session, "dc1");
assertThat(localReplicas).hasSize(3);
BoundNode replica1 = findNode(localReplicas.get(0));
List<Node> localOthers = nonReplicasInDc(session, "dc1");
assertThat(localOthers).hasSize(2);
BoundNode other1 = findNode(localOthers.get(0));
BoundNode other2 = findNode(localOthers.get(1));
replica1.stop();
other1.stop();
other2.stop();
awaitDown(localReplicas.get(0), localOthers.get(0), localOthers.get(1));
return localReplicas.subList(1, 3);
}
use of com.datastax.oss.simulacron.server.BoundNode in project java-driver by datastax.
the class ProtocolVersionMixedClusterIT method should_not_downgrade_and_force_down_old_nodes_if_version_forced.
@Test
public void should_not_downgrade_and_force_down_old_nodes_if_version_forced() {
DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withString(DefaultDriverOption.PROTOCOL_VERSION, "V4").withBoolean(DefaultDriverOption.METADATA_SCHEMA_ENABLED, false).build();
try (BoundCluster simulacron = mixedVersions("3.0.0", "2.2.0", "2.0.0");
BoundNode contactPoint = simulacron.node(0);
CqlSession session = (CqlSession) SessionUtils.baseBuilder().addContactPoint(contactPoint.inetSocketAddress()).withConfigLoader(loader).build()) {
assertThat(session.getContext().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");
// Note: the 2.0.0 would be forced down if we try to open a connection to it. We can't check
// that here because Simulacron can't prime STARTUP requests.
}
}
Aggregations