|
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 |
|
@@ -139,4 +142,22 @@ public void testConcurrentFailures() throws InterruptedException {
|
139 | 142 | assertThat(exception, instanceOf(IOException.class));
|
140 | 143 | assertEquals(numGroups - 1, exception.getSuppressed().length);
|
141 | 144 | }
|
| 145 | + |
| 146 | + /* |
| 147 | + * It can happen that the same exception causes a grouped listener to be notified of the failure multiple times. Since we suppress |
| 148 | + * additional exceptions into the first exception, we have to guard against suppressing into the same exception, which could occur if we |
| 149 | + * are notified of with the same failure multiple times. This test verifies that the guard against self-suppression remains. |
| 150 | + */ |
| 151 | + public void testRepeatNotificationForTheSameException() { |
| 152 | + final AtomicReference<Exception> finalException = new AtomicReference<>(); |
| 153 | + final GroupedActionListener<Void> listener = |
| 154 | + new GroupedActionListener<Void>(ActionListener.wrap(r -> {}, finalException::set), 2, Collections.emptyList()); |
| 155 | + final Exception e = new Exception(); |
| 156 | + // repeat notification for the same exception |
| 157 | + listener.onFailure(e); |
| 158 | + listener.onFailure(e); |
| 159 | + assertThat(finalException.get(), not(nullValue())); |
| 160 | + assertThat(finalException.get(), equalTo(e)); |
| 161 | + } |
| 162 | + |
142 | 163 | }
|
0 commit comments