Package org.akka.essentials.stm.transactor.example2

Examples of org.akka.essentials.stm.transactor.example2.BankTransactorTest


    @Test
    public void successTest() throws Exception {
        ActorRef bank = _system.actorOf(new Props(BankActor.class));
        bank.tell(new TransferMsg(Float.valueOf("1777")));

        AccountBalance balance = (AccountBalance) Await.result(
                ask(bank, new AccountBalance("XYZ"), 5000),
                Duration.create("5 second"));

        Assert.assertEquals(Float.parseFloat("3223"), balance.getBalance(),
                Float.parseFloat("0"));

        balance = (AccountBalance) Await.result(
                ask(bank, new AccountBalance("ABC"), 5000),
                Duration.create("5 second"));

        Assert.assertEquals(Float.parseFloat("2777"), balance.getBalance(),
                Float.parseFloat("0"));

    }
View Full Code Here


        bank.tell(new TransferMsg(Float.valueOf("5500")));

        // sleeping to allow some time for actors to be restarted
        Thread.sleep(4000);

        AccountBalance balance = (AccountBalance) Await.result(
                ask(bank, new AccountBalance("XYZ"), 5000),
                Duration.create("5 second"));

        Assert.assertEquals(Float.parseFloat("5000"), balance.getBalance(),
                Float.parseFloat("0"));

        balance = (AccountBalance) Await.result(
                ask(bank, new AccountBalance("ABC"), 5000),
                Duration.create("5 second"));

        Assert.assertEquals(Float.parseFloat("1000"), balance.getBalance(),
                Float.parseFloat("0"));

    }
View Full Code Here

        bank.tell(new AccountDebit(Float.parseFloat("3500")));

        // sleeping to allow some time for all messages to be processed
        Thread.sleep(4000);

        AccountBalance balance = (AccountBalance) Await.result(
                ask(bank, new AccountBalance("XYZ"), 5000),
                Duration.create("5 second"));

        Assert.assertEquals(Float.parseFloat("2000"), balance.getBalance(),
                Float.parseFloat("0"));

    }
View Full Code Here

  @Override
  public void onReceive(Object message) throws Exception {
    if (message instanceof TransferMsg) {
      transfer.tell(message);
    } else if (message instanceof AccountBalance) {
      AccountBalance account = (AccountBalance) Await.result(
          ask(transfer, message, 5000), Duration.create("5 second"));

      System.out.println("Account #" + account.getAccountNumber()
          + " , Balance " + account.getBalance());

      getSender().tell(account);
    } else if (message instanceof AccountMsg) {
      transfer.tell(message);
    }
View Full Code Here

              .getAmtToBeTransferred())));
        }
      });
    } else if (message instanceof AccountBalance) {

      AccountBalance accBalance = (AccountBalance) message;
      // check the account number and return the balance
      if (accBalance.getAccountNumber().equals(fromAccount)) {
        from.tell(accBalance, sender());
      }
      if (accBalance.getAccountNumber().equals(toAccount)) {
        to.tell(accBalance, sender());
      }
    }else if(message instanceof AccountMsg){
      from.tell(message);
    }
View Full Code Here

  // method.
  @Override
  public boolean normally(Object message) {
    if (message instanceof AccountBalance) {
      // reply with the account balance
      sender().tell(new AccountBalance(accountNumber, balance.get()));
      return true;
    }
    return false;
  }
View Full Code Here

  }

  private void showBalances() {
    try {
      Thread.sleep(2000);
      bank.tell(new AccountBalance("XYZ"));
      bank.tell(new AccountBalance("ABC"));

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here

    @Test
    public void accountTest() throws Exception {
        ActorRef bank = _system.actorOf(new Props(BankActor.class));

        bank.tell(new AccountDebit(Float.parseFloat("1000")));
        bank.tell(new AccountCredit(Float.parseFloat("1000")));
        bank.tell(new AccountDebit(Float.parseFloat("1000")));
        bank.tell(new AccountDebit(Float.parseFloat("1000")));
        bank.tell(new AccountDebit(Float.parseFloat("3500")));
        bank.tell(new AccountCredit(Float.parseFloat("2500")));
        bank.tell(new AccountDebit(Float.parseFloat("3500")));

        // sleeping to allow some time for all messages to be processed
        Thread.sleep(4000);
View Full Code Here

      final Coordinated coordinated = new Coordinated(timeout);

      coordinated.atomic(new Runnable() {
        public void run() {
          // credit amount - will always be successful
          to.tell(coordinated.coordinate(new AccountCredit(transfer
              .getAmtToBeTransferred())));
          // debit amount - throws an exception if funds insufficient
          from.tell(coordinated.coordinate(new AccountDebit(transfer
              .getAmtToBeTransferred())));
        }
View Full Code Here

        throw new IllegalStateException("Insufficient Balance");
      }

    } else if (message instanceof AccountCredit) {

      AccountCredit accCredit = (AccountCredit) message;
      float bal = balance.get() + accCredit.getAmount();
      balance.set(bal);

    }
  }
View Full Code Here

TOP

Related Classes of org.akka.essentials.stm.transactor.example2.BankTransactorTest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.