@Test public void testIfCommandIsDispatchedAndCorrelationIdIsNotNull() { CommandMessage<Object> command = new GenericCommandMessage<>(new Object()); gateway.sendAndWaitForEvent(command, mock(EventCallback.class), HIGH_TIMEOUT_IN_MILLIS); CorrelationToken correlationToken = verifyDispatchAndCaptureCorrelationToken(); assertTrue(correlationToken != null); }
public void sendAndWaitForEvent(Object command, final EventCallback callback, final long timeoutInMillis) { final CorrelationToken correlationToken = new CorrelationToken(); final TimedEventCallback timedEventCallback = new TimedEventCallback(callback); callbacks.put(correlationToken, timedEventCallback); timedEventCallback.scheduleTimer(new Runnable() { @Override public void run() { callbacks.remove(correlationToken); } }, timeoutInMillis); if (started.compareAndSet(false, true)) { eventBus.subscribe(new AnnotationEventListenerAdapter(this)); } final CommandMessage commandMessage = asCommandMessage(command) .andMetaData(Collections.singletonMap(CorrelationToken.KEY, correlationToken)); commandBus.dispatch(commandMessage); }
EventWaitingGateway { public void sendAndWaitForEvent(Object command, final EventCallback callback, final long timeoutInMillis) { final CorrelationToken correlationToken = new CorrelationToken(); final TimedEventCallback timedEventCallback = new TimedEventCallback(callback); callbacks.put(correlationToken, timedEventCallback); timedEventCallback.scheduleTimer(new Runnable() { @Override public void run() { callbacks.remove(correlationToken); } }, timeoutInMillis); if (started.compareAndSet(false, true)) { eventBus.subscribe(new AnnotationEventListenerAdapter(this)); } final CommandMessage commandMessage = asCommandMessage(command) .andMetaData(Collections.singletonMap(CorrelationToken.KEY, correlationToken)); commandBus.dispatch(commandMessage); } }
EventWaitingGateway { public void sendAndWaitForEvent(Object command, final EventCallback callback, final long timeoutInMillis) { final CorrelationToken correlationToken = new CorrelationToken(); final TimedEventCallback timedEventCallback = new TimedEventCallback(callback); callbacks.put(correlationToken, timedEventCallback); timedEventCallback.scheduleTimer(new Runnable() { @Override public void run() { callbacks.remove(correlationToken); } }, timeoutInMillis); if (started.compareAndSet(false, true)) { eventBus.subscribe(new AnnotationEventListenerAdapter(this)); } final CommandMessage commandMessage = asCommandMessage(command) .andMetaData(Collections.singletonMap(CorrelationToken.KEY, correlationToken)); commandBus.dispatch(commandMessage); }  }
EventWaitingGateway { public void sendAndWaitForEvent(Object command, final EventCallback callback, final long timeoutInMillis) { final CorrelationToken correlationToken = new CorrelationToken(); final TimedEventCallback timedEventCallback = new TimedEventCallback(callback); callbacks.put(correlationToken, timedEventCallback); timedEventCallback.scheduleTimer(new Runnable() { @Override public void run() { callbacks.remove(correlationToken); } }, timeoutInMillis); if (started.compareAndSet(false, true)) { eventBus.subscribe(new AnnotationEventListenerAdapter(this)); } final CommandMessage commandMessage = asCommandMessage(command) .andMetaData(Collections.singletonMap(CorrelationToken.KEY, correlationToken)); commandBus.dispatch(commandMessage); }  void sendAndWaitForEvent(Object command, final EventCallback callback, final long timeoutInMillis); void setEventBus(EventBus eventBus); void setCommandBus(CommandBus commandBus); }
EventWaitingGateway { public void sendAndWaitForEvent(Object command, final EventCallback callback, final long timeoutInMillis) { final CorrelationToken correlationToken = new CorrelationToken(); final TimedEventCallback timedEventCallback = new TimedEventCallback(callback); callbacks.put(correlationToken, timedEventCallback); timedEventCallback.scheduleTimer(new Runnable() { @Override public void run() { callbacks.remove(correlationToken); } }, timeoutInMillis); if (started.compareAndSet(false, true)) { eventBus.subscribe(new AnnotationEventListenerAdapter(this)); } final CommandMessage commandMessage = asCommandMessage(command) .andMetaData(Collections.singletonMap(CorrelationToken.KEY, correlationToken)); commandBus.dispatch(commandMessage); }  void sendAndWaitForEvent(Object command, final EventCallback callback, final long timeoutInMillis); void setEventBus(EventBus eventBus); void setCommandBus(CommandBus commandBus);  }