Wrap listener metadata state changes in a try-finally block inside the AEQ listener processEvents(:List<AsyncEvent>) method.

This commit is contained in:
John Blum
2020-12-01 16:47:34 -08:00
parent 2089db6864
commit cbbf8d9335
2 changed files with 42 additions and 4 deletions

View File

@@ -420,6 +420,41 @@ public class RepositoryAsyncEventListenerUnitTests {
assertThat(listener.hasFiredSinceLastCheck()).isFalse();
}
@Test(expected = IllegalStateException.class)
public void processEventsCountsInvocationsEvenWhenAnExceptionIsThrown() {
CrudRepository<?, ?> mockRepository = mock(CrudRepository.class);
RepositoryAsyncEventListener<?, ?> listener = spy(new RepositoryAsyncEventListener<>(mockRepository));
doThrow(new IllegalStateException("TEST")).when(listener).doProcessEvents(any());
assertThat(listener).isNotNull();
assertThat(listener.getFiredCount()).isZero();
assertThat(listener.hasFired()).isFalse();
assertThat(listener.hasFiredSinceLastCheck()).isFalse();
try {
listener.processEvents(Collections.singletonList(mock(AsyncEvent.class)));
}
catch (IllegalStateException expected) {
assertThat(expected).hasMessage("TEST");
assertThat(expected).hasNoCause();
throw expected;
}
finally {
assertThat(listener.getFiredCount()).isOne();
assertThat(listener.hasFired()).isTrue();
assertThat(listener.hasFiredSinceLastCheck()).isTrue();
assertThat(listener.getFiredCount()).isOne();
assertThat(listener.hasFired()).isTrue();
assertThat(listener.hasFiredSinceLastCheck()).isFalse();
}
}
@Test
public void constructAsyncEventError() {