Exemplo 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);
 }
Exemplo 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);
  }
Exemplo n.º 3
0
 @BeforeClass
 public static void startTestServer()
     throws ObjectGridException, FileNotFoundException, IOException, URISyntaxException {
   utils = WXSUtils.getDefaultUtils();
   client = utils.getObjectGrid();
   skuMap = utils.getCache(TestMapNames.skuMap);
   asManager = new AsyncServiceManagerImpl(utils);
 }
Exemplo n.º 4
0
  /**
   * This method searches across multiple indexes and combines the answers. Create the business
   * object and only initialize the attributes you want to actually use in the query. You can AND or
   * OR all these attributes.
   *
   * @param criteria A business object with only attributes in the query set. Others must be null
   * @param isAND TRUE if results are to be ANDed otherwise the results are ORed
   * @return The list of keys for the matching entries @See TestSubstringIndex
   */
  public SearchResult<RK> searchMultipleIndexes(A criteria, boolean isAND) {
    try {
      Set<ByteArrayKey> result = null;
      // first run the individual queries for each attribute in parallel
      Collection<Future<SearchResult<byte[]>>> threads =
          new ArrayList<Future<SearchResult<byte[]>>>();
      for (Field f : indexedFields) {
        final String value = (String) f.get(criteria); // non null field means it's in the query
        if (value != null) {
          final Index<A, RK> index = getIndex(f.getName());

          Callable<SearchResult<byte[]>> c =
              new Callable<SearchResult<byte[]>>() {
                public SearchResult<byte[]> call() {
                  SearchResult<byte[]> r = index.rawContains(value);
                  return r;
                }
              };

          Future<SearchResult<byte[]>> future = utils.getExecutorService().submit(c);
          threads.add(future);
        }
      }
      // the collect the results and AND/OR them
      for (Future<SearchResult<byte[]>> future : threads) {
        SearchResult<byte[]> r = future.get();
        if (!r.isTooManyMatches()) {
          Collection<ByteArrayKey> rr = convertToKeys(r.getResults());
          if (result == null) result = new HashSet<ByteArrayKey>(rr);
          else if (isAND) {
            // AND this index match with the current running results
            LinkedList<ByteArrayKey> removeList = new LinkedList<ByteArrayKey>();
            for (ByteArrayKey k : rr) {
              if (!result.contains(k)) removeList.add(k);
            }
            for (ByteArrayKey k : result) {
              if (!rr.contains(k)) removeList.add(k);
            }
            result.removeAll(removeList);
          } else result.addAll(rr);
        }
      }
      if (result != null) {
        Map<ByteArrayKey, RK> rc =
            utils.getAll(result, utils.getObjectGrid().getMap(internalKeyToRealKeyMapName));
        return new SearchResult<RK>(new ArrayList<RK>(rc.values()));
      } else return new SearchResult<RK>();
    } catch (Exception e) {
      throw new ObjectGridRuntimeException(e);
    }
  }
Exemplo n.º 5
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());
  }
Exemplo n.º 6
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());
    }
  }