Add metadata and state to track the RepositoryAsyncEventListener.processEvents(:List<AsyncEvent>) method invocations.

Specifically, the listener state will track:

* The number of processEvents(:List<AsyncEvent>) method invocations.
* Whether the processEvents(..) method has ever been invoked.
* And, whether the processEvents(..) method has been invoked since the last check.

Introduces a protected doProcessEvents(:List<AsyncEvent>) method and changes processEvents(:List<AsyncEvent>) method to final.
This commit is contained in:
John Blum
2020-12-01 16:09:43 -08:00
parent c25100ebe7
commit cccadf68aa
2 changed files with 88 additions and 2 deletions

View File

@@ -385,6 +385,41 @@ public class RepositoryAsyncEventListenerUnitTests {
verifyNoInteractions(mockRepository);
}
@Test
public void processEventsCountsInvocations() {
CrudRepository<?, ?> mockRepository = mock(CrudRepository.class);
RepositoryAsyncEventListener<?, ?> listener = spy(new RepositoryAsyncEventListener<>(mockRepository));
doReturn(true).when(listener).doProcessEvents(any());
assertThat(listener).isNotNull();
assertThat(listener.getRepository()).isEqualTo(mockRepository);
assertThat(listener.getFiredCount()).isZero();
assertThat(listener.hasFired()).isFalse();
assertThat(listener.hasFiredSinceLastCheck()).isFalse();
listener.processEvents(Collections.emptyList());
assertThat(listener.getFiredCount()).isOne();
assertThat(listener.hasFired()).isTrue();
assertThat(listener.hasFiredSinceLastCheck()).isTrue();
assertThat(listener.getFiredCount()).isOne();
assertThat(listener.hasFired()).isTrue();
assertThat(listener.hasFiredSinceLastCheck()).isFalse();
listener.processEvents(Collections.singletonList(mock(AsyncEvent.class)));
listener.processEvents(Collections.emptyList());
assertThat(listener.getFiredCount()).isEqualTo(3);
assertThat(listener.hasFired()).isTrue();
assertThat(listener.hasFiredSinceLastCheck()).isTrue();
assertThat(listener.getFiredCount()).isEqualTo(3);
assertThat(listener.hasFired()).isTrue();
assertThat(listener.hasFiredSinceLastCheck()).isFalse();
}
@Test
public void constructAsyncEventError() {