@Test public void executeAsyncInvalidPayload() { SerializedObject payload = SerializedObject.newBuilder() .setData(ByteString.copyFromUtf8("Some random string")) .setType(Command.class.getName()) .build(); CompletableFuture<Void> result = testSubject.executeAsync("context", payload); try { result.get(1, TimeUnit.SECONDS); fail("Should not succeed on non-event payload"); } catch (InterruptedException e) { Thread.currentThread().interrupt(); fail("Interrupted"); } catch (ExecutionException e) { } catch (TimeoutException e) { fail("Timeout waiting for result"); } }
@Override public CompletableFuture<Void> executeAsync(String context, Object payload) { CompletableFuture<Void> result = new CompletableFuture<>(); try { ScheduledEventWrapper scheduledEventWrapper = (ScheduledEventWrapper) payload; Event event = Event.newBuilder(Event.parseFrom(scheduledEventWrapper.getBytes())) .setTimestamp(System.currentTimeMillis()).build(); StreamObserver<InputStream> inputStream = localEventStore.createAppendEventConnection(scheduledEventWrapper .getContext(), new StreamObserver<Confirmation>() { @Override public void onNext( Confirmation confirmation) { result.complete( null); } @Override public void onError( Throwable throwable) { result.completeExceptionally( throwable); } @Override public void onCompleted() { } }); inputStream.onNext(new SerializedEvent(event).asInputStream()); inputStream.onCompleted(); } catch (Exception e) { result.completeExceptionally(e); } return result; }
ScheduledEventExecutor implements ScheduledTask { @Override public CompletableFuture<Void> executeAsync(String context, Object payload) { CompletableFuture<Void> result = new CompletableFuture<>(); try { ScheduledEventWrapper scheduledEventWrapper = (ScheduledEventWrapper) payload; Event event = Event.newBuilder(Event.parseFrom(scheduledEventWrapper.getBytes())) .setTimestamp(System.currentTimeMillis()).build(); StreamObserver<InputStream> inputStream = localEventStore.createAppendEventConnection(scheduledEventWrapper .getContext(), new StreamObserver<Confirmation>() { @Override public void onNext( Confirmation confirmation) { result.complete( null); } @Override public void onError( Throwable throwable) { result.completeExceptionally( throwable); } @Override public void onCompleted() { } }); inputStream.onNext(new SerializedEvent(event).asInputStream()); inputStream.onCompleted(); } catch (Exception e) { result.completeExceptionally(e); } return result; } }
ScheduledEventExecutor implements ScheduledTask { @Override public CompletableFuture<Void> executeAsync(String context, Object payload) { CompletableFuture<Void> result = new CompletableFuture<>(); try { ScheduledEventWrapper scheduledEventWrapper = (ScheduledEventWrapper) payload; Event event = Event.newBuilder(Event.parseFrom(scheduledEventWrapper.getBytes())) .setTimestamp(System.currentTimeMillis()).build(); StreamObserver<InputStream> inputStream = localEventStore.createAppendEventConnection(scheduledEventWrapper .getContext(), new StreamObserver<Confirmation>() { @Override public void onNext( Confirmation confirmation) { result.complete( null); } @Override public void onError( Throwable throwable) { result.completeExceptionally( throwable); } @Override public void onCompleted() { } }); inputStream.onNext(new SerializedEvent(event).asInputStream()); inputStream.onCompleted(); } catch (Exception e) { result.completeExceptionally(e); } return result; } ScheduledEventExecutor(LocalEventStore localEventStore); }
ScheduledEventExecutor implements ScheduledTask { @Override public CompletableFuture<Void> executeAsync(String context, Object payload) { CompletableFuture<Void> result = new CompletableFuture<>(); try { ScheduledEventWrapper scheduledEventWrapper = (ScheduledEventWrapper) payload; Event event = Event.newBuilder(Event.parseFrom(scheduledEventWrapper.getBytes())) .setTimestamp(System.currentTimeMillis()).build(); StreamObserver<InputStream> inputStream = localEventStore.createAppendEventConnection(scheduledEventWrapper .getContext(), new StreamObserver<Confirmation>() { @Override public void onNext( Confirmation confirmation) { result.complete( null); } @Override public void onError( Throwable throwable) { result.completeExceptionally( throwable); } @Override public void onCompleted() { } }); inputStream.onNext(new SerializedEvent(event).asInputStream()); inputStream.onCompleted(); } catch (Exception e) { result.completeExceptionally(e); } return result; } ScheduledEventExecutor(LocalEventStore localEventStore); @Override CompletableFuture<Void> executeAsync(String context, Object payload); }
ScheduledEventExecutor implements ScheduledTask { @Override public CompletableFuture<Void> executeAsync(String context, Object payload) { CompletableFuture<Void> result = new CompletableFuture<>(); try { ScheduledEventWrapper scheduledEventWrapper = (ScheduledEventWrapper) payload; Event event = Event.newBuilder(Event.parseFrom(scheduledEventWrapper.getBytes())) .setTimestamp(System.currentTimeMillis()).build(); StreamObserver<InputStream> inputStream = localEventStore.createAppendEventConnection(scheduledEventWrapper .getContext(), new StreamObserver<Confirmation>() { @Override public void onNext( Confirmation confirmation) { result.complete( null); } @Override public void onError( Throwable throwable) { result.completeExceptionally( throwable); } @Override public void onCompleted() { } }); inputStream.onNext(new SerializedEvent(event).asInputStream()); inputStream.onCompleted(); } catch (Exception e) { result.completeExceptionally(e); } return result; } ScheduledEventExecutor(LocalEventStore localEventStore); @Override CompletableFuture<Void> executeAsync(String context, Object payload);  }