예제 #1
0
 // We never actually reindex posts currently, implement just for completeness
 @Override
 protected void doDelete(IndexReader reader, List<Object> ids) throws IOException {
   for (Object o : ids) {
     Guid guid = (Guid) o;
     Term term = new Term("id", guid.toString());
     reader.deleteDocuments(term);
   }
 }
예제 #2
0
  // Test grouping
  public void testGrouping() throws Exception {
    EntityManager em;

    TestViewpoint viewpoint = new TestViewpoint(Guid.createNew());

    /////////////////////////////////////////////////
    // Setup

    em = support.beginSessionRW(viewpoint);

    TestUser bob = new TestUser("Bob");
    Guid bobId = bob.getGuid();
    em.persist(bob);

    em.getTransaction().commit();

    /////////////////////////////////////////////////

    em = support.beginSessionRO(viewpoint);

    ReadOnlySession session = support.currentSessionRO();

    TestUserDMO bobDMO = session.find(TestUserDMO.class, bobId);

    assertEquals("initializedA", bobDMO.getGroupedA());
    assertEquals("initializedB", bobDMO.getGroupedB());

    em.getTransaction().commit();
  }
예제 #3
0
  // Test multi-valued properties and custom keys
  public void testMultiValued() throws Exception {
    EntityManager em;

    TestViewpoint viewpoint = new TestViewpoint(Guid.createNew());

    /////////////////////////////////////////////////
    // Setup

    em = support.beginSessionRW(viewpoint);

    TestUser bob = new TestUser("Bob");
    Guid bobId = bob.getGuid();
    em.persist(bob);

    TestUser jane = new TestUser("Jane");
    Guid janeId = jane.getGuid();
    em.persist(jane);

    TestGroup group = new TestGroup("BobAndJane");
    Guid groupId = group.getGuid();
    em.persist(group);

    TestGroupMember groupMember;

    groupMember = new TestGroupMember(group, bob);
    em.persist(groupMember);
    group.getMembers().add(groupMember);

    groupMember = new TestGroupMember(group, jane);
    em.persist(groupMember);
    group.getMembers().add(groupMember);

    em.getTransaction().commit();

    /////////////////////////////////////////////////

    em = support.beginSessionRO(viewpoint);

    // Check that the group looks OK read as DMO's from a new transaction.
    logger.debug("===== Checking the group in a new transaction ====\n");
    checkGroupValidity(groupId, bobId, janeId);

    // Check again with everything cached in the sesssion
    logger.debug("===== Checking the group again in the same transaction ====\n");
    checkGroupValidity(groupId, bobId, janeId);

    em.getTransaction().commit();

    em = support.beginSessionRO(viewpoint);

    // Now check once again in another new transaction to test reading
    // back from the global cache
    logger.debug("===== Checking the group again in a different new transaction ====\n");
    checkGroupValidity(groupId, bobId, janeId);

    em.getTransaction().commit();
  }
예제 #4
0
  // Test whether properties can be retrieved from the session and global caches
  public void testCaching() throws NotFoundException {
    TestGroup group;
    TestGroupDMO groupDMO;
    EntityManager em;
    ReadOnlySession session;
    Guid guid;
    TestViewpoint viewpoint = new TestViewpoint(Guid.createNew());

    em = support.beginSessionRW(viewpoint);

    group = new TestGroup("Hippos");
    guid = group.getGuid();
    em.persist(group);

    em.getTransaction().commit();

    //////////////////////////////////////

    em = support.beginSessionRO(viewpoint);

    session = support.currentSessionRO();

    // First time stores in session-local and global caches
    groupDMO = session.find(TestGroupDMO.class, guid);
    assertTrue(groupDMO != null);
    assertTrue(groupDMO.getKey().equals(guid));
    assertTrue(groupDMO.getName().equals("Hippos"));

    // Second time within session finds the existing DMO in
    // the session-local cache. The property value is cached
    // in the DMO.
    groupDMO = session.find(TestGroupDMO.class, guid);
    assertTrue(groupDMO != null);
    assertTrue(groupDMO.getKey().equals(guid));
    assertTrue(groupDMO.getName().equals("Hippos"));

    em.getTransaction().commit();

    //////////////////////////////////////////////////

    em = support.beginSessionRO(viewpoint);

    session = support.currentSessionRO();

    // Creates a new GroupDMO. The property value will be found
    // from the global cache
    groupDMO = session.find(TestGroupDMO.class, guid);
    assertTrue(groupDMO != null);
    assertTrue(groupDMO.getKey().equals(guid));
    assertTrue(groupDMO.getName().equals("Hippos"));

    em.getTransaction().commit();
  }
예제 #5
0
  /**
   * Send a message to a set of users.
   *
   * @param to the users to send the message to
   * @param template template for the messages we want to send out. It will be copied and the
   *     recipient filled in.
   */
  public void sendMessage(Set<Guid> to, Message template) {
    for (Guid guid : to) {
      String node = guid.toJabberId(null);

      // We want to avoid queueing messages for users not on this server,
      // since that will frequently be the vast majority of the recipients
      // that we are given
      if (SessionManager.getInstance().getSessionCount(node) == 0) continue;

      UserMessageQueue userQueue;

      synchronized (userQueues) {
        userQueue = userQueues.get(guid);
        if (userQueue == null) {
          userQueue = new UserMessageQueue(node);
          userQueues.put(guid, userQueue);
        }
      }

      userQueue.addMessage(pool, template);
    }
  }
예제 #6
0
  // Test looking up objects by String resource ID
  public void testStringResourceId() throws NotFoundException {
    EntityManager em;

    TestViewpoint viewpoint = new TestViewpoint(Guid.createNew());

    /////////////////////////////////////////////////
    // Setup

    em = support.beginSessionRW(viewpoint);

    TestUser bob = new TestUser("Bob");
    em.persist(bob);

    TestGroup group = new TestGroup("BobOnly");
    Guid groupId = group.getGuid();
    em.persist(group);

    TestGroupMember groupMember;

    groupMember = new TestGroupMember(group, bob);
    em.persist(groupMember);
    group.getMembers().add(groupMember);

    em.getTransaction().commit();

    /////////////////////////////////////////////////

    em = support.beginSessionRO(viewpoint);

    ReadOnlySession session = support.currentSessionRO();

    // Test for a GUID key
    TestGroupDMO groupDMO = session.find(TestGroupDMO.class, groupId);
    assertEquals(groupDMO, session.find(groupDMO.getResourceId()));

    // Test for a custom key
    TestGroupMemberDMO groupMemberDMO = groupDMO.getMembers().get(0);
    assertEquals(groupMemberDMO, session.find(groupMemberDMO.getResourceId()));

    em.getTransaction().commit();
  }
예제 #7
0
 /**
  * Check to see if a user is present on the system. This check will be done automatically when you
  * call sendMessage(), but if you are sending to only one user and creating the message payload is
  * significantly expensive, then it may be useful to check ahead of time.
  */
 public boolean userIsPresent(Guid guid) {
   String node = guid.toJabberId(null);
   return (SessionManager.getInstance().getSessionCount(node) > 0);
 }