Search in sources :

Example 1 with EntityIdVersionAndEventIds

use of io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds in project eventuate-local by eventuate-local.

the class MySQLClientNameTest method test.

@Test
public void test() throws Exception {
    databaseOffsetKafkaStore = createDatabaseOffsetKafkaStore(createMySqlBinaryLogClient());
    BlockingQueue<PublishedEvent> publishedEvents = new LinkedBlockingDeque<>();
    CdcProcessor<PublishedEvent> cdcProcessor = createMySQLCdcProcessor();
    cdcProcessor.start(publishedEvent -> {
        publishedEvents.add(publishedEvent);
        databaseOffsetKafkaStore.save(publishedEvent.getBinlogFileOffset());
    });
    EventuateLocalAggregateCrud localAggregateCrud = new EventuateLocalAggregateCrud(eventuateJdbcAccess);
    List<EventTypeAndData> events = Collections.singletonList(new EventTypeAndData("TestEvent", "{}", Optional.empty()));
    EntityIdVersionAndEventIds entityIdVersionAndEventIds = localAggregateCrud.save("TestAggregate", events, Optional.empty());
    PublishedEvent publishedEvent;
    while ((publishedEvent = publishedEvents.poll(10, TimeUnit.SECONDS)) != null) {
        if (entityIdVersionAndEventIds.getEntityVersion().asString().equals(publishedEvent.getId())) {
            break;
        }
    }
    Assert.assertEquals(entityIdVersionAndEventIds.getEntityVersion().asString(), publishedEvent.getId());
    cdcProcessor.stop();
    /*waiting while offset is storing in kafka*/
    Thread.sleep(10000);
    databaseOffsetKafkaStore = createDatabaseOffsetKafkaStore(createMySqlBinaryLogClient());
    cdcProcessor = createMySQLCdcProcessor();
    cdcProcessor.start(event -> {
        publishedEvents.add(event);
        databaseOffsetKafkaStore.save(event.getBinlogFileOffset());
    });
    while ((publishedEvent = publishedEvents.poll(10, TimeUnit.SECONDS)) != null) {
        Assert.assertNotEquals(entityIdVersionAndEventIds.getEntityVersion().asString(), publishedEvent.getId());
    }
}
Also used : EntityIdVersionAndEventIds(io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) EventuateLocalAggregateCrud(io.eventuate.local.java.jdbckafkastore.EventuateLocalAggregateCrud) EventTypeAndData(io.eventuate.javaclient.commonimpl.EventTypeAndData) Test(org.junit.Test) AbstractCdcTest(io.eventuate.local.test.util.AbstractCdcTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with EntityIdVersionAndEventIds

use of io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds in project eventuate-local by eventuate-local.

the class MySQLMigrationTest method test.

@Test
public void test() throws Exception {
    BlockingQueue<PublishedEvent> publishedEvents = new LinkedBlockingDeque<>();
    CdcProcessor<PublishedEvent> cdcProcessor = createMySQLCdcProcessor();
    cdcProcessor.start(publishedEvent -> {
        publishedEvents.add(publishedEvent);
        databaseOffsetKafkaStore.save(publishedEvent.getBinlogFileOffset());
    });
    EventuateLocalAggregateCrud localAggregateCrud = new EventuateLocalAggregateCrud(eventuateJdbcAccess);
    List<EventTypeAndData> events = Collections.singletonList(new EventTypeAndData("TestEvent_MIGRATION", "{}", Optional.empty()));
    EntityIdVersionAndEventIds entityIdVersionAndEventIds = localAggregateCrud.save("TestAggregate_MIGRATION", events, Optional.empty());
    PublishedEvent publishedEvent;
    while ((publishedEvent = publishedEvents.poll(10, TimeUnit.SECONDS)) != null) {
        if ("TestEvent_MIGRATION".equals(publishedEvent.getEventType())) {
            break;
        }
    }
    Assert.assertNotNull(publishedEvent);
    Assert.assertEquals(entityIdVersionAndEventIds.getEntityVersion().asString(), publishedEvent.getId());
}
Also used : EntityIdVersionAndEventIds(io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) EventuateLocalAggregateCrud(io.eventuate.local.java.jdbckafkastore.EventuateLocalAggregateCrud) EventTypeAndData(io.eventuate.javaclient.commonimpl.EventTypeAndData) PublishedEvent(io.eventuate.local.common.PublishedEvent) Test(org.junit.Test) AbstractCdcTest(io.eventuate.local.test.util.AbstractCdcTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with EntityIdVersionAndEventIds

use of io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds in project eventuate-local by eventuate-local.

the class AbstractPostgresWalCdcIntegrationTest method shouldGetEvents.

@Test
public void shouldGetEvents() throws InterruptedException {
    PostgresWalClient<PublishedEvent> postgresWalClient = new PostgresWalClient<>(postgresWalMessageParser, dataSourceURL, dbUserName, dbPassword, eventuateConfigurationProperties.getBinlogConnectionTimeoutInMilliseconds(), eventuateConfigurationProperties.getMaxAttemptsForBinlogConnection(), eventuateConfigurationProperties.getPostgresWalIntervalInMilliseconds(), eventuateConfigurationProperties.getPostgresReplicationStatusIntervalInMilliseconds(), eventuateConfigurationProperties.getPostgresReplicationSlotName());
    EventuateLocalAggregateCrud localAggregateCrud = new EventuateLocalAggregateCrud(eventuateJdbcAccess);
    BlockingQueue<PublishedEvent> publishedEvents = new LinkedBlockingDeque<>();
    postgresWalClient.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);
    postgresWalClient.stop();
}
Also used : EntityIdVersionAndEventIds(io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds) LocalDateTime(java.time.LocalDateTime) 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 4 with EntityIdVersionAndEventIds

use of io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds 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 5 with EntityIdVersionAndEventIds

use of io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds 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)

Aggregations

EntityIdVersionAndEventIds (io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds)9 Test (org.junit.Test)8 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)7 PublishedEvent (io.eventuate.local.common.PublishedEvent)6 EventTypeAndData (io.eventuate.javaclient.commonimpl.EventTypeAndData)4 EventuateLocalAggregateCrud (io.eventuate.local.java.jdbckafkastore.EventuateLocalAggregateCrud)4 AbstractCdcTest (io.eventuate.local.test.util.AbstractCdcTest)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Int128 (io.eventuate.Int128)2 SubscriberOptions (io.eventuate.SubscriberOptions)2 AggregateCrud (io.eventuate.javaclient.commonimpl.AggregateCrud)2 EventuateKafkaAggregateSubscriptions (io.eventuate.local.java.jdbckafkastore.EventuateKafkaAggregateSubscriptions)2 AsyncUtil (io.eventuate.testutil.AsyncUtil)2 LocalDateTime (java.time.LocalDateTime)2 Collections (java.util.Collections)2 List (java.util.List)2 Optional (java.util.Optional)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2