コード例 #1
0
ファイル: BasicTest.java プロジェクト: bnewport/Samples
  @Test
  public void testShoppingCartFiveItemsOutOfStock() throws Exception {
    initializeTest();

    Map<String, KeyOperator<String>> cartCommand = new HashMap<String, KeyOperator<String>>();
    for (int sku = 0; sku < 5; ++sku) {
      ShoppingCartWorker worker1 = new ShoppingCartWorker();
      worker1.quantity = 1;
      cartCommand.put(Integer.toString(sku), worker1);
    }
    Session session = utils.getObjectGrid().getSession();
    Future<Map<String, KeyOperatorResult<String>>> rc =
        asManager.doChainedTransaction(session, TestMapNames.skuMap, cartCommand);
    while (!rc.isDone()) {
      Thread.sleep(1000);
    }

    Map<String, KeyOperatorResult<String>> results = rc.get();
    // 1 false/false, size - 1 true/true
    boolean failedApplied = false;
    int unapplied = 0;
    for (KeyOperatorResult<String> r : results.values()) {
      if (!r.isApplied() && !r.isUnapplied()) {
        failedApplied = true;
      } else if (r.isApplied() && r.isUnapplied()) {
        unapplied++;
      }
    }

    Assert.assertTrue(failedApplied);
    Assert.assertEquals(results.size() - 1, unapplied);
  }
コード例 #2
0
ファイル: BasicTest.java プロジェクト: bnewport/Samples
  @Test
  public void testShoppingCartOneItemOutOfStock() throws Exception {
    initializeTest();
    ShoppingCartWorker worker1 = new ShoppingCartWorker();
    worker1.quantity = 1;

    Map<String, KeyOperator<String>> cartCommand = new HashMap<String, KeyOperator<String>>();
    cartCommand.put("0", worker1);
    Session session = utils.getObjectGrid().getSession();
    Future<Map<String, KeyOperatorResult<String>>> rc =
        asManager.doChainedTransaction(session, TestMapNames.skuMap, cartCommand);

    while (!rc.isDone()) {
      Thread.sleep(1000);
    }

    Map<String, KeyOperatorResult<String>> results = rc.get();
    Assert.assertEquals(1, results.size());
    KeyOperatorResult<String> r = results.get("0");
    // apply returned false, unapply not executed
    Assert.assertFalse(r.isApplied());
    Assert.assertFalse(r.isUnapplied());
  }
コード例 #3
0
ファイル: BasicTest.java プロジェクト: bnewport/Samples
  @Test
  public void testShoppingCartFiveItems() throws Exception {
    initializeTest();

    Map<String, KeyOperator<String>> cartCommand = new HashMap<String, KeyOperator<String>>();
    for (int sku = 1; sku <= 5; ++sku) {
      ShoppingCartWorker worker1 = new ShoppingCartWorker();
      worker1.quantity = 1;
      cartCommand.put(Integer.toString(sku), worker1);
    }
    Session session = utils.getObjectGrid().getSession();
    Future<Map<String, KeyOperatorResult<String>>> rc =
        asManager.doChainedTransaction(session, TestMapNames.skuMap, cartCommand);
    while (!rc.isDone()) {
      Thread.sleep(1000);
    }

    Map<String, KeyOperatorResult<String>> results = rc.get();
    Assert.assertEquals(5, results.size());
    for (KeyOperatorResult<String> r : results.values()) {
      Assert.assertFalse(r.isUnapplied());
      Assert.assertTrue(r.isApplied());
    }
  }