예제 #1
0
  @Test
  public void userFirstNameSearch() throws Exception {
    UUID applicationId = createApplication("testOrganization", "testFirstName");
    assertNotNull(applicationId);

    EntityManager em = emf.getEntityManager(applicationId);
    assertNotNull(em);

    String firstName = "firstName" + UUIDUtils.newTimeUUID();

    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    properties.put("username", "edanuff");
    properties.put("email", "*****@*****.**");
    properties.put("firstname", firstName);

    Entity user = em.create("user", properties);
    assertNotNull(user);

    // EntityRef
    Query query = new Query();
    query.addEqualityFilter("firstname", firstName);

    Results r = em.searchCollection(em.getApplicationRef(), "users", query);

    assertTrue(r.size() > 0);

    Entity returned = r.getEntities().get(0);

    assertEquals(user.getUuid(), returned.getUuid());

    // update the username
    String newFirstName = "firstName" + UUIDUtils.newTimeUUID();

    user.setProperty("firstname", newFirstName);

    em.update(user);

    // search with the old username, should be no results
    query = new Query();
    query.addEqualityFilter("firstname", firstName);

    r = em.searchCollection(em.getApplicationRef(), "users", query);

    assertEquals(0, r.size());

    // search with the new username, should be results.

    query = new Query();
    query.addEqualityFilter("firstname", newFirstName);

    r = em.searchCollection(em.getApplicationRef(), "users", query);

    assertTrue(r.size() > 0);

    returned = r.getEntities().get(0);

    assertEquals(user.getUuid(), returned.getUuid());
  }
예제 #2
0
  @Test
  public void groupTitleSearch() throws Exception {
    UUID applicationId = createApplication("testOrganization", "groupTitleSearch");
    assertNotNull(applicationId);

    EntityManager em = emf.getEntityManager(applicationId);
    assertNotNull(em);

    String titleName = "groupName" + UUIDUtils.newTimeUUID();

    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    properties.put("title", titleName);
    properties.put("path", "testPath");
    properties.put("name", "testName");

    Entity group = em.create("group", properties);
    assertNotNull(group);

    // EntityRef
    Query query = new Query();
    query.addEqualityFilter("title", titleName);

    Results r = em.searchCollection(em.getApplicationRef(), "groups", query);

    assertTrue(r.size() > 0);

    Entity returned = r.getEntities().get(0);

    assertEquals(group.getUuid(), returned.getUuid());
  }
예제 #3
0
  @Test
  public void userLastNameSearch() throws Exception {
    UUID applicationId = createApplication("testOrganization", "testLastName");
    assertNotNull(applicationId);

    EntityManager em = emf.getEntityManager(applicationId);
    assertNotNull(em);

    String lastName = "lastName" + UUIDUtils.newTimeUUID();

    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    properties.put("username", "edanuff");
    properties.put("email", "*****@*****.**");
    properties.put("lastname", lastName);

    Entity user = em.create("user", properties);
    assertNotNull(user);

    // EntityRef
    Query query = new Query();
    query.addEqualityFilter("lastname", lastName);

    Results r = em.searchCollection(em.getApplicationRef(), "users", query);

    assertTrue(r.size() > 0);

    Entity returned = r.getEntities().get(0);

    assertEquals(user.getUuid(), returned.getUuid());
  }
예제 #4
0
  @Override
  public boolean hasMessagesInQueue(String queuePath, UUID consumerId) {

    Keyspace ko = cass.getApplicationKeyspace(applicationId);
    UUID queueId = CassandraMQUtils.getQueueId(queuePath);

    if (consumerId == null) {
      consumerId = queueId;
    }

    NoTransactionSearch search = new NoTransactionSearch(ko);

    QueueBounds bounds = search.getQueueBounds(queueId);

    // Queue doesn't exist
    if (bounds == null) {
      return false;
    }

    UUID consumerPosition = search.getConsumerQueuePosition(queueId, consumerId);

    // queue exists, but the consumer does not, meaning it's never read from the Q
    if (consumerPosition == null) {
      return true;
    }

    // check our consumer position against the newest message.  If it's equal or larger,
    // we're read to the end of the queue
    // note that this does not take transactions into consideration, just the client pointer
    // relative to the largest
    // message in the queue
    return UUIDUtils.compare(consumerPosition, bounds.getNewest()) < 0;
  }
예제 #5
0
  /**
   * Write the updated client pointer
   *
   * @param queueId
   * @param consumerId
   * @param lastReturnedId This is a null safe parameter. If it's null, this won't be written since
   *     it means we didn't read any messages
   */
  protected void writeClientPointer(UUID queueId, UUID consumerId, UUID lastReturnedId) {
    // nothing to do
    if (lastReturnedId == null) {
      return;
    }

    // we want to set the timestamp to the value from the time uuid. If this is
    // not the max time uuid to ever be written
    // for this consumer, we want this to be discarded to avoid internode race
    // conditions with clock drift.
    long colTimestamp = UUIDUtils.getTimestampInMicros(lastReturnedId);

    Mutator<UUID> mutator = createMutator(ko, ue);

    if (logger.isDebugEnabled()) {
      logger.debug(
          "Writing last client id pointer of '{}' for queue '{}' and consumer '{}' with timestamp '{}",
          new Object[] {lastReturnedId, queueId, consumerId, colTimestamp});
    }

    mutator.addInsertion(
        consumerId,
        CONSUMERS.getColumnFamily(),
        createColumn(queueId, lastReturnedId, colTimestamp, ue, ue));

    mutator.execute();
  }
예제 #6
0
  @Test
  public void emptyQueryReverse() throws Exception {
    UUID applicationId = createApplication("testOrganization", "testEmptyQueryReverse");
    assertNotNull(applicationId);

    EntityManager em = emf.getEntityManager(applicationId);
    assertNotNull(em);

    String firstName = "firstName" + UUIDUtils.newTimeUUID();

    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    properties.put("username", "edanuff");
    properties.put("email", "*****@*****.**");
    properties.put("firstname", firstName);

    Entity user = em.create("user", properties);
    assertNotNull(user);

    properties = new LinkedHashMap<String, Object>();
    properties.put("username", "djacobs");
    properties.put("email", "*****@*****.**");

    Entity user2 = em.create("user", properties);
    assertNotNull(user2);

    // EntityRef
    Query query = new Query();
    query.setReversed(true);

    Results r = em.searchCollection(em.getApplicationRef(), "users", query);

    assertEquals(2, r.size());

    Entity returned = r.getEntities().get(0);

    assertEquals(user2.getUuid(), returned.getUuid());

    returned = r.getEntities().get(1);

    assertEquals(user.getUuid(), returned.getUuid());
  }
예제 #7
0
 public TraceTag createMetered(String tagName) {
   return TraceTag.getMeteredInstance(UUIDUtils.newTimeUUID(), tagName);
 }