use of com.datastax.oss.driver.internal.core.channel.DriverChannel in project java-driver by datastax.
the class DefaultTopologyMonitor method refreshNode.
@Override
public CompletionStage<Optional<NodeInfo>> refreshNode(Node node) {
if (closeFuture.isDone()) {
return CompletableFutures.failedFuture(new IllegalStateException("closed"));
}
LOG.debug("[{}] Refreshing info for {}", logPrefix, node);
DriverChannel channel = controlConnection.channel();
EndPoint localEndPoint = channel.getEndPoint();
if (node.getEndPoint().equals(channel.getEndPoint())) {
// refreshNode is called for nodes that just came up. If the control node just came up, it
// means the control connection just reconnected, which means we did a full node refresh. So
// we don't need to process this call.
LOG.debug("[{}] Ignoring refresh of control node", logPrefix);
return CompletableFuture.completedFuture(Optional.empty());
} else if (node.getBroadcastAddress().isPresent()) {
CompletionStage<AdminResult> query;
if (isSchemaV2) {
query = query(channel, "SELECT * FROM " + getPeerTableName() + " WHERE peer = :address and peer_port = :port", ImmutableMap.of("address", node.getBroadcastAddress().get().getAddress(), "port", node.getBroadcastAddress().get().getPort()));
} else {
query = query(channel, "SELECT * FROM " + getPeerTableName() + " WHERE peer = :address", ImmutableMap.of("address", node.getBroadcastAddress().get().getAddress()));
}
return query.thenApply(result -> firstPeerRowAsNodeInfo(result, localEndPoint));
} else {
return query(channel, "SELECT * FROM " + getPeerTableName()).thenApply(result -> findInPeers(result, node.getHostId(), localEndPoint));
}
}
use of com.datastax.oss.driver.internal.core.channel.DriverChannel in project java-driver by datastax.
the class DefaultTopologyMonitor method getNewNodeInfo.
@Override
public CompletionStage<Optional<NodeInfo>> getNewNodeInfo(InetSocketAddress broadcastRpcAddress) {
if (closeFuture.isDone()) {
return CompletableFutures.failedFuture(new IllegalStateException("closed"));
}
LOG.debug("[{}] Fetching info for new node {}", logPrefix, broadcastRpcAddress);
DriverChannel channel = controlConnection.channel();
EndPoint localEndPoint = channel.getEndPoint();
return query(channel, "SELECT * FROM " + getPeerTableName()).thenApply(result -> findInPeers(result, broadcastRpcAddress, localEndPoint));
}
use of com.datastax.oss.driver.internal.core.channel.DriverChannel in project java-driver by datastax.
the class ControlConnectionTest method should_init_with_first_contact_point_if_reachable.
@Test
public void should_init_with_first_contact_point_if_reachable() {
// Given
DriverChannel channel1 = newMockDriverChannel(1);
MockChannelFactoryHelper factoryHelper = MockChannelFactoryHelper.builder(channelFactory).success(node1, channel1).build();
// When
CompletionStage<Void> initFuture = controlConnection.init(false, false, false);
factoryHelper.waitForCall(node1);
// Then
assertThatStage(initFuture).isSuccess(v -> assertThat(controlConnection.channel()).isEqualTo(channel1));
verify(eventBus, VERIFY_TIMEOUT).fire(ChannelEvent.channelOpened(node1));
factoryHelper.verifyNoMoreCalls();
}
use of com.datastax.oss.driver.internal.core.channel.DriverChannel in project java-driver by datastax.
the class ControlConnectionTest method should_close_channel_when_closing.
@Test
public void should_close_channel_when_closing() {
// Given
DriverChannel channel1 = newMockDriverChannel(1);
MockChannelFactoryHelper factoryHelper = MockChannelFactoryHelper.builder(channelFactory).success(node1, channel1).build();
CompletionStage<Void> initFuture = controlConnection.init(false, false, false);
factoryHelper.waitForCall(node1);
assertThatStage(initFuture).isSuccess();
// When
CompletionStage<Void> closeFuture = controlConnection.forceCloseAsync();
// Then
assertThatStage(closeFuture).isSuccess();
verify(channel1, VERIFY_TIMEOUT).forceClose();
factoryHelper.verifyNoMoreCalls();
}
use of com.datastax.oss.driver.internal.core.channel.DriverChannel in project java-driver by datastax.
the class ControlConnectionTest method should_force_reconnection_even_if_connected.
@Test
public void should_force_reconnection_even_if_connected() {
// Given
DriverChannel channel1 = newMockDriverChannel(1);
DriverChannel channel2 = newMockDriverChannel(2);
MockChannelFactoryHelper factoryHelper = MockChannelFactoryHelper.builder(channelFactory).success(node1, channel1).failure(node1, "mock failure").success(node2, channel2).build();
CompletionStage<Void> initFuture = controlConnection.init(false, false, false);
factoryHelper.waitForCall(node1);
assertThatStage(initFuture).isSuccess(v -> assertThat(controlConnection.channel()).isEqualTo(channel1));
verify(eventBus, VERIFY_TIMEOUT).fire(ChannelEvent.channelOpened(node1));
// When
controlConnection.reconnectNow();
// Then
factoryHelper.waitForCall(node1);
factoryHelper.waitForCall(node2);
await().untilAsserted(() -> assertThat(controlConnection.channel()).isEqualTo(channel2));
verify(channel1, VERIFY_TIMEOUT).forceClose();
verify(eventBus, VERIFY_TIMEOUT).fire(ChannelEvent.channelClosed(node1));
verify(eventBus, VERIFY_TIMEOUT).fire(ChannelEvent.channelOpened(node2));
factoryHelper.verifyNoMoreCalls();
}
Aggregations