use of com.datastax.oss.driver.internal.core.channel.DriverChannel in project java-driver by datastax.
the class ChannelSocketOptionsIT method should_report_socket_options.
@Test
public void should_report_socket_options() {
Session session = SESSION_RULE.session();
DriverExecutionProfile config = session.getContext().getConfig().getDefaultProfile();
assertThat(config.getBoolean(SOCKET_TCP_NODELAY)).isTrue();
assertThat(config.getBoolean(SOCKET_KEEP_ALIVE)).isFalse();
assertThat(config.getBoolean(SOCKET_REUSE_ADDRESS)).isFalse();
assertThat(config.getInt(SOCKET_LINGER_INTERVAL)).isEqualTo(10);
assertThat(config.getInt(SOCKET_RECEIVE_BUFFER_SIZE)).isEqualTo(123456);
assertThat(config.getInt(SOCKET_SEND_BUFFER_SIZE)).isEqualTo(123456);
Node node = session.getMetadata().getNodes().values().iterator().next();
if (session instanceof SessionWrapper) {
session = ((SessionWrapper) session).getDelegate();
}
DriverChannel channel = ((DefaultSession) session).getChannel(node, "test");
assertThat(channel).isNotNull();
assertThat(channel.config()).isInstanceOf(SocketChannelConfig.class);
SocketChannelConfig socketConfig = (SocketChannelConfig) channel.config();
assertThat(socketConfig.isTcpNoDelay()).isTrue();
assertThat(socketConfig.isKeepAlive()).isFalse();
assertThat(socketConfig.isReuseAddress()).isFalse();
assertThat(socketConfig.getSoLinger()).isEqualTo(10);
RecvByteBufAllocator allocator = socketConfig.getRecvByteBufAllocator();
assertThat(allocator).isInstanceOf(FixedRecvByteBufAllocator.class);
assertThat(allocator.newHandle().guess()).isEqualTo(123456);
// cannot assert around SO_RCVBUF and SO_SNDBUF, such values are just hints
}
use of com.datastax.oss.driver.internal.core.channel.DriverChannel in project java-driver by datastax.
the class ChannelSet method getAvailableIds.
/**
* @return the number of available stream ids on all channels in this channel set.
*/
int getAvailableIds() {
int availableIds = 0;
DriverChannel[] snapshot = this.channels;
for (DriverChannel channel : snapshot) {
availableIds += channel.getAvailableIds();
}
return availableIds;
}
use of com.datastax.oss.driver.internal.core.channel.DriverChannel in project java-driver by datastax.
the class ChannelSet method getOrphanedIds.
/**
* @return the number of stream ids for requests in all channels in this channel set that have
* either timed out or been cancelled, but for which we can't release the stream id because a
* request might still come from the server.
*/
int getOrphanedIds() {
int orphanedIds = 0;
DriverChannel[] snapshot = this.channels;
for (DriverChannel channel : snapshot) {
orphanedIds += channel.getOrphanedIds();
}
return orphanedIds;
}
use of com.datastax.oss.driver.internal.core.channel.DriverChannel in project java-driver by datastax.
the class ChannelSet method next.
/**
* @return null if the set is empty or all are full
*/
DriverChannel next() {
DriverChannel[] snapshot = this.channels;
switch(snapshot.length) {
case 0:
return null;
case 1:
DriverChannel onlyChannel = snapshot[0];
return onlyChannel.preAcquireId() ? onlyChannel : null;
default:
for (int i = 0; i < MAX_ITERATIONS; i++) {
DriverChannel best = null;
int bestScore = 0;
for (DriverChannel channel : snapshot) {
int score = channel.getAvailableIds();
if (score > bestScore) {
bestScore = score;
best = channel;
}
}
if (best == null) {
return null;
} else if (best.preAcquireId()) {
return best;
}
}
LOG.trace("Could not select a channel after {} iterations", MAX_ITERATIONS);
return null;
}
}
use of com.datastax.oss.driver.internal.core.channel.DriverChannel in project java-driver by datastax.
the class ChannelPoolInitTest method should_initialize_when_all_channels_succeed.
@Test
public void should_initialize_when_all_channels_succeed() throws Exception {
when(defaultProfile.getInt(DefaultDriverOption.CONNECTION_POOL_LOCAL_SIZE)).thenReturn(3);
DriverChannel channel1 = newMockDriverChannel(1);
DriverChannel channel2 = newMockDriverChannel(2);
DriverChannel channel3 = newMockDriverChannel(3);
MockChannelFactoryHelper factoryHelper = MockChannelFactoryHelper.builder(channelFactory).success(node, channel1).success(node, channel2).success(node, channel3).build();
CompletionStage<ChannelPool> poolFuture = ChannelPool.init(node, null, NodeDistance.LOCAL, context, "test");
factoryHelper.waitForCalls(node, 3);
assertThatStage(poolFuture).isSuccess(pool -> assertThat(pool.channels).containsOnly(channel1, channel2, channel3));
verify(eventBus, VERIFY_TIMEOUT.times(3)).fire(ChannelEvent.channelOpened(node));
factoryHelper.verifyNoMoreCalls();
}
Aggregations