Search in sources :

Example 6 with EntityIdVersionAndEventIds

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

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

Example 8 with EntityIdVersionAndEventIds

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

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

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