|
33 | 33 | import java.util.concurrent.atomic.AtomicReference;
|
34 | 34 |
|
35 | 35 | import static org.hamcrest.CoreMatchers.instanceOf;
|
| 36 | +import static org.hamcrest.CoreMatchers.nullValue; |
| 37 | +import static org.hamcrest.Matchers.equalTo; |
| 38 | +import static org.hamcrest.Matchers.not; |
36 | 39 |
|
37 | 40 | public class GroupedActionListenerTests extends ESTestCase {
|
38 | 41 |
|
@@ -133,4 +136,21 @@ public void testConcurrentFailures() throws InterruptedException {
|
133 | 136 | assertThat(exception, instanceOf(IOException.class));
|
134 | 137 | assertEquals(numGroups - 1, exception.getSuppressed().length);
|
135 | 138 | }
|
| 139 | + |
| 140 | + /* |
| 141 | + * It can happen that the same exception causes a grouped listener to be notified of the failure multiple times. Since we suppress |
| 142 | + * additional exceptions into the first exception, we have to guard against suppressing into the same exception, which could occur if we |
| 143 | + * are notified of with the same failure multiple times. This test verifies that the guard against self-suppression remains. |
| 144 | + */ |
| 145 | + public void testRepeatNotificationForTheSameException() { |
| 146 | + final AtomicReference<Exception> finalException = new AtomicReference<>(); |
| 147 | + final GroupedActionListener<Void> listener = new GroupedActionListener<>(ActionListener.wrap(r -> {}, finalException::set), 2); |
| 148 | + final Exception e = new Exception(); |
| 149 | + // repeat notification for the same exception |
| 150 | + listener.onFailure(e); |
| 151 | + listener.onFailure(e); |
| 152 | + assertThat(finalException.get(), not(nullValue())); |
| 153 | + assertThat(finalException.get(), equalTo(e)); |
| 154 | + } |
| 155 | + |
136 | 156 | }
|
0 commit comments