private CompletableFuture<String> subscribeAsync(String subscribeId) { return (CompletableFuture<String>) client.subscribe(subscribeId, Collections.singletonMap("MyEntityType", Collections.singleton("MyEvent")), null, se -> { ids.add(se.getId()); return CompletableFuture.completedFuture("x"); }); }
private void assertContainsEventWithMetadata(Int128 expectedEventId, String expectedMetadata, LinkedBlockingQueue<SerializedEvent> events) throws InterruptedException { long now = System.currentTimeMillis(); long deadline = now + 10 * 1000; while (System.currentTimeMillis() < deadline) { SerializedEvent event = events.poll(100, TimeUnit.MILLISECONDS); if (event != null && event.getId().equals(expectedEventId)) { assertEquals(Optional.of(expectedMetadata), event.getMetadata()); return; } } fail("could not find"); }
@Override public Optional<DispatchedEvent<Event>> toDispatchedEvent(SerializedEvent se) { String eventType = se.getEventType(); Class<Event> eventClass = toEventClass(eventType); Event event = JSonMapper.fromJson(se.getEventData(), eventClass); return Optional.of(new DispatchedEvent<>(se.getEntityId(), se.getId(), event, se.getSwimLane(), se.getOffset(), se.getEventContext(), se.getMetadata() == null ? Optional.empty() : se.getMetadata().map(md -> JSonMapper.fromJson(md, Map.class)))); }
@Override public Optional<DispatchedEvent<Event>> toDispatchedEvent(SerializedEvent se) { String eventType = se.getEventType(); Class<Event> eventClass = toEventClass(eventType); Event event = JSonMapper.fromJson(se.getEventData(), eventClass); return Optional.of(new DispatchedEvent<>(se.getEntityId(), se.getId(), event, se.getSwimLane(), se.getOffset(), se.getEventContext(), se.getMetadata() == null ? Optional.empty() : se.getMetadata().map(md -> JSonMapper.fromJson(md, Map.class)))); }