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();
}
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));
}
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();
}
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();
}
Aggregations