use of com.datastax.oss.driver.api.core.session.Session in project java-driver by datastax.
the class DefaultSessionPoolsTest method should_not_recreate_pool_if_node_is_forced_back_up_but_ignored.
@Test
public void should_not_recreate_pool_if_node_is_forced_back_up_but_ignored() {
when(node2.getState()).thenReturn(NodeState.FORCED_DOWN);
when(node2.getDistance()).thenReturn(NodeDistance.IGNORED);
ChannelPool pool1 = mockPool(node1);
ChannelPool pool3 = mockPool(node3);
MockChannelPoolFactoryHelper factoryHelper = MockChannelPoolFactoryHelper.builder(channelPoolFactory).success(node1, KEYSPACE, NodeDistance.LOCAL, pool1).success(node3, KEYSPACE, NodeDistance.LOCAL, pool3).build();
CompletionStage<CqlSession> initFuture = newSession();
factoryHelper.waitForCall(node1, KEYSPACE, NodeDistance.LOCAL);
factoryHelper.waitForCall(node3, KEYSPACE, NodeDistance.LOCAL);
assertThatStage(initFuture).isSuccess();
Session session = CompletableFutures.getCompleted(initFuture.toCompletableFuture());
assertThat(((DefaultSession) session).getPools()).containsValues(pool1, pool3);
eventBus.fire(NodeStateEvent.changed(NodeState.FORCED_DOWN, NodeState.UP, node2));
await().untilAsserted(() -> assertThat(((DefaultSession) session).getPools()).containsValues(pool1, pool3));
factoryHelper.verifyNoMoreCalls();
}
use of com.datastax.oss.driver.api.core.session.Session in project java-driver by datastax.
the class DefaultSessionPoolsTest method should_recreate_pool_if_node_becomes_not_ignored.
@Test
public void should_recreate_pool_if_node_becomes_not_ignored() {
when(node2.getDistance()).thenReturn(NodeDistance.IGNORED);
ChannelPool pool1 = mockPool(node1);
ChannelPool pool2 = mockPool(node2);
ChannelPool pool3 = mockPool(node3);
MockChannelPoolFactoryHelper factoryHelper = MockChannelPoolFactoryHelper.builder(channelPoolFactory).success(node1, KEYSPACE, NodeDistance.LOCAL, pool1).success(node3, KEYSPACE, NodeDistance.LOCAL, pool3).success(node2, KEYSPACE, NodeDistance.LOCAL, pool2).build();
CompletionStage<CqlSession> initFuture = newSession();
factoryHelper.waitForCall(node1, KEYSPACE, NodeDistance.LOCAL);
factoryHelper.waitForCall(node3, KEYSPACE, NodeDistance.LOCAL);
assertThatStage(initFuture).isSuccess();
Session session = CompletableFutures.getCompleted(initFuture.toCompletableFuture());
assertThat(((DefaultSession) session).getPools()).containsValues(pool1, pool3);
eventBus.fire(new DistanceEvent(NodeDistance.LOCAL, node2));
factoryHelper.waitForCall(node2, KEYSPACE, NodeDistance.LOCAL);
await().untilAsserted(() -> assertThat(((DefaultSession) session).getPools()).containsValues(pool1, pool2, pool3));
}
use of com.datastax.oss.driver.api.core.session.Session in project java-driver by datastax.
the class DefaultSessionPoolsTest method should_remove_pool_if_node_is_forced_down.
@Test
public void should_remove_pool_if_node_is_forced_down() {
ChannelPool pool1 = mockPool(node1);
ChannelPool pool2 = mockPool(node2);
ChannelPool pool3 = mockPool(node3);
MockChannelPoolFactoryHelper factoryHelper = MockChannelPoolFactoryHelper.builder(channelPoolFactory).success(node1, KEYSPACE, NodeDistance.LOCAL, pool1).success(node2, KEYSPACE, NodeDistance.LOCAL, pool2).success(node3, KEYSPACE, NodeDistance.LOCAL, pool3).build();
CompletionStage<CqlSession> initFuture = newSession();
factoryHelper.waitForCall(node1, KEYSPACE, NodeDistance.LOCAL);
factoryHelper.waitForCall(node2, KEYSPACE, NodeDistance.LOCAL);
factoryHelper.waitForCall(node3, KEYSPACE, NodeDistance.LOCAL);
assertThatStage(initFuture).isSuccess();
eventBus.fire(NodeStateEvent.changed(NodeState.UP, NodeState.FORCED_DOWN, node2));
verify(pool2, timeout(500)).closeAsync();
Session session = CompletableFutures.getCompleted(initFuture.toCompletableFuture());
await().untilAsserted(() -> assertThat(((DefaultSession) session).getPools()).containsValues(pool1, pool3));
}
use of com.datastax.oss.driver.api.core.session.Session in project java-driver by datastax.
the class DefaultSessionPoolsTest method should_remove_pool_if_ignored_while_recreating.
@Test
public void should_remove_pool_if_ignored_while_recreating() {
when(node2.getDistance()).thenReturn(NodeDistance.IGNORED);
ChannelPool pool1 = mockPool(node1);
ChannelPool pool2 = mockPool(node2);
CompletableFuture<ChannelPool> pool2Future = new CompletableFuture<>();
ChannelPool pool3 = mockPool(node3);
MockChannelPoolFactoryHelper factoryHelper = MockChannelPoolFactoryHelper.builder(channelPoolFactory).success(node1, KEYSPACE, NodeDistance.LOCAL, pool1).success(node3, KEYSPACE, NodeDistance.LOCAL, pool3).pending(node2, KEYSPACE, NodeDistance.LOCAL, pool2Future).build();
CompletionStage<CqlSession> initFuture = newSession();
factoryHelper.waitForCall(node1, KEYSPACE, NodeDistance.LOCAL);
factoryHelper.waitForCall(node3, KEYSPACE, NodeDistance.LOCAL);
assertThatStage(initFuture).isSuccess();
Session session = CompletableFutures.getCompleted(initFuture.toCompletableFuture());
assertThat(((DefaultSession) session).getPools()).containsValues(pool1, pool3);
eventBus.fire(new DistanceEvent(NodeDistance.LOCAL, node2));
factoryHelper.waitForCall(node2, KEYSPACE, NodeDistance.LOCAL);
// Distance changes to ignored while pool init is in progress
eventBus.fire(new DistanceEvent(NodeDistance.IGNORED, node2));
// Now pool init succeeds
pool2Future.complete(pool2);
// Pool should have been closed
verify(pool2, VERIFY_TIMEOUT).closeAsync();
await().untilAsserted(() -> assertThat(((DefaultSession) session).getPools()).containsValues(pool1, pool3));
}
use of com.datastax.oss.driver.api.core.session.Session in project java-driver by datastax.
the class DefaultSessionPoolsTest method should_do_nothing_if_node_becomes_ignored_but_was_already_ignored.
@Test
public void should_do_nothing_if_node_becomes_ignored_but_was_already_ignored() throws InterruptedException {
ChannelPool pool1 = mockPool(node1);
ChannelPool pool2 = mockPool(node2);
ChannelPool pool3 = mockPool(node3);
MockChannelPoolFactoryHelper factoryHelper = MockChannelPoolFactoryHelper.builder(channelPoolFactory).success(node1, KEYSPACE, NodeDistance.LOCAL, pool1).success(node2, KEYSPACE, NodeDistance.LOCAL, pool2).success(node3, KEYSPACE, NodeDistance.LOCAL, pool3).build();
CompletionStage<CqlSession> initFuture = newSession();
factoryHelper.waitForCall(node1, KEYSPACE, NodeDistance.LOCAL);
factoryHelper.waitForCall(node2, KEYSPACE, NodeDistance.LOCAL);
factoryHelper.waitForCall(node3, KEYSPACE, NodeDistance.LOCAL);
assertThatStage(initFuture).isSuccess();
eventBus.fire(new DistanceEvent(NodeDistance.IGNORED, node2));
verify(pool2, timeout(100)).closeAsync();
Session session = CompletableFutures.getCompleted(initFuture.toCompletableFuture());
assertThat(((DefaultSession) session).getPools()).containsValues(pool1, pool3);
// Fire the same event again, nothing should happen
eventBus.fire(new DistanceEvent(NodeDistance.IGNORED, node2));
TimeUnit.MILLISECONDS.sleep(200);
factoryHelper.verifyNoMoreCalls();
}
Aggregations