Search in sources :

Example 11 with PublishedEvent

use of io.eventuate.local.common.PublishedEvent in project eventuate-local by eventuate-local.

the class CdcProcessorTest method shouldReadNewEventsOnly.

@Test
public void shouldReadNewEventsOnly() throws InterruptedException {
    BlockingQueue<PublishedEvent> publishedEvents = new LinkedBlockingDeque<>();
    CdcProcessor<PublishedEvent> cdcProcessor = createCdcProcessor();
    cdcProcessor.start(publishedEvent -> {
        publishedEvents.add(publishedEvent);
        onEventSent(publishedEvent);
    });
    String accountCreatedEventData = generateAccountCreatedEvent();
    EntityIdVersionAndEventIds entityIdVersionAndEventIds = saveEvent(localAggregateCrud, accountCreatedEventData);
    waitForEvent(publishedEvents, entityIdVersionAndEventIds.getEntityVersion(), LocalDateTime.now().plusSeconds(10), accountCreatedEventData);
    cdcProcessor.stop();
    Thread.sleep(10000);
    publishedEvents.clear();
    cdcProcessor.start(publishedEvent -> {
        publishedEvents.add(publishedEvent);
        onEventSent(publishedEvent);
    });
    List<String> excludedIds = entityIdVersionAndEventIds.getEventIds().stream().map(Int128::asString).collect(Collectors.toList());
    accountCreatedEventData = generateAccountCreatedEvent();
    entityIdVersionAndEventIds = saveEvent(localAggregateCrud, accountCreatedEventData);
    waitForEventExcluding(publishedEvents, entityIdVersionAndEventIds.getEntityVersion(), LocalDateTime.now().plusSeconds(10), accountCreatedEventData, excludedIds);
    cdcProcessor.stop();
}
Also used : EntityIdVersionAndEventIds(io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) PublishedEvent(io.eventuate.local.common.PublishedEvent) Test(org.junit.Test)

Aggregations

PublishedEvent (io.eventuate.local.common.PublishedEvent)11 EntityIdVersionAndEventIds (io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds)6 Test (org.junit.Test)6 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)5 EventuateLocalAggregateCrud (io.eventuate.local.java.jdbckafkastore.EventuateLocalAggregateCrud)3 AbstractCdcTest (io.eventuate.local.test.util.AbstractCdcTest)3 LocalDateTime (java.time.LocalDateTime)2 EventTypeAndData (io.eventuate.javaclient.commonimpl.EventTypeAndData)1 BinlogFileOffset (io.eventuate.local.common.BinlogFileOffset)1 JdbcUrl (io.eventuate.local.common.JdbcUrl)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1