Search in sources :

Example 6 with PublishedEvent

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

the class AbstractCdcTest method waitForEvent.

public PublishedEvent waitForEvent(BlockingQueue<PublishedEvent> publishedEvents, Int128 eventId, LocalDateTime deadline, String eventData) throws InterruptedException {
    while (LocalDateTime.now().isBefore(deadline)) {
        long millis = ChronoUnit.MILLIS.between(deadline, LocalDateTime.now());
        PublishedEvent event = publishedEvents.poll(millis, TimeUnit.MILLISECONDS);
        if (event != null && event.getId().equals(eventId.asString()) && eventData.equals(event.getEventData()))
            return event;
    }
    throw new RuntimeException("event not found: " + eventId);
}
Also used : PublishedEvent(io.eventuate.local.common.PublishedEvent)

Example 7 with PublishedEvent

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

the class CdcKafkaPublisherTest method shouldSendPublishedEventsToKafka.

@Test
public void shouldSendPublishedEventsToKafka() throws InterruptedException {
    CdcKafkaPublisher<PublishedEvent> cdcKafkaPublisher = createCdcKafkaPublisher();
    cdcKafkaPublisher.start();
    cdcProcessor.start(cdcKafkaPublisher::handleEvent);
    String accountCreatedEventData = generateAccountCreatedEvent();
    EntityIdVersionAndEventIds entityIdVersionAndEventIds = saveEvent(localAggregateCrud, accountCreatedEventData);
    KafkaConsumer<String, String> consumer = createConsumer(eventuateKafkaConfigurationProperties.getBootstrapServers());
    consumer.partitionsFor(getEventTopicName());
    consumer.subscribe(Collections.singletonList(getEventTopicName()));
    waitForEventInKafka(consumer, entityIdVersionAndEventIds.getEntityId(), LocalDateTime.now().plusSeconds(40));
    cdcKafkaPublisher.stop();
}
Also used : EntityIdVersionAndEventIds(io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds) PublishedEvent(io.eventuate.local.common.PublishedEvent) Test(org.junit.Test)

Example 8 with PublishedEvent

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

the class CdcProcessorTest method shouldReadUnprocessedEventsAfterStartup.

@Test
public void shouldReadUnprocessedEventsAfterStartup() throws InterruptedException {
    BlockingQueue<PublishedEvent> publishedEvents = new LinkedBlockingDeque<>();
    String accountCreatedEventData = generateAccountCreatedEvent();
    EntityIdVersionAndEventIds entityIdVersionAndEventIds = saveEvent(localAggregateCrud, accountCreatedEventData);
    CdcProcessor<PublishedEvent> cdcProcessor = createCdcProcessor();
    cdcProcessor.start(publishedEvents::add);
    waitForEvent(publishedEvents, entityIdVersionAndEventIds.getEntityVersion(), LocalDateTime.now().plusSeconds(20), accountCreatedEventData);
    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)

Example 9 with PublishedEvent

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

the class AbstractMySqlBinlogCdcIntegrationTest method shouldGetEvents.

@Test
public void shouldGetEvents() throws InterruptedException {
    JdbcUrl jdbcUrl = JdbcUrlParser.parse(dataSourceURL);
    MySqlBinaryLogClient<PublishedEvent> mySqlBinaryLogClient = new MySqlBinaryLogClient<>(eventDataParser, eventuateConfigurationProperties.getDbUserName(), eventuateConfigurationProperties.getDbPassword(), jdbcUrl.getHost(), jdbcUrl.getPort(), eventuateConfigurationProperties.getBinlogClientId(), sourceTableNameSupplier.getSourceTableName(), eventuateConfigurationProperties.getMySqlBinLogClientName(), eventuateConfigurationProperties.getBinlogConnectionTimeoutInMilliseconds(), eventuateConfigurationProperties.getMaxAttemptsForBinlogConnection());
    EventuateLocalAggregateCrud localAggregateCrud = new EventuateLocalAggregateCrud(eventuateJdbcAccess);
    BlockingQueue<PublishedEvent> publishedEvents = new LinkedBlockingDeque<>();
    mySqlBinaryLogClient.start(Optional.empty(), publishedEvents::add);
    String accountCreatedEventData = generateAccountCreatedEvent();
    EntityIdVersionAndEventIds saveResult = saveEvent(localAggregateCrud, accountCreatedEventData);
    String accountDebitedEventData = generateAccountDebitedEvent();
    EntityIdVersionAndEventIds updateResult = updateEvent(saveResult.getEntityId(), saveResult.getEntityVersion(), localAggregateCrud, accountDebitedEventData);
    // Wait for 10 seconds
    LocalDateTime deadline = LocalDateTime.now().plusSeconds(10);
    waitForEvent(publishedEvents, saveResult.getEntityVersion(), deadline, accountCreatedEventData);
    waitForEvent(publishedEvents, updateResult.getEntityVersion(), deadline, accountDebitedEventData);
    mySqlBinaryLogClient.stop();
}
Also used : EntityIdVersionAndEventIds(io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds) LocalDateTime(java.time.LocalDateTime) JdbcUrl(io.eventuate.local.common.JdbcUrl) EventuateLocalAggregateCrud(io.eventuate.local.java.jdbckafkastore.EventuateLocalAggregateCrud) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) PublishedEvent(io.eventuate.local.common.PublishedEvent) Test(org.junit.Test) AbstractCdcTest(io.eventuate.local.test.util.AbstractCdcTest)

Example 10 with PublishedEvent

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

the class CdcProcessorTest method waitForEventExcluding.

private PublishedEvent waitForEventExcluding(BlockingQueue<PublishedEvent> publishedEvents, Int128 eventId, LocalDateTime deadline, String eventData, List<String> excludedIds) throws InterruptedException {
    PublishedEvent result = null;
    while (LocalDateTime.now().isBefore(deadline)) {
        long millis = ChronoUnit.MILLIS.between(deadline, LocalDateTime.now());
        PublishedEvent event = publishedEvents.poll(millis, TimeUnit.MILLISECONDS);
        if (event != null) {
            if (event.getId().equals(eventId.asString()) && eventData.equals(event.getEventData()))
                result = event;
            if (excludedIds.contains(event.getId()))
                throw new RuntimeException("Wrong event found in the queue");
        }
    }
    if (result != null)
        return result;
    throw new RuntimeException("event not found: " + eventId);
}
Also used : PublishedEvent(io.eventuate.local.common.PublishedEvent)

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