@Test
 public void testHandlerDispatching_WithReturnType() throws Throwable {
   Object actualReturnValue =
       testSubject.handle(GenericCommandMessage.asCommandMessage(1L), mockUnitOfWork);
   assertEquals(1L, actualReturnValue);
   assertEquals(0, mockTarget.voidHandlerInvoked);
   assertEquals(1, mockTarget.returningHandlerInvoked);
 }
 @Test
 public void testHandlerDispatching_ThrowingException() throws Throwable {
   try {
     testSubject.handle(GenericCommandMessage.asCommandMessage(new HashSet()), mockUnitOfWork);
     fail("Expected exception");
   } catch (Exception ex) {
     assertEquals(Exception.class, ex.getClass());
   }
 }
  public static void main(String[] args) {
    CommandBus cb = new SimpleCommandBus();

    InMemoryEventStore eventStore = new InMemoryEventStore();
    eventStore.appendInitialEvent(
        new SimpleDomainEventStream(
            new GenericDomainEventMessage<>(aggregateIdentifier.toString(), 0, new SomeEvent())));

    final MyAggregate myAggregate = new MyAggregate(aggregateIdentifier);
    Repository<MyAggregate> repository =
        new Repository<MyAggregate>() {
          @Override
          public MyAggregate load(String aggregateIdentifier, Long expectedVersion) {
            throw new UnsupportedOperationException("Not implemented yet");
          }

          @Override
          public MyAggregate load(String aggregateIdentifier) {
            return myAggregate;
          }

          @Override
          public void add(MyAggregate aggregate) {
            throw new UnsupportedOperationException("Not implemented yet");
          }
        };
    cb.subscribe(String.class.getName(), new MyCommandHandler(repository));
    //        new AnnotationCommandHandlerAdapter(new MyCommandHandler(repository), cb).subscribe();

    long COMMAND_COUNT = 5 * 1000 * 1000;
    cb.dispatch(GenericCommandMessage.asCommandMessage("ready,"));
    long t1 = System.currentTimeMillis();
    for (int t = 0; t < COMMAND_COUNT; t++) {
      cb.dispatch(GenericCommandMessage.asCommandMessage("go!"));
    }
    long t2 = System.currentTimeMillis();
    System.out.println(
        String.format("Just did %d commands per second", ((COMMAND_COUNT * 1000) / (t2 - t1))));
  }
  @SuppressWarnings({"unchecked"})
  @Test
  public void testEventHandlerCallsRedirectToAdapter() throws Throwable {
    Object result1 =
        testSubject.postProcessBeforeInitialization(new AnnotatedCommandHandler(), "beanName");
    Object postProcessedBean = testSubject.postProcessAfterInitialization(result1, "beanName");

    assertTrue(Enhancer.isEnhanced(postProcessedBean.getClass()));
    assertTrue(postProcessedBean instanceof CommandHandler);
    assertTrue(postProcessedBean instanceof AnnotatedCommandHandler);

    CommandHandler<MyCommand> commandHandler = (CommandHandler<MyCommand>) postProcessedBean;
    AnnotatedCommandHandler annotatedCommandHandler = (AnnotatedCommandHandler) postProcessedBean;
    CommandMessage<MyCommand> myCommand = GenericCommandMessage.asCommandMessage(new MyCommand());
    commandHandler.handle(myCommand, null);

    assertEquals(1, annotatedCommandHandler.getInvocationCount());
  }
Пример #5
0
  /** This test should make sure the problem described in issue #91 does not occur anymore */
  @Test
  public void testCallbackCalled() {
    SimpleCommandBus scb = new SimpleCommandBus();
    AnnotationCommandHandlerAdapter.subscribe(this, scb);

    scb.dispatch(
        GenericCommandMessage.asCommandMessage("Hello"),
        new VoidCallback() {
          @Override
          protected void onSuccess() {
            // what I expected
          }

          @Override
          public void onFailure(Throwable cause) {
            cause.printStackTrace();
            fail("Did not expect a failure");
          }
        });
  }
 @Test(expected = NoHandlerForCommandException.class)
 public void testHandle_NoHandlerForCommand() throws Throwable {
   testSubject.handle(GenericCommandMessage.asCommandMessage(new LinkedList()), null);
 }
 private <R> FutureCallback<R> doSend(Object command) {
   FutureCallback<R> futureCallback = new FutureCallback<R>();
   commandBus.dispatch(GenericCommandMessage.asCommandMessage(command), futureCallback);
   return futureCallback;
 }