Example #1
0
  @Test
  public void failedTransaction2() throws ExecutionException, InterruptedException {
    Stage stage = createStage();
    Bank bank = Actor.getReference(Bank.class, "jimmy");
    Inventory inventory = Actor.getReference(Inventory.class, "jimmy");
    Store store = Actor.getReference(Store.class, "all");
    bank.increment(15).join();

    fakeSync.put("proceed", "ok");

    // this item is invalid but the bank balance is decreased first.
    store.buyItem(bank, inventory, "candy", 10).join();
    store.buyItem(bank, inventory, "chocolate", 1).join();
    try {
      store.buyItem(bank, inventory, "ice cream", 50).join();
      fail("expecting an exception");
    } catch (CompletionException ex) {
      System.out.println(ex.getCause().getMessage());
    }

    // the bank credits must be restored.
    eventually(() -> assertEquals((Integer) 4, bank.getBalance().join()));
    // no items were given
    eventually(() -> assertEquals(2, inventory.getItems().join().size()));
    dumpMessages();
  }
Example #2
0
  @Test
  public void failedTransaction() throws ExecutionException, InterruptedException {
    Stage stage = createStage();
    Bank bank = Actor.getReference(Bank.class, "jimmy");
    Inventory inventory = Actor.getReference(Inventory.class, "jimmy");
    Store store = Actor.getReference(Store.class, "all");
    bank.increment(15).join();

    fakeSync.put("proceed", "fail");

    // this item is invalid but the bank balance is decreased first.
    expectException(() -> store.buyItem(bank, inventory, "ice cream", 10).join());

    // the bank credits must be restored.
    eventually(() -> assertEquals((Integer) 15, bank.getBalance().join()));
    // no items were given
    assertEquals(0, inventory.getItems().join().size());
    dumpMessages();
  }