Search in sources :

Example 1 with EventTypeAndData

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

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

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

the class AbstractTopicRelayTest method shouldCaptureAndPublishChange.

@Test
public void shouldCaptureAndPublishChange() throws ExecutionException, InterruptedException {
    String aggregateType = "TestAggregate";
    String eventType = "TestEvent";
    List<EventTypeAndData> myEvents = Collections.singletonList(new EventTypeAndData(eventType, "{}", Optional.empty()));
    long publishTime = System.currentTimeMillis();
    EntityIdVersionAndEventIds ewidv = AsyncUtil.await(eventuateJdbcEventStore.save(aggregateType, myEvents, Optional.empty()));
    Int128 expectedEventId = ewidv.getEntityVersion();
    BlockingQueue<Int128> result = new LinkedBlockingDeque<>();
    logger.debug("Looking for eventId {}", expectedEventId);
    eventuateKafkaAggregateSubscriptions.subscribe("testSubscriber-" + getClass().getName(), Collections.singletonMap(aggregateType, Collections.singleton(eventType)), SubscriberOptions.DEFAULTS, se -> {
        logger.debug("got se {}", se);
        if (se.getId().equals(expectedEventId))
            result.add(se.getId());
        return CompletableFuture.completedFuture(null);
    }).get();
    Assert.assertNotNull("Failed to find eventId: " + expectedEventId, result.poll(30, TimeUnit.SECONDS));
    Assert.assertNull(result.poll(30, TimeUnit.SECONDS));
    long endTime = System.currentTimeMillis();
    logger.debug("got the event I just published in msecs {}", endTime - publishTime);
// eventTableChangesToAggregateTopicRelay.stopCapturingChanges();
}
Also used : EntityIdVersionAndEventIds(io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds) AggregateCrud(io.eventuate.javaclient.commonimpl.AggregateCrud) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) BlockingQueue(java.util.concurrent.BlockingQueue) CompletableFuture(java.util.concurrent.CompletableFuture) Int128(io.eventuate.Int128) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) Optional(java.util.Optional) EventTypeAndData(io.eventuate.javaclient.commonimpl.EventTypeAndData) SubscriberOptions(io.eventuate.SubscriberOptions) EntityIdVersionAndEventIds(io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds) org.junit(org.junit) EventuateKafkaAggregateSubscriptions(io.eventuate.local.java.jdbckafkastore.EventuateKafkaAggregateSubscriptions) Collections(java.util.Collections) AsyncUtil(io.eventuate.testutil.AsyncUtil) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) EventTypeAndData(io.eventuate.javaclient.commonimpl.EventTypeAndData) Int128(io.eventuate.Int128)

Example 4 with EventTypeAndData

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

the class PrepareMigrationToNewCdcTest method shouldCaptureAndPublishChange.

@Test
public void shouldCaptureAndPublishChange() throws ExecutionException, InterruptedException {
    String aggregateType = "TestAggregate_MIGRATION";
    String eventType = "TestEvent_MIGRATION";
    List<EventTypeAndData> myEvents = Collections.singletonList(new EventTypeAndData(eventType, "{}", Optional.empty()));
    EntityIdVersionAndEventIds ewidv = AsyncUtil.await(eventuateJdbcEventStore.save(aggregateType, myEvents, Optional.empty()));
    Int128 expectedEventId = ewidv.getEntityVersion();
    BlockingQueue<Int128> result = new LinkedBlockingDeque<>();
    eventuateKafkaAggregateSubscriptions.subscribe("testSubscriber", Collections.singletonMap(aggregateType, Collections.singleton(eventType)), SubscriberOptions.DEFAULTS, se -> {
        logger.debug("got se {}", se);
        if (se.getId().equals(expectedEventId))
            result.add(se.getId());
        return CompletableFuture.completedFuture(null);
    }).get();
    Assert.assertNotNull(result.poll(30, TimeUnit.SECONDS));
}
Also used : EntityIdVersionAndEventIds(io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds) DirtiesContext(org.springframework.test.annotation.DirtiesContext) AggregateCrud(io.eventuate.javaclient.commonimpl.AggregateCrud) Logger(org.slf4j.Logger) EnableAutoConfiguration(org.springframework.boot.autoconfigure.EnableAutoConfiguration) java.util.concurrent(java.util.concurrent) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Import(org.springframework.context.annotation.Import) Test(org.junit.Test) Int128(io.eventuate.Int128) List(java.util.List) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) EventuateLocalConfiguration(io.eventuate.local.java.jdbckafkastore.EventuateLocalConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Optional(java.util.Optional) EventTypeAndData(io.eventuate.javaclient.commonimpl.EventTypeAndData) SubscriberOptions(io.eventuate.SubscriberOptions) EntityIdVersionAndEventIds(io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds) EventuateKafkaAggregateSubscriptions(io.eventuate.local.java.jdbckafkastore.EventuateKafkaAggregateSubscriptions) Assert(org.junit.Assert) Collections(java.util.Collections) AsyncUtil(io.eventuate.testutil.AsyncUtil) EventTypeAndData(io.eventuate.javaclient.commonimpl.EventTypeAndData) Int128(io.eventuate.Int128) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

EntityIdVersionAndEventIds (io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds)4 EventTypeAndData (io.eventuate.javaclient.commonimpl.EventTypeAndData)4 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)3 Test (org.junit.Test)3 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 EventuateLocalAggregateCrud (io.eventuate.local.java.jdbckafkastore.EventuateLocalAggregateCrud)2 AbstractCdcTest (io.eventuate.local.test.util.AbstractCdcTest)2 AsyncUtil (io.eventuate.testutil.AsyncUtil)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 PublishedEvent (io.eventuate.local.common.PublishedEvent)1 EventuateLocalConfiguration (io.eventuate.local.java.jdbckafkastore.EventuateLocalConfiguration)1