Esempio n. 1
0
 public void testPerformanceSingleThread() throws ObjectGridException, InterruptedException {
   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();
   long start = System.currentTimeMillis();
   ArrayList<Future<Map<String, KeyOperatorResult<String>>>> futures =
       new ArrayList<Future<Map<String, KeyOperatorResult<String>>>>();
   int maxChains = 1;
   for (int i = 0; i < maxChains; ++i) {
     Future<Map<String, KeyOperatorResult<String>>> rc =
         asManager.doChainedTransaction(session, TestMapNames.skuMap, cartCommand);
     futures.add(rc);
   }
   long phase1 = System.currentTimeMillis();
   System.out.println("Waiting");
   for (int i = 0; i < maxChains; ++i) {
     Future<Map<String, KeyOperatorResult<String>>> rc = futures.get(i);
     while (!rc.isDone()) {
       Thread.sleep(1);
     }
   }
   long phase2 = System.currentTimeMillis();
   double rate = maxChains / ((phase1 - start) / 1000.0);
   System.out.println("Phase 1 is " + rate);
   rate = maxChains / ((phase2 - start) / 1000.0);
   System.out.println("Phase 2 is " + rate);
 }
Esempio n. 2
0
  @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);
  }
Esempio n. 3
0
  @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());
  }
Esempio n. 4
0
  @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());
    }
  }