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