Search in sources :

Example 16 with Session

use of com.datastax.oss.driver.api.core.session.Session 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();
}
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 17 with Session

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_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));
}
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)

Example 18 with Session

use of com.datastax.oss.driver.api.core.session.Session 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));
}
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)

Aggregations

CqlSession (com.datastax.oss.driver.api.core.CqlSession)18 Session (com.datastax.oss.driver.api.core.session.Session)18 Test (org.junit.Test)18 ChannelPool (com.datastax.oss.driver.internal.core.pool.ChannelPool)13 DistanceEvent (com.datastax.oss.driver.internal.core.metadata.DistanceEvent)6 CompletableFuture (java.util.concurrent.CompletableFuture)4 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)3 DefaultSession (com.datastax.oss.driver.internal.core.session.DefaultSession)3 Node (com.datastax.oss.driver.api.core.metadata.Node)2 Metric (com.codahale.metrics.Metric)1 ReactiveRow (com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow)1 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)1 InvalidKeyspaceException (com.datastax.oss.driver.api.core.InvalidKeyspaceException)1 DefaultDriverOption (com.datastax.oss.driver.api.core.config.DefaultDriverOption)1 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)1 DriverContext (com.datastax.oss.driver.api.core.context.DriverContext)1 LoadBalancingPolicy (com.datastax.oss.driver.api.core.loadbalancing.LoadBalancingPolicy)1 NodeDistance (com.datastax.oss.driver.api.core.loadbalancing.NodeDistance)1 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)1 Metrics (com.datastax.oss.driver.api.core.metrics.Metrics)1