use of org.opensearch.transport.TransportService.NOOP_TRANSPORT_INTERCEPTOR in project OpenSearch by opensearch-project.
the class DisruptableMockTransportTests method initTransports.
@Before
public void initTransports() {
node1 = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Version.CURRENT);
node2 = new DiscoveryNode("node2", buildNewFakeTransportAddress(), Version.CURRENT);
disconnectedLinks = new HashSet<>();
blackholedLinks = new HashSet<>();
blackholedRequestLinks = new HashSet<>();
List<DisruptableMockTransport> transports = new ArrayList<>();
deterministicTaskQueue = new DeterministicTaskQueue(Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), "dummy").build(), random());
final DisruptableMockTransport transport1 = new DisruptableMockTransport(node1, logger, deterministicTaskQueue) {
@Override
protected ConnectionStatus getConnectionStatus(DiscoveryNode destination) {
return DisruptableMockTransportTests.this.getConnectionStatus(getLocalNode(), destination);
}
@Override
protected Optional<DisruptableMockTransport> getDisruptableMockTransport(TransportAddress address) {
return transports.stream().filter(t -> t.getLocalNode().getAddress().equals(address)).findAny();
}
@Override
protected void execute(Runnable runnable) {
deterministicTaskQueue.scheduleNow(runnable);
}
};
final DisruptableMockTransport transport2 = new DisruptableMockTransport(node2, logger, deterministicTaskQueue) {
@Override
protected ConnectionStatus getConnectionStatus(DiscoveryNode destination) {
return DisruptableMockTransportTests.this.getConnectionStatus(getLocalNode(), destination);
}
@Override
protected Optional<DisruptableMockTransport> getDisruptableMockTransport(TransportAddress address) {
return transports.stream().filter(t -> t.getLocalNode().getAddress().equals(address)).findAny();
}
@Override
protected void execute(Runnable runnable) {
deterministicTaskQueue.scheduleNow(runnable);
}
};
transports.add(transport1);
transports.add(transport2);
service1 = transport1.createTransportService(Settings.EMPTY, deterministicTaskQueue.getThreadPool(), NOOP_TRANSPORT_INTERCEPTOR, a -> node1, null, Collections.emptySet());
service2 = transport2.createTransportService(Settings.EMPTY, deterministicTaskQueue.getThreadPool(), NOOP_TRANSPORT_INTERCEPTOR, a -> node2, null, Collections.emptySet());
service1.start();
service2.start();
final PlainActionFuture<Void> fut1 = new PlainActionFuture<>();
service1.connectToNode(node2, fut1);
final PlainActionFuture<Void> fut2 = new PlainActionFuture<>();
service2.connectToNode(node1, fut2);
deterministicTaskQueue.runAllTasksInTimeOrder();
assertTrue(fut1.isDone());
assertTrue(fut2.isDone());
}
Aggregations