Skip to content

Commit

Permalink
Use assertNoSuccessListener
Browse files Browse the repository at this point in the history
  • Loading branch information
henningandersen committed May 31, 2024
1 parent f93cc1c commit f34ef8f
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.TransportVersion;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionListenerResponseHandler;
import org.elasticsearch.action.support.ActionTestUtils;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodeUtils;
Expand Down Expand Up @@ -47,6 +48,7 @@
import static java.util.Collections.emptySet;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.startsWith;

public class TransportServiceLifecycleTests extends ESTestCase {
Expand Down Expand Up @@ -248,24 +250,28 @@ public void testOnConnetionCloseStackOverflowAvoidance() {
private void onConnectionClosedUsesHandlerExecutor(Settings settings, String executorName, String expectedExecutor) {
try (var nodeA = new TestNode("node-A", settings)) {
final var testThread = Thread.currentThread();
final var future = new PlainActionFuture<TransportResponse.Empty>();
final var future = new PlainActionFuture<Exception>();
Executor executor = nodeA.getExecutor(executorName);
Transport.Connection connection = nodeA.getDevNullConnection();
nodeA.transportService.sendRequest(
connection,
TestNode.randomActionName(random()),
new TransportRequest.Empty(),
TransportRequestOptions.EMPTY,
new ActionListenerResponseHandler<>(ActionListener.assertOnce(future.delegateResponse((l, e) -> {
assertThat(EsExecutors.executorName(Thread.currentThread()), equalTo(expectedExecutor));
if (expectedExecutor == null) {
assertSame(testThread, Thread.currentThread());
}
l.onFailure(e);
})), unusedReader(), executor)
new ActionListenerResponseHandler<>(
ActionListener.assertOnce(ActionTestUtils.assertNoSuccessListener(future::onResponse).delegateResponse((l, e) -> {
assertThat(EsExecutors.executorName(Thread.currentThread()), equalTo(expectedExecutor));
if (expectedExecutor == null) {
assertSame(testThread, Thread.currentThread());
}
l.onFailure(e);
})),
unusedReader(),
executor
)
);
nodeA.transportService.onConnectionClosed(connection);
expectThrows(ExecutionException.class, NodeDisconnectedException.class, () -> future.get(10, TimeUnit.SECONDS));
assertThat(safeGet(future), instanceOf(NodeDisconnectedException.class));
}
}

Expand Down

0 comments on commit f34ef8f

Please sign in to comment.