@Override public String getId(PublishedEvent data) { return data.getId(); }
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); }
@Override public Optional<Long> getCreateTime(PublishedEvent publishedEvent) { return Optional.of(Int128.fromString(publishedEvent.getId()).getHi()); }
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; break; } if (excludedIds.contains(event.getId())) throw new RuntimeException("Event with excluded id found in the queue"); } } if (result != null) return result; throw new RuntimeException("event not found: " + eventId); } }
private SerializedEvent toSerializedEvent(ConsumerRecord<String, String> record) { PublishedEvent pe = JSonMapper.fromJson(record.value(), PublishedEvent.class); return new SerializedEvent( Int128.fromString(pe.getId()), pe.getEntityId(), pe.getEntityType(), pe.getEventData(), pe.getEventType(), record.partition(), record.offset(), EtopEventContext.make(pe.getId(), record.topic(), record.partition(), record.offset()), pe.getMetadata()); }
private SerializedEvent toSerializedEvent(ConsumerRecord<String, String> record) { PublishedEvent pe = JSonMapper.fromJson(record.value(), PublishedEvent.class); return new SerializedEvent( Int128.fromString(pe.getId()), pe.getEntityId(), pe.getEntityType(), pe.getEventData(), pe.getEventType(), record.partition(), record.offset(), EtopEventContext.make(pe.getId(), record.topic(), record.partition(), record.offset()), pe.getMetadata()); }
if (event != null) { System.out.println("Got: " + event); if (event.getId().equals(eventId.asString()) && eventData.equals(event.getEventData())) { foundEvent = true; } else if (event.getId().equals(otherSaveResult.getEntityIdVersionAndEventIds().getEventIds().get(0).asString())) { fail("Found event inserted into other schema");