FINERACT-2081: External event sending enhance findBy query
This commit is contained in:
+1
-1
@@ -83,7 +83,7 @@ public class SendAsynchronousEventsTasklet implements Tasklet {
|
||||
private List<ExternalEventView> getQueuedEventsBatch() {
|
||||
int readBatchSize = getBatchSize();
|
||||
Pageable batchSize = PageRequest.ofSize(readBatchSize);
|
||||
return measure(() -> repository.findByStatusOrderById(ExternalEventStatus.TO_BE_SENT, batchSize),
|
||||
return measure(() -> repository.findByStatusOrderByBusinessDateAscIdAsc(ExternalEventStatus.TO_BE_SENT, batchSize),
|
||||
(events, timeTaken) -> log.debug("Loaded {} events in {}ms", events.size(), timeTaken.toMillis()));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ import org.springframework.data.repository.query.Param;
|
||||
|
||||
public interface ExternalEventRepository extends JpaRepository<ExternalEvent, Long>, JpaSpecificationExecutor<ExternalEvent> {
|
||||
|
||||
List<ExternalEventView> findByStatusOrderById(ExternalEventStatus status, Pageable batchSize);
|
||||
List<ExternalEventView> findByStatusOrderByBusinessDateAscIdAsc(ExternalEventStatus status, Pageable batchSize);
|
||||
|
||||
@Modifying(flushAutomatically = true)
|
||||
@Query("delete from ExternalEvent e where e.status = :status and e.businessDate <= :dateForPurgeCriteria")
|
||||
|
||||
+6
-6
@@ -128,7 +128,7 @@ class SendAsynchronousEventsTaskletTest {
|
||||
MessageV1 dummyMessage = new MessageV1(1, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
|
||||
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
|
||||
|
||||
when(repository.findByStatusOrderById(Mockito.any(), Mockito.any())).thenReturn(events);
|
||||
when(repository.findByStatusOrderByBusinessDateAscIdAsc(Mockito.any(), Mockito.any())).thenReturn(events);
|
||||
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
|
||||
when(byteBufferConverter.convert(Mockito.any(ByteBuffer.class))).thenReturn(new byte[0]);
|
||||
// when
|
||||
@@ -147,7 +147,7 @@ class SendAsynchronousEventsTaskletTest {
|
||||
createExternalEventView("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey", 1L));
|
||||
MessageV1 dummyMessage = new MessageV1(1, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
|
||||
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
|
||||
when(repository.findByStatusOrderById(Mockito.any(), Mockito.any())).thenReturn(events);
|
||||
when(repository.findByStatusOrderByBusinessDateAscIdAsc(Mockito.any(), Mockito.any())).thenReturn(events);
|
||||
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
|
||||
when(byteBufferConverter.convert(Mockito.any(ByteBuffer.class))).thenReturn(new byte[0]);
|
||||
doThrow(new AcknowledgementTimeoutException("Event Send Exception", new RuntimeException())).when(eventProducer)
|
||||
@@ -166,7 +166,7 @@ class SendAsynchronousEventsTaskletTest {
|
||||
.asList(createExternalEventView("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey", 1L));
|
||||
MessageV1 dummyMessage = new MessageV1(1, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
|
||||
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
|
||||
when(repository.findByStatusOrderById(Mockito.any(), Mockito.any())).thenReturn(events);
|
||||
when(repository.findByStatusOrderByBusinessDateAscIdAsc(Mockito.any(), Mockito.any())).thenReturn(events);
|
||||
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
|
||||
when(byteBufferConverter.convert(Mockito.any(ByteBuffer.class))).thenReturn(new byte[0]);
|
||||
// when
|
||||
@@ -185,7 +185,7 @@ class SendAsynchronousEventsTaskletTest {
|
||||
.asList(createExternalEventView("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey", null));
|
||||
MessageV1 dummyMessage = new MessageV1(1, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
|
||||
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
|
||||
when(repository.findByStatusOrderById(Mockito.any(), Mockito.any())).thenReturn(events);
|
||||
when(repository.findByStatusOrderByBusinessDateAscIdAsc(Mockito.any(), Mockito.any())).thenReturn(events);
|
||||
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
|
||||
byte[] byteMsg = new byte[0];
|
||||
when(byteBufferConverter.convert(Mockito.any(ByteBuffer.class))).thenReturn(byteMsg);
|
||||
@@ -202,11 +202,11 @@ class SendAsynchronousEventsTaskletTest {
|
||||
public void givenEventBatchSizeIsConfiguredAs10WhenTaskExecutionThenEventReadPageSizeIsCorrect() {
|
||||
ArgumentCaptor<Pageable> externalEventPageSizeArgumentCaptor = ArgumentCaptor.forClass(Pageable.class);
|
||||
List<ExternalEventView> events = new ArrayList<>();
|
||||
when(repository.findByStatusOrderById(Mockito.any(), Mockito.any())).thenReturn(events);
|
||||
when(repository.findByStatusOrderByBusinessDateAscIdAsc(Mockito.any(), Mockito.any())).thenReturn(events);
|
||||
// when
|
||||
resultStatus = underTest.execute(stepContribution, chunkContext);
|
||||
// then
|
||||
verify(repository).findByStatusOrderById(Mockito.any(), externalEventPageSizeArgumentCaptor.capture());
|
||||
verify(repository).findByStatusOrderByBusinessDateAscIdAsc(Mockito.any(), externalEventPageSizeArgumentCaptor.capture());
|
||||
assertThat(externalEventPageSizeArgumentCaptor.getValue().getPageSize()).isEqualTo(10);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user