use of com.datastax.oss.driver.internal.core.pool.ChannelPool in project java-driver by datastax.
the class DefaultSessionPoolsTest method should_close_all_pools_when_closing.
@Test
public void should_close_all_pools_when_closing() {
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();
Session session = CompletableFutures.getCompleted(initFuture.toCompletableFuture());
CompletionStage<Void> closeFuture = session.closeAsync();
assertThatStage(closeFuture).isSuccess();
verify(pool1, VERIFY_TIMEOUT).closeAsync();
verify(pool2, VERIFY_TIMEOUT).closeAsync();
verify(pool3, VERIFY_TIMEOUT).closeAsync();
}
use of com.datastax.oss.driver.internal.core.pool.ChannelPool in project java-driver by datastax.
the class DefaultSessionPoolsTest method should_resize_pool_if_distance_changes.
@Test
public void should_resize_pool_if_distance_changes() {
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.REMOTE, node2));
verify(pool2, timeout(500)).resize(NodeDistance.REMOTE);
}
use of com.datastax.oss.driver.internal.core.pool.ChannelPool in project java-driver by datastax.
the class DefaultSessionPoolsTest method should_remove_pool_if_node_becomes_ignored.
@Test
public void should_remove_pool_if_node_becomes_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(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(500)).closeAsync();
Session session = CompletableFutures.getCompleted(initFuture.toCompletableFuture());
await().untilAsserted(() -> assertThat(((DefaultSession) session).getPools()).containsValues(pool1, pool3));
}
use of com.datastax.oss.driver.internal.core.pool.ChannelPool in project java-driver by datastax.
the class DefaultSessionPoolsTest method should_adjust_distance_if_changed_while_recreating.
@Test
public void should_adjust_distance_if_changed_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 again while pool init is in progress
eventBus.fire(new DistanceEvent(NodeDistance.REMOTE, node2));
// Now pool init succeeds
pool2Future.complete(pool2);
// Pool should have been adjusted
verify(pool2, VERIFY_TIMEOUT).resize(NodeDistance.REMOTE);
await().untilAsserted(() -> assertThat(((DefaultSession) session).getPools()).containsValues(pool1, pool2, pool3));
}
use of com.datastax.oss.driver.internal.core.pool.ChannelPool in project java-driver by datastax.
the class AddedNodeIT method should_signal_and_create_pool_when_node_gets_added.
@Test
public void should_signal_and_create_pool_when_node_gets_added() {
AddListener addListener = new AddListener();
try (CqlSession session = SessionUtils.newSession(CCM_RULE, null, addListener, null, null)) {
assertThat(session.getMetadata().getTokenMap()).isPresent();
Set<TokenRange> tokenRanges = session.getMetadata().getTokenMap().get().getTokenRanges();
assertThat(tokenRanges).hasSize(3);
CCM_RULE.getCcmBridge().add(4, "dc1");
await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).until(() -> addListener.addedNode != null);
Map<Node, ChannelPool> pools = ((DefaultSession) session).getPools();
await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).until(() -> pools.containsKey(addListener.addedNode));
await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).until(() -> session.getMetadata().getTokenMap().get().getTokenRanges().size() == 4);
}
}
Aggregations