|
19 | 19 |
|
20 | 20 | package org.elasticsearch.action.support;
|
21 | 21 |
|
| 22 | +import org.elasticsearch.ElasticsearchException; |
22 | 23 | import org.elasticsearch.common.unit.TimeValue;
|
| 24 | +import org.elasticsearch.common.util.concurrent.UncategorizedExecutionException; |
23 | 25 | import org.elasticsearch.test.ESTestCase;
|
| 26 | +import org.elasticsearch.transport.RemoteTransportException; |
24 | 27 |
|
25 | 28 | import java.util.Objects;
|
26 | 29 | import java.util.concurrent.BrokenBarrierException;
|
27 | 30 | import java.util.concurrent.CyclicBarrier;
|
| 31 | +import java.util.concurrent.ExecutionException; |
28 | 32 | import java.util.concurrent.TimeUnit;
|
29 | 33 | import java.util.concurrent.atomic.AtomicBoolean;
|
30 | 34 |
|
@@ -90,4 +94,28 @@ protected String convert(final Integer listenerResponse) {
|
90 | 94 | thread.join();
|
91 | 95 | }
|
92 | 96 |
|
| 97 | + public void testUnwrapException() { |
| 98 | + checkUnwrap(new RemoteTransportException("test", new RuntimeException()), RuntimeException.class, RemoteTransportException.class); |
| 99 | + checkUnwrap(new RemoteTransportException("test", new Exception()), |
| 100 | + UncategorizedExecutionException.class, RemoteTransportException.class); |
| 101 | + checkUnwrap(new Exception(), UncategorizedExecutionException.class, Exception.class); |
| 102 | + checkUnwrap(new ElasticsearchException("test", new Exception()), ElasticsearchException.class, ElasticsearchException.class); |
| 103 | + } |
| 104 | + |
| 105 | + private void checkUnwrap(Exception exception, Class<? extends Exception> actionGetException, |
| 106 | + Class<? extends Exception> getException) { |
| 107 | + final AdapterActionFuture<Void, Void> adapter = new AdapterActionFuture<Void, Void>() { |
| 108 | + @Override |
| 109 | + protected Void convert(Void listenerResponse) { |
| 110 | + fail(); |
| 111 | + return null; |
| 112 | + } |
| 113 | + }; |
| 114 | + |
| 115 | + adapter.onFailure(exception); |
| 116 | + assertEquals(actionGetException, expectThrows(RuntimeException.class, adapter::actionGet).getClass()); |
| 117 | + assertEquals(actionGetException, expectThrows(RuntimeException.class, () -> adapter.actionGet(10, TimeUnit.SECONDS)).getClass()); |
| 118 | + assertEquals(getException, expectThrows(ExecutionException.class, () -> adapter.get()).getCause().getClass()); |
| 119 | + assertEquals(getException, expectThrows(ExecutionException.class, () -> adapter.get(10, TimeUnit.SECONDS)).getCause().getClass()); |
| 120 | + } |
93 | 121 | }
|
0 commit comments