use of com.datastax.oss.driver.internal.core.pool.ChannelPool in project java-driver by datastax.
the class InsightsClientTest method mockConnectionPools.
private void mockConnectionPools(DefaultDriverContext driverContext) {
Node node1 = mock(Node.class);
EndPoint endPoint1 = mock(EndPoint.class);
when(endPoint1.resolve()).thenReturn(new InetSocketAddress("127.0.0.1", 10));
when(node1.getEndPoint()).thenReturn(endPoint1);
when(node1.getOpenConnections()).thenReturn(1);
ChannelPool channelPool1 = mock(ChannelPool.class);
when(channelPool1.getInFlight()).thenReturn(10);
Node node2 = mock(Node.class);
EndPoint endPoint2 = mock(EndPoint.class);
when(endPoint2.resolve()).thenReturn(new InetSocketAddress("127.0.0.1", 20));
when(node2.getEndPoint()).thenReturn(endPoint2);
when(node2.getOpenConnections()).thenReturn(2);
ChannelPool channelPool2 = mock(ChannelPool.class);
when(channelPool2.getInFlight()).thenReturn(20);
Map<Node, ChannelPool> channelPools = ImmutableMap.of(node1, channelPool1, node2, channelPool2);
PoolManager poolManager = mock(PoolManager.class);
when(poolManager.getPools()).thenReturn(channelPools);
when(driverContext.getPoolManager()).thenReturn(poolManager);
}
use of com.datastax.oss.driver.internal.core.pool.ChannelPool in project java-driver by datastax.
the class RemovedNodeIT method should_signal_and_destroy_pool_when_node_gets_removed.
@Test
public void should_signal_and_destroy_pool_when_node_gets_removed() {
RemovalListener removalListener = new RemovalListener();
try (CqlSession session = SessionUtils.newSession(CCM_RULE, null, removalListener, null, null)) {
assertThat(session.getMetadata().getTokenMap()).isPresent();
Set<TokenRange> tokenRanges = session.getMetadata().getTokenMap().get().getTokenRanges();
assertThat(tokenRanges).hasSize(4);
CCM_RULE.getCcmBridge().decommission(2);
await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).until(() -> removalListener.removedNode != null);
Map<Node, ChannelPool> pools = ((DefaultSession) session).getPools();
await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).until(() -> !pools.containsKey(removalListener.removedNode));
await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).until(() -> session.getMetadata().getTokenMap().get().getTokenRanges().size() == 3);
}
}
use of com.datastax.oss.driver.internal.core.pool.ChannelPool in project java-driver by datastax.
the class DefaultSessionPoolsTest method should_not_connect_to_forced_down_nodes.
@Test
public void should_not_connect_to_forced_down_nodes() {
when(node2.getState()).thenReturn(NodeState.FORCED_DOWN);
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 -> 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_initialize_pools_with_distances.
@Test
public void should_initialize_pools_with_distances() {
when(node3.getDistance()).thenReturn(NodeDistance.REMOTE);
CompletableFuture<ChannelPool> pool1Future = new CompletableFuture<>();
CompletableFuture<ChannelPool> pool2Future = new CompletableFuture<>();
CompletableFuture<ChannelPool> pool3Future = new CompletableFuture<>();
ChannelPool pool1 = mockPool(node1);
ChannelPool pool2 = mockPool(node2);
ChannelPool pool3 = mockPool(node3);
MockChannelPoolFactoryHelper factoryHelper = MockChannelPoolFactoryHelper.builder(channelPoolFactory).pending(node1, KEYSPACE, NodeDistance.LOCAL, pool1Future).pending(node2, KEYSPACE, NodeDistance.LOCAL, pool2Future).pending(node3, KEYSPACE, NodeDistance.REMOTE, pool3Future).build();
CompletionStage<CqlSession> initFuture = newSession();
factoryHelper.waitForCall(node1, KEYSPACE, NodeDistance.LOCAL);
factoryHelper.waitForCall(node2, KEYSPACE, NodeDistance.LOCAL);
factoryHelper.waitForCall(node3, KEYSPACE, NodeDistance.REMOTE);
assertThatStage(initFuture).isNotDone();
pool1Future.complete(pool1);
pool2Future.complete(pool2);
pool3Future.complete(pool3);
assertThatStage(initFuture).isSuccess(session -> 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 DefaultSessionPoolsTest method should_remove_pool_if_forced_down_while_init.
@Test
public void should_remove_pool_if_forced_down_while_init() {
CompletableFuture<ChannelPool> pool1Future = new CompletableFuture<>();
CompletableFuture<ChannelPool> pool2Future = new CompletableFuture<>();
CompletableFuture<ChannelPool> pool3Future = new CompletableFuture<>();
ChannelPool pool1 = mockPool(node1);
ChannelPool pool2 = mockPool(node2);
ChannelPool pool3 = mockPool(node3);
MockChannelPoolFactoryHelper factoryHelper = MockChannelPoolFactoryHelper.builder(channelPoolFactory).pending(node1, KEYSPACE, NodeDistance.LOCAL, pool1Future).pending(node2, KEYSPACE, NodeDistance.LOCAL, pool2Future).pending(node3, KEYSPACE, NodeDistance.LOCAL, pool3Future).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).isNotDone();
// Forced down while init still pending
eventBus.fire(NodeStateEvent.changed(NodeState.UP, NodeState.FORCED_DOWN, node2));
pool1Future.complete(pool1);
pool2Future.complete(pool2);
pool3Future.complete(pool3);
verify(pool2, VERIFY_TIMEOUT).closeAsync();
assertThatStage(initFuture).isSuccess(session -> assertThat(((DefaultSession) session).getPools()).containsValues(pool1, pool3));
}
Aggregations