use of org.opensearch.transport.TcpChannel in project OpenSearch by opensearch-project.
the class SimpleNioTransportTests method build.
@Override
protected Transport build(Settings settings, final Version version, ClusterSettings clusterSettings, boolean doHandshake) {
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
NetworkService networkService = new NetworkService(Collections.emptyList());
return new NioTransport(settings, version, threadPool, networkService, new MockPageCacheRecycler(settings), namedWriteableRegistry, new NoneCircuitBreakerService(), new NioGroupFactory(settings, logger)) {
@Override
public void executeHandshake(DiscoveryNode node, TcpChannel channel, ConnectionProfile profile, ActionListener<Version> listener) {
if (doHandshake) {
super.executeHandshake(node, channel, profile, listener);
} else {
listener.onResponse(version.minimumCompatibilityVersion());
}
}
};
}
use of org.opensearch.transport.TcpChannel in project OpenSearch by opensearch-project.
the class SimpleNioTransportTests method testDefaultKeepAliveSettings.
public void testDefaultKeepAliveSettings() throws IOException {
assumeTrue("setting default keepalive options not supported on this platform", (IOUtils.LINUX || IOUtils.MAC_OS_X) && JavaVersion.current().compareTo(JavaVersion.parse("11")) >= 0);
try (MockTransportService serviceC = buildService("TS_C", Version.CURRENT, Settings.EMPTY);
MockTransportService serviceD = buildService("TS_D", Version.CURRENT, Settings.EMPTY)) {
serviceC.start();
serviceC.acceptIncomingRequests();
serviceD.start();
serviceD.acceptIncomingRequests();
try (Transport.Connection connection = serviceC.openConnection(serviceD.getLocalDiscoNode(), TestProfiles.LIGHT_PROFILE)) {
assertThat(connection, instanceOf(StubbableTransport.WrappedConnection.class));
Transport.Connection conn = ((StubbableTransport.WrappedConnection) connection).getConnection();
assertThat(conn, instanceOf(TcpTransport.NodeChannels.class));
TcpTransport.NodeChannels nodeChannels = (TcpTransport.NodeChannels) conn;
for (TcpChannel channel : nodeChannels.getChannels()) {
assertFalse(channel.isServerChannel());
checkDefaultKeepAliveOptions(channel);
}
assertThat(serviceD.getOriginalTransport(), instanceOf(TcpTransport.class));
for (TcpChannel channel : getAcceptedChannels((TcpTransport) serviceD.getOriginalTransport())) {
assertTrue(channel.isServerChannel());
checkDefaultKeepAliveOptions(channel);
}
}
}
}
use of org.opensearch.transport.TcpChannel in project OpenSearch by opensearch-project.
the class TaskManagerTests method testTrackingChannelTask.
public void testTrackingChannelTask() throws Exception {
final TaskManager taskManager = new TaskManager(Settings.EMPTY, threadPool, Collections.emptySet());
Set<Task> cancelledTasks = ConcurrentCollections.newConcurrentSet();
taskManager.setTaskCancellationService(new TaskCancellationService(mock(TransportService.class)) {
@Override
void cancelTaskAndDescendants(CancellableTask task, String reason, boolean waitForCompletion, ActionListener<Void> listener) {
assertThat(reason, equalTo("channel was closed"));
assertFalse(waitForCompletion);
assertTrue("task [" + task + "] was cancelled already", cancelledTasks.add(task));
}
});
Map<TcpChannel, Set<Task>> pendingTasks = new HashMap<>();
Set<Task> expectedCancelledTasks = new HashSet<>();
FakeTcpChannel[] channels = new FakeTcpChannel[randomIntBetween(1, 10)];
List<Releasable> stopTrackingTasks = new ArrayList<>();
for (int i = 0; i < channels.length; i++) {
channels[i] = new SingleThreadedTcpChannel();
}
int iterations = randomIntBetween(1, 200);
for (int i = 0; i < iterations; i++) {
final List<Releasable> subset = randomSubsetOf(stopTrackingTasks);
stopTrackingTasks.removeAll(subset);
Releasables.close(subset);
final FakeTcpChannel channel = randomFrom(channels);
final Task task = taskManager.register("transport", "test", new CancellableRequest(Integer.toString(i)));
if (channel.isOpen() && randomBoolean()) {
channel.close();
expectedCancelledTasks.addAll(pendingTasks.getOrDefault(channel, Collections.emptySet()));
}
final Releasable stopTracking = taskManager.startTrackingCancellableChannelTask(channel, (CancellableTask) task);
if (channel.isOpen()) {
pendingTasks.computeIfAbsent(channel, k -> new HashSet<>()).add(task);
stopTrackingTasks.add(() -> {
stopTracking.close();
assertTrue(pendingTasks.get(channel).remove(task));
expectedCancelledTasks.remove(task);
});
} else {
expectedCancelledTasks.add(task);
}
}
assertBusy(() -> assertThat(expectedCancelledTasks, everyItem(in(cancelledTasks))), 30, TimeUnit.SECONDS);
for (FakeTcpChannel channel : channels) {
channel.close();
}
assertThat(taskManager.numberOfChannelPendingTaskTrackers(), equalTo(0));
}
use of org.opensearch.transport.TcpChannel in project OpenSearch by opensearch-project.
the class SimpleMockNioTransportTests method build.
@Override
protected Transport build(Settings settings, final Version version, ClusterSettings clusterSettings, boolean doHandshake) {
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
NetworkService networkService = new NetworkService(Collections.emptyList());
return new MockNioTransport(settings, version, threadPool, networkService, new MockPageCacheRecycler(settings), namedWriteableRegistry, new NoneCircuitBreakerService()) {
@Override
public void executeHandshake(DiscoveryNode node, TcpChannel channel, ConnectionProfile profile, ActionListener<Version> listener) {
if (doHandshake) {
super.executeHandshake(node, channel, profile, listener);
} else {
listener.onResponse(version.minimumCompatibilityVersion());
}
}
};
}
use of org.opensearch.transport.TcpChannel in project OpenSearch by opensearch-project.
the class SimpleNetty4TransportTests method testDefaultKeepAliveSettings.
public void testDefaultKeepAliveSettings() throws IOException {
assumeTrue("setting default keepalive options not supported on this platform", (IOUtils.LINUX || IOUtils.MAC_OS_X) && JavaVersion.current().compareTo(JavaVersion.parse("11")) >= 0);
try (MockTransportService serviceC = buildService("TS_C", Version.CURRENT, Settings.EMPTY);
MockTransportService serviceD = buildService("TS_D", Version.CURRENT, Settings.EMPTY)) {
serviceC.start();
serviceC.acceptIncomingRequests();
serviceD.start();
serviceD.acceptIncomingRequests();
try (Transport.Connection connection = serviceC.openConnection(serviceD.getLocalDiscoNode(), TestProfiles.LIGHT_PROFILE)) {
assertThat(connection, instanceOf(StubbableTransport.WrappedConnection.class));
Transport.Connection conn = ((StubbableTransport.WrappedConnection) connection).getConnection();
assertThat(conn, instanceOf(TcpTransport.NodeChannels.class));
TcpTransport.NodeChannels nodeChannels = (TcpTransport.NodeChannels) conn;
for (TcpChannel channel : nodeChannels.getChannels()) {
assertFalse(channel.isServerChannel());
checkDefaultKeepAliveOptions(channel);
}
assertThat(serviceD.getOriginalTransport(), instanceOf(TcpTransport.class));
for (TcpChannel channel : getAcceptedChannels((TcpTransport) serviceD.getOriginalTransport())) {
assertTrue(channel.isServerChannel());
checkDefaultKeepAliveOptions(channel);
}
}
}
}
Aggregations