@Test
  public void testDisruptorCommandBusRepositoryNotAvailableOutsideOfInvokerThread() {
    DisruptorCommandBus commandBus = new DisruptorCommandBus(eventStore, eventBus);
    Repository<Aggregate> repository =
        commandBus.createRepository(new GenericAggregateFactory<Aggregate>(Aggregate.class));

    AggregateAnnotationCommandHandler<Aggregate> handler =
        new AggregateAnnotationCommandHandler<Aggregate>(Aggregate.class, repository);
    AggregateAnnotationCommandHandler.subscribe(handler, commandBus);
    DefaultCommandGateway gateway = new DefaultCommandGateway(commandBus);

    // Create the aggregate
    String aggregateId = "" + System.currentTimeMillis();
    gateway.sendAndWait(new CreateCommandAndEvent(aggregateId));

    // Load the aggretate from the repository -- from "worker" thread
    UnitOfWork uow = DefaultUnitOfWork.startAndGet();
    try {
      Aggregate aggregate = repository.load(aggregateId);
      fail("Expected IllegalStateException");
    } catch (IllegalStateException e) {
      assertTrue(e.getMessage().contains("DisruptorCommandBus"));
    } finally {
      uow.rollback();
    }
  }
Esempio n. 2
0
 @Test
 public void testEnsureNotNegative_InvalidCase() {
   IllegalStateException expected = null;
   try {
     DBQueries.ensureNotNegative(-1);
   } catch (IllegalStateException e) {
     expected = e;
   }
   assertNotNull(expected);
   assertEquals("Update returned error code: -1", expected.getMessage());
 }
 @Test
 public void should_fail_if_issue_is_not_resolved() throws Exception {
   Issue issue = new DefaultIssue().setEndOfLife(false);
   when(context.issue()).thenReturn(issue);
   try {
     function.execute(context);
     fail();
   } catch (IllegalStateException e) {
     assertThat(e.getMessage()).contains("Issue is still alive");
     verify(context, never()).setResolution(anyString());
   }
 }