Search in sources :

Example 6 with ChannelPool

use of com.datastax.oss.driver.internal.core.pool.ChannelPool in project java-driver by datastax.

the class DefaultSessionPoolsTest method should_not_connect_to_ignored_nodes.

@Test
public void should_not_connect_to_ignored_nodes() {
    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 -> assertThat(((DefaultSession) session).getPools()).containsValues(pool1, pool3));
}
Also used : ChannelPool(com.datastax.oss.driver.internal.core.pool.ChannelPool) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 7 with ChannelPool

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_recreating.

@Test
public void should_remove_pool_if_forced_down_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);
    // Forced down while pool init is in progress
    eventBus.fire(NodeStateEvent.changed(NodeState.UP, NodeState.FORCED_DOWN, 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));
}
Also used : ChannelPool(com.datastax.oss.driver.internal.core.pool.ChannelPool) CompletableFuture(java.util.concurrent.CompletableFuture) DistanceEvent(com.datastax.oss.driver.internal.core.metadata.DistanceEvent) CqlSession(com.datastax.oss.driver.api.core.CqlSession) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Session(com.datastax.oss.driver.api.core.session.Session) Test(org.junit.Test)

Example 8 with ChannelPool

use of com.datastax.oss.driver.internal.core.pool.ChannelPool in project java-driver by datastax.

the class DefaultSessionPoolsTest method should_recreate_pool_if_node_is_forced_back_up.

@Test
public void should_recreate_pool_if_node_is_forced_back_up() {
    when(node2.getState()).thenReturn(NodeState.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(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(NodeStateEvent.changed(NodeState.FORCED_DOWN, NodeState.UP, node2));
    factoryHelper.waitForCall(node2, KEYSPACE, NodeDistance.LOCAL);
    await().untilAsserted(() -> assertThat(((DefaultSession) session).getPools()).containsValues(pool1, pool2, pool3));
}
Also used : ChannelPool(com.datastax.oss.driver.internal.core.pool.ChannelPool) CqlSession(com.datastax.oss.driver.api.core.CqlSession) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Session(com.datastax.oss.driver.api.core.session.Session) Test(org.junit.Test)

Example 9 with ChannelPool

use of com.datastax.oss.driver.internal.core.pool.ChannelPool 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();
}
Also used : ChannelPool(com.datastax.oss.driver.internal.core.pool.ChannelPool) CqlSession(com.datastax.oss.driver.api.core.CqlSession) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Session(com.datastax.oss.driver.api.core.session.Session) Test(org.junit.Test)

Example 10 with ChannelPool

use of com.datastax.oss.driver.internal.core.pool.ChannelPool 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));
}
Also used : ChannelPool(com.datastax.oss.driver.internal.core.pool.ChannelPool) DistanceEvent(com.datastax.oss.driver.internal.core.metadata.DistanceEvent) CqlSession(com.datastax.oss.driver.api.core.CqlSession) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Session(com.datastax.oss.driver.api.core.session.Session) Test(org.junit.Test)

Aggregations

ChannelPool (com.datastax.oss.driver.internal.core.pool.ChannelPool)25 CqlSession (com.datastax.oss.driver.api.core.CqlSession)23 Test (org.junit.Test)23 Session (com.datastax.oss.driver.api.core.session.Session)13 CompletableFuture (java.util.concurrent.CompletableFuture)10 DistanceEvent (com.datastax.oss.driver.internal.core.metadata.DistanceEvent)9 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)3 Node (com.datastax.oss.driver.api.core.metadata.Node)3 TokenRange (com.datastax.oss.driver.api.core.metadata.token.TokenRange)2 DefaultSession (com.datastax.oss.driver.internal.core.session.DefaultSession)2 SessionStateForNode (com.datastax.dse.driver.internal.core.insights.schema.SessionStateForNode)1 EndPoint (com.datastax.oss.driver.api.core.metadata.EndPoint)1 DefaultNode (com.datastax.oss.driver.internal.core.metadata.DefaultNode)1 PoolManager (com.datastax.oss.driver.internal.core.session.PoolManager)1 InetSocketAddress (java.net.InetSocketAddress)1