Esempio n. 1
0
  @Test // USERGRID-1401
  public void groupQueriesWithConsistentResults() {

    CustomCollection groups = context.application().collection("groups");

    int maxRangeLimit = 20;
    JsonNode[] saved = new JsonNode[maxRangeLimit];

    Map<String, String> actor = hashMap("displayName", "Erin");
    Map<String, Object> props = new HashMap<String, Object>();

    props.put("actor", actor);
    Map<String, Integer> location = hashMap("latitude", 37);
    location.put("longitude", -75);
    props.put("location", location);
    props.put("verb", "go");
    props.put("content", "bragh");

    for (int i = 0; i < 20; i++) {
      String newPath = String.format("/kero" + i);
      props.put("path", newPath);
      props.put("ordinal", i);
      JsonNode activity = groups.create(props).get("entities").get(0);
      saved[i] = activity;
    }

    JsonNode node = null;
    for (int consistent = 0; consistent < 20; consistent++) {
      String query =
          String.format(
              "select * where location within 100 of 37, -75 and ordinal >= %d and ordinal < %d",
              saved[7].get("ordinal").asLong(), saved[10].get("ordinal").asLong());

      node = groups.withQuery(query).get(); // groups.query(query);

      JsonNode entities = node.get("entities");

      assertEquals(3, entities.size());

      for (int i = 0; i < 3; i++) {
        // shouldn't start at 10 since you're excluding it above in the query, it should return
        // 9,8,7
        assertEquals(saved[7 + i], entities.get(i));
      }
    }
  }
Esempio n. 2
0
  @Test // ("Test uses up to many resources to run reliably") // USERGRID-1403
  public void groupQueriesWithGeoPaging() {

    CustomCollection groups = context.application().collection("groups");

    int maxRangeLimit = 2000;
    long[] index = new long[maxRangeLimit];
    Map actor = hashMap("displayName", "Erin");

    Map props = new HashMap();

    props.put("actor", actor);
    Map location = hashMap("latitude", 37);
    location.put("longitude", -75);
    props.put("location", location);
    props.put("verb", "go");
    props.put("content", "bragh");

    for (int i = 0; i < 5; i++) {
      String newPath = String.format("/kero" + i);
      props.put("path", newPath);
      props.put("ordinal", i);
      JsonNode activity = groups.create(props);
      index[i] = activity.findValue("created").getLongValue();
    }

    String query =
        "select * where location within 20000 of 37,-75 and created > "
            + index[2]
            + " and "
            + "created < "
            + index[4]
            + "";
    JsonNode node = groups.withQuery(query).get();
    assertEquals(1, node.get("entities").size());

    assertEquals(index[3], node.get("entities").get(0).get("created").getLongValue());
  }
  @Test
  public void transactionTimeout() throws InterruptedException {

    Queue queue = context.application().queues().queue("test");

    final int count = 2;

    for (int i = 0; i < count; i++) {
      queue.post(MapUtils.hashMap("id", i));
    }

    // now consume and make sure we get each message. We should receive each
    // message, and we'll use this for comparing results later
    final long timeout = 5000;

    queue = queue.withTimeout(timeout);

    TransactionResponseHandler transHandler = new TransactionResponseHandler(count);

    testMessages(queue, transHandler, new NoLastCommand());

    long start = System.currentTimeMillis();

    transHandler.assertResults();

    List<String> originalMessageIds = transHandler.getMessageIds();
    BiMap<String, String> transactionInfo = transHandler.getTransactionToMessageId();

    // now read again, we shouldn't have any results because our timeout hasn't
    // lapsed
    IncrementHandler incrementHandler = new IncrementHandler(0);

    testMessages(queue, incrementHandler, new NoLastCommand());

    incrementHandler.assertResults();

    // now sleep until our timeout expires
    Thread.sleep(timeout - (System.currentTimeMillis() - start));

    // now re-read our messages, we should get them all again
    transHandler = new TransactionResponseHandler(count);

    testMessages(queue, transHandler, new NoLastCommand());

    start = System.currentTimeMillis();

    transHandler.assertResults();

    List<String> returned = transHandler.getMessageIds();

    assertTrue(returned.size() > 0);

    // compare the replayed messages and the make sure they're in the same order
    BiMap<String, String> newTransactions = transHandler.getTransactionToMessageId();

    for (int i = 0; i < originalMessageIds.size(); i++) {
      // check the messages come back in the same order, they should
      assertEquals(originalMessageIds.get(i), returned.get(i));

      assertNotNull(transactionInfo.get(originalMessageIds.get(i)));
    }

    // sleep again before testing a second timeout
    Thread.sleep(timeout - (System.currentTimeMillis() - start));
    // now re-read our messages, we should get them all again
    transHandler = new TransactionResponseHandler(count);

    testMessages(queue, transHandler, new NoLastCommand());

    start = System.currentTimeMillis();

    transHandler.assertResults();

    returned = transHandler.getMessageIds();

    assertTrue(returned.size() > 0);

    // compare the replayed messages and the make sure they're in the same order
    newTransactions = transHandler.getTransactionToMessageId();

    for (int i = 0; i < originalMessageIds.size(); i++) {
      // check the messages come back in the same order, they should
      assertEquals(originalMessageIds.get(i), returned.get(i));

      assertNotNull(transactionInfo.get(originalMessageIds.get(i)));

      // ack the transaction we were returned
      Transaction transaction =
          queue.transactions().transaction(newTransactions.get(originalMessageIds.get(i)));
      transaction.delete();
    }

    // now sleep again we shouldn't have any messages since we acked all the
    // transactions
    Thread.sleep(timeout - (System.currentTimeMillis() - start));

    incrementHandler = new IncrementHandler(0);

    testMessages(queue, incrementHandler, new NoLastCommand());

    incrementHandler.assertResults();
  }