Search in sources :

Example 6 with DistanceEvent

use of com.datastax.oss.driver.internal.core.metadata.DistanceEvent 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();
}
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 7 with DistanceEvent

use of com.datastax.oss.driver.internal.core.metadata.DistanceEvent in project java-driver by datastax.

the class DefaultSessionPoolsTest method should_adjust_distance_if_changed_while_init.

@Test
public void should_adjust_distance_if_changed_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();
    // Distance changes while init still pending
    eventBus.fire(new DistanceEvent(NodeDistance.REMOTE, node2));
    pool1Future.complete(pool1);
    pool2Future.complete(pool2);
    pool3Future.complete(pool3);
    verify(pool2, VERIFY_TIMEOUT).resize(NodeDistance.REMOTE);
    assertThatStage(initFuture).isSuccess(session -> 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) Test(org.junit.Test)

Example 8 with DistanceEvent

use of com.datastax.oss.driver.internal.core.metadata.DistanceEvent in project java-driver by datastax.

the class DefaultSessionPoolsTest method should_remove_pool_if_ignored_while_init.

@Test
public void should_remove_pool_if_ignored_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();
    // Distance changes while init still pending
    eventBus.fire(new DistanceEvent(NodeDistance.IGNORED, 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));
}
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) Test(org.junit.Test)

Example 9 with DistanceEvent

use of com.datastax.oss.driver.internal.core.metadata.DistanceEvent 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);
}
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) Test(org.junit.Test)

Example 10 with DistanceEvent

use of com.datastax.oss.driver.internal.core.metadata.DistanceEvent 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)

Aggregations

DistanceEvent (com.datastax.oss.driver.internal.core.metadata.DistanceEvent)11 Test (org.junit.Test)11 CqlSession (com.datastax.oss.driver.api.core.CqlSession)9 ChannelPool (com.datastax.oss.driver.internal.core.pool.ChannelPool)9 Session (com.datastax.oss.driver.api.core.session.Session)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 DriverChannel (com.datastax.oss.driver.internal.core.channel.DriverChannel)2 MockChannelFactoryHelper (com.datastax.oss.driver.internal.core.channel.MockChannelFactoryHelper)2