⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 groupstester.java

📁 uPortal是开放源码的Portal门户产品
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    print(CR + "***** LEAVING GroupsTester.testUpdateLockableGroups() *****" + CR);}/** */public void testUpdateLockableGroupsWithRenewableLock() throws Exception{    print(CR + "***** ENTERING GroupsTester.testUpdateLockableGroupsWithRenewableLock() *****" + CR);    String msg = null;    Class type = TEST_ENTITY_CLASS;    IEntityGroup group = null;    boolean testValue = false;    Exception e = null;    String groupKey = null;    msg = "Creating new group.";    print(msg);    group = getNewGroup();    group.update();    assertNotNull(msg, group);        msg = "Getting group key.";    print(msg);    groupKey = group.getKey();    msg = "Retrieving lockable group for key " + groupKey;    print(msg);    ILockableEntityGroup lockableGroup = findLockableGroup(groupKey);    assertNotNull(msg, lockableGroup);    msg = "Checking lock of first group";    print(msg);    testValue = lockableGroup.getLock().isValid();    assertTrue(msg, testValue);        String oldName = lockableGroup.getName();    String newName = "NEW GROUP NAME";    msg = "Updating name of lockable group but not committing.";    print(msg);    lockableGroup.setName(newName);    assertEquals(msg, newName, lockableGroup.getName());    msg = "Checking lock of first group";    print(msg);    testValue = lockableGroup.getLock().isValid();    assertTrue(msg, testValue);        msg = "Committing change to lockable group and renewing lock.";    print(msg);    lockableGroup.updateAndRenewLock();    testValue = lockableGroup.getLock().isValid();    assertTrue(msg, testValue);    msg = "Retrieving duplicate group from service; change should be visible now.";    print(msg);    IEntityGroup nonLockableGroup = findGroup(groupKey);    assertEquals(msg, newName, nonLockableGroup.getName());    msg = "Update name of lockable group again.";    print(msg);    lockableGroup.setName(oldName);    assertEquals(msg, oldName, lockableGroup.getName());        msg = "Committing change to lockable group and renewing lock.";    print(msg);    lockableGroup.updateAndRenewLock();    testValue = lockableGroup.getLock().isValid();    assertTrue(msg, testValue);    msg = "Attempting to delete lockable group " + groupKey;    print(msg);    lockableGroup.delete();    nonLockableGroup = findGroup(groupKey);    assertNull(msg, nonLockableGroup);    print(CR + "***** LEAVING GroupsTester.testUpdateLockableGroupsWithRenewableLock() *****" + CR);}/** */public void testUpdateMembersVisibility() throws Exception{    print(CR + "***** ENTERING GroupsTester.testUpdateMembersVisibility() *****" + CR);    String msg = null;    Class type = TEST_ENTITY_CLASS;    int totNumGroups = 3;    int totNumEntities = 5;    IEntityGroup[] groups = new IEntityGroup[totNumGroups];    IEntity[] entities = new IEntity[totNumEntities];    IGroupMember[] groupMembers = null;    Iterator itr = null;    ArrayList list = null;    int idx = 0;    boolean testValue = false;    msg = "Creating " + totNumGroups + " new groups.";    print(msg);    for (idx=0; idx<totNumGroups; idx++)    {        groups[idx] = getNewGroup();        groups[idx].getMembers();  // cache members from now on.        assertNotNull(msg, groups[idx]);    }    IEntityGroup rootGroup = groups[0];    IEntityGroup childGroup = groups[1];    msg = "Adding " + (totNumGroups - 1) + " to root group.";    print(msg);    for(idx=1; idx<totNumGroups; idx++)        { rootGroup.addMember(groups[idx]); }    msg = "Retrieving members from root group.";    print(msg);    list = new ArrayList();    for( itr=rootGroup.getMembers(); itr.hasNext(); )        { list.add(itr.next()); }    assertEquals(msg, (totNumGroups - 1), list.size());    msg = "Adding " + (totNumEntities - 2) + " to root group.";    print(msg);    for(idx=0; idx<(totNumEntities - 2) ; idx++)        { rootGroup.addMember(testEntities[idx]); }    msg = "Retrieving members from root group.";    print(msg);    list = new ArrayList();    for( itr=rootGroup.getMembers(); itr.hasNext(); )        { list.add(itr.next()); }    assertEquals(msg, (totNumGroups - 1 + totNumEntities - 2), list.size());    msg = "Adding 2 entities to child group.";    print(msg);    childGroup.addMember(testEntities[totNumEntities - 1]);    childGroup.addMember(testEntities[totNumEntities]);    msg = "Retrieving ALL members from root group.";    print(msg);    list = new ArrayList();    for( itr=rootGroup.getAllMembers(); itr.hasNext(); )        { list.add(itr.next()); }    assertEquals(msg, (totNumGroups - 1 + totNumEntities), list.size());    // At this point, the child group members should not yet be aware of their parents.    msg = "Checking child groups for parents (should be none).";    print(msg);    list = new ArrayList();    for(idx=1; idx<totNumGroups; idx++)    {         for (itr = groups[idx].getContainingGroups(); itr.hasNext();)            { list.add(itr.next()); }        assertEquals(msg, 0, list.size());    }    testValue = testEntities[0].isMemberOf(rootGroup);    assertEquals(msg, false, testValue);    // Update the parent group.  Its children should now be aware of it.    msg = "Updating parent group.";    print(msg);    rootGroup.update();    msg = "Checking child entity for membership in parent.";    print(msg);    testValue = testEntities[0].isMemberOf(rootGroup);    assertEquals(msg, true, testValue);        // Child group not yet updated.  Its child should still be unaware of it.    msg = "Checking child entity for membership in child group.";    print(msg);    testValue = testEntities[totNumEntities].isMemberOf(childGroup);    assertEquals(msg, false, testValue);        // Update the child group.  Its children should now be aware of it.    msg = "Updating child group.";    print(msg);    childGroup.update();    msg = "Checking child entity for membership in child group.";    print(msg);    testValue = testEntities[totNumEntities].isMemberOf(childGroup);    assertEquals(msg, true, testValue);    msg = "Getting child entity thru the service (should be cached copy).";    print(msg);    EntityIdentifier entID = testEntities[totNumEntities].getUnderlyingEntityIdentifier();    IGroupMember ent = GroupService.getGroupMember(entID);    msg = "Checking child entity for membership in child group.";    print(msg);    testValue = ent.isMemberOf(childGroup);    assertEquals(msg, true, testValue);    // Child entity should now be aware of both of its parents.    msg = "Checking child entity for ALL containing groups.";    print(msg);    list = new ArrayList();    for (itr = ent.getAllContainingGroups(); itr.hasNext();)            { list.add(itr.next()); }    assertEquals(msg, 2, list.size());        print(CR + "***** LEAVING GroupsTester.testUpdateMembersVisibility() *****" + CR);}/** */public void testMixLockableAndNonLockableGroups() throws Exception{    print(CR + "***** ENTERING GroupsTester.testMixLockableAndNonLockableGroups() *****" + CR);    String msg = null;    Class type = TEST_ENTITY_CLASS;    int totNumGroups = 3;    IEntityGroup[] groups = new IEntityGroup[totNumGroups];    boolean testValue = false;    Exception e = null;    int idx = 0;    msg = "Creating " + totNumGroups + " new groups.";    print(msg);    for (idx=0; idx<totNumGroups; idx++)    {        groups[idx] = getNewGroup();        groups[idx].update();        assertNotNull(msg, groups[idx]);        groups[idx].update();    }        msg = "Getting group keys.";    print(msg);    String[] groupKeys = new String[totNumGroups];    for (idx=0; idx<totNumGroups; idx++)    {        groupKeys[idx] = groups[idx].getKey();    }    msg = "Retrieving nonLockable group " + groupKeys[0];    print(msg);    IEntityGroup group1 = findGroup(groupKeys[0]);    assertNotNull(msg, group1);    msg = "Retrieving lockable group for key " + groupKeys[0];    print(msg);    ILockableEntityGroup lockableGroup = findLockableGroup(groupKeys[0]);    testValue = lockableGroup.getLock().isValid();    assertTrue(msg, testValue);        msg = "Updating lockable group.";    print(msg);    String oldName = lockableGroup.getName();    String newName = "NEW GROUP NAME";    print(msg);    lockableGroup.setName(newName);    lockableGroup.update();    msg = "Retrieving a second nonLockable group for " + groupKeys[0];    print(msg);    IEntityGroup group2 = findGroup(groupKeys[0]);    assertNotNull(msg, group2);    assertEquals(msg, newName, group2.getName());    msg = "Updating second nonLockable group.";    print(msg);    group2.setName(oldName);    group2.update();    msg = "Retrieving a second lockable group for key " + groupKeys[0];    print(msg);    ILockableEntityGroup lockableGroup2 = findLockableGroup(groupKeys[0]);    testValue = lockableGroup2.getLock().isValid();    assertTrue(msg, testValue);        msg = "Updating second lockable group.";    print(msg);    lockableGroup2.setName(newName);    lockableGroup2.update();        print(CR + "***** LEAVING GroupsTester.testMixLockableAndNonLockableGroups() *****" + CR);}/** */public void testConcurrentAccess() throws Exception{    print(CR + "***** ENTERING GroupsTester.testConcurrentAccess() *****" + CR);    String msg = null;    Class type = TEST_ENTITY_CLASS;    int totNumGroups = 3;    int numContainingGroups = totNumGroups - 1;    IEntityGroup[] groups = new IEntityGroup[totNumGroups];    int idx = 0;    int numReadTests = 50;    int numThreads = 10;    msg = "Creating " + totNumGroups + " new groups.";    print(msg);    for (idx=0; idx<totNumGroups; idx++)    {        groups[idx] = getNewGroup();        groups[idx].update();        assertNotNull(msg, groups[idx]);        groups[idx].update();    }    IEntityGroup child = groups[0];    msg = "Adding parents to child group " + child.getName();    print(msg);    for (idx=1; idx<totNumGroups; idx++)    {        IEntityGroup parent =  groups[idx];        parent.addMember(child);        groups[idx].update();    }    print("Starting testing Threads.");    Thread[] testers = new Thread[numThreads];    for (idx=0; idx<numThreads; idx++)    {        String id = "" + idx;        GroupsReadTester grt = new GroupsReadTester(id, child, numReadTests);        testers[idx] = new Thread(grt);         testers[idx].start();    }        msg = "Adding members to " + child;    print(msg);    for (idx=0; idx<numTestEntities; idx++)    {        IEntity childEntity = testEntities[idx];        child.addMember(childEntity);        if ( idx % 10 == 0 )  // update once for every 10 adds            { child.update(); }         assertTrue(msg,child.contains(childEntity));//      print("added entity # " + (idx + 1) + " to " + child);    }        msg = "Updating " + child;    print(msg);    child.update();    msg = "Removing members from " + child;    print(msg);    for (idx=0; idx<numTestEntities; idx++)    {        IEntity childEntity = testEntities[idx];        child.removeMember(childEntity);        assertTrue(msg,! child.contains(childEntity));    }    msg = "Updating " + child;    print(msg);    child.update();        Thread.sleep(numReadTests * 20);  // let them die.    print(CR + "***** LEAVING GroupsTester.testConcurrentAccess() *****" + CR);}/** */public void testParseCompoundKeys() throws Exception{    print(CR + "***** ENTERING GroupsTester.testParseCompoundKeys() *****" + CR);        String msg = null;    int maxNodes=5;    int idx=0;    String[] keys = new String[maxNodes];    String[] nodes = new String[maxNodes];    String key = null;    String sep = GroupServiceConfiguration.getConfiguration().getNodeSeparator();    print("GroupServiceConfiguration node separator: " + sep);        print("Creating random node strings.");    for (idx=0; idx<maxNodes; idx++)        { nodes[idx] = (getRandomString(random, 3) + idx); }    print ("Creating keys.");        for (idx=0; idx<maxNodes; idx++)    {        key = nodes[0];        for (int i = 1; i<=idx; i++)             { key = key + sep + nodes[i]; }        keys[idx] = key;        print("key " + idx + " : " + key);    }        for (idx=1; idx<maxNodes; idx++)    {        CompositeEntityIdentifier cei = null;        msg = "Creating CompositeEntityIdentifier for " + keys[idx];        print(msg);        cei = new CompositeEntityIdentifier(keys[idx], GROUP_CLASS);        assertNotNull(msg, cei);        msg = "Testing COMPOUND key of " + cei;        assertEquals(msg, keys[idx], cei.getKey());        msg = "Testing LOCAL key of " + cei;        assertEquals(msg, nodes[idx], cei.getLocalKey());        msg = "Testing SERVICE NAME of " + cei;        assertEquals(msg, idx, cei.getServiceName().size());    }            print(CR + "***** LEAVING GroupsTester.testParseCompoundKeys() *****" + CR);}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -