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

📄 entitylocktester.java

📁 uPortal是开放源码的Portal门户产品
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        msg = "Selecting locks for Group type.";        print(msg);        selectedLocks = getLockStore().find(GROUP_CLASS, null, null, null, null);        numLocks = selectedLocks.length;        assertEquals(numLocks, numUnexpiredIEntityGroupLocksInStore);        for (ctr=0; ctr<numLocks; ctr++)            { assertEquals(msg, selectedLocks[ctr].getEntityType(), GROUP_CLASS); }        // select locks by entity type and entity key        msg = "Selecting locks by type and key.";        print(msg);        selectedLocks = getLockStore().find(GROUP_CLASS, testKeys[1], null, null, null);        numLocks = selectedLocks.length;        assertEquals(msg, numLocks, 1);        assertEquals(msg, selectedLocks[0].getEntityType(), GROUP_CLASS);        assertEquals(msg, selectedLocks[0].getEntityKey(), testKeys[1]);       // select locks by entity type, entity key and lock type        msg = "Selecting locks by type, key, and lock type";        print(msg);        selectedLocks = getLockStore().find(IPERSON_CLASS, testKeys[1], new Integer(1), null, null);        numLocks = selectedLocks.length;        assertEquals(msg, numLocks, 1);        assertEquals(msg, selectedLocks[0].getEntityType(), IPERSON_CLASS);        assertEquals(msg, selectedLocks[0].getEntityKey(), testKeys[1]);        assertEquals(msg, selectedLocks[0].getLockType(), 1);        selectedLocks = getLockStore().find(IPERSON_CLASS, testKeys[1], new Integer(0), null, null);        numLocks = selectedLocks.length;        assertEquals(msg, numLocks, 0);        // select locks by entity type and owner        msg = "Selecting locks by entity type and owner";        String id = testIds[1];        print(msg);        selectedLocks = getLockStore().find(IPERSON_CLASS, null, null, null, id );        numLocks = selectedLocks.length;        assertEquals(numLocks, numIPersonLocksInStoreForTestId);        for (ctr=0; ctr<numLocks; ctr++)        {            assertEquals(msg, selectedLocks[ctr].getEntityType(), IPERSON_CLASS);            assertEquals(msg, selectedLocks[ctr].getLockOwner(), id);        }}/** */public void testService() throws Exception{    String msg = null;    IEntityLock readLock1, readLock2, writeLock = null;    String key = System.currentTimeMillis() + "";    print("Creating first read lock.");    readLock1 = EntityLockService.instance().newReadLock(IPERSON_CLASS, key, testIds[0]);    print("Creating second read lock (for same entity).");    readLock2 = EntityLockService.instance().newReadLock(IPERSON_CLASS, key, testIds[0]);    msg = "Attempting to create a write lock for the entity: should fail.";    print(msg);    try        { writeLock = EntityLockService.instance().newWriteLock(IPERSON_CLASS, key, testIds[0]); }    catch (LockingException le)        { System.out.println("Caught Exception: " + le.getMessage()); }    assertNull(msg, writeLock);    msg = "Releasing read locks: lock should be invalid.";    print(msg);    readLock1.release();    assertTrue( msg, ! readLock1.isValid() );    readLock2.release();    assertTrue( msg, ! readLock2.isValid() );    msg = "Attempting to create a write lock for the entity: should succeed.";    print(msg);    try        { writeLock = EntityLockService.instance().newWriteLock(IPERSON_CLASS, key, testIds[0]); }    catch (LockingException le)        { System.out.println("Caught Exception: " + le.getMessage()); }    assertTrue( msg, writeLock.isValid() );    msg = "Releasing write lock: should be invalid.";    print(msg);    writeLock.release();    assertTrue( msg, ! writeLock.isValid() );}/** */public void testServiceConvert() throws Exception{    String msg = null;    boolean valid = false;    IEntityLockService service = getService();    int readSecs = 30;    int writeSecs = 45;    // Create a READ lock on Group testKeys[3], owned by testIds[0]:    print("Creating new READ lock");    IEntityLock lock = service.newLock(GROUP_CLASS, testKeys[3], IEntityLockService.READ_LOCK, testIds[0], readSecs);    msg = "Testing if new lock is valid";    valid = service.isValid(lock);    print(msg);    assertTrue(msg, valid);    // Convert the READ lock to a WRITE lock:    print("Converting READ lock to WRITE");    service.convert(lock, IEntityLockService.WRITE_LOCK, writeSecs);    msg = "Testing if converted lock is still valid";    valid = service.isValid(lock);    print(msg);    assertTrue(msg, valid);    // Convert the WRITE lock back to a READ lock:    print("Converting WRITE lock to READ");    service.convert(lock, IEntityLockService.READ_LOCK, readSecs);    msg = "Testing if converted lock is still valid";    valid = service.isValid(lock);    print(msg);    assertTrue(msg, valid);    // Now try to create a WRITE lock on the same entity for a different owner.    IEntityLock duplicateLock = null;    msg = "Attempting to create a duplicate lock; should be null";    print(msg);    try { duplicateLock = service.newLock(GROUP_CLASS, testKeys[3], IEntityLockService.WRITE_LOCK, testIds[1]); }    catch (LockingException le) {print("Caught exception: " + le.getMessage()); }    assertNull(msg, duplicateLock);}/** */public void testServiceLockRenewal() throws Exception{    String msg = null;    boolean valid = false;    IEntityLockService service = getService();    msg = "Attempting to renew an old lock";    print(msg);    IEntityLock badLock = testLocks[2];    msg = "Checking if lock was renewed.";    print(msg);    try { service.renew(badLock); } catch (Exception ex) {print("Caught Exception: " + ex.getMessage()); }    assertTrue(msg, ! service.isValid(badLock));    msg = "Attempting to renew a valid lock";    print(msg);    IEntityLock goodLock = testLocks[0];    msg = "Checking if lock was renewed.";    print(msg);    try { service.renew(goodLock); } catch (Exception ex) {print("Caught Exception: " + ex.getMessage()); }    assertTrue(msg, service.isValid(goodLock));}/** */public void testServiceNewLock() throws Exception{    String msg = null;    boolean valid = false;    print("Creating new lock");    IEntityLockService service = getService();    IEntityLock newLock = service.newLock(GROUP_CLASS, testKeys[3], IEntityLockService.WRITE_LOCK, testIds[0]);    msg = "Testing if new lock is valid";    valid = getService().existsInStore(newLock);    print(msg);    assertTrue(msg, valid);    print("Releasing new lock");    getService().release(newLock);    msg = "Testing if new lock is still valid";    valid = getService().existsInStore(newLock);    print(msg);    assertTrue(msg, ! valid);}/** */public void testStoreUpdate() throws Exception{    long fiveMinutes = 1000 * 60 * 5;    long tenMinutes =  1000 * 60 * 10;    long now = System.currentTimeMillis();    String msg = null;    print("Update expiration and lock type of testLocks[1].");    java.util.Date newExpiration = new java.util.Date(now + fiveMinutes);    int newType = IEntityLockService.WRITE_LOCK;    // Copy testLocks[1] to lock1.    IEntityLock lock1 = new EntityLockImpl        (testLocks[1].getEntityType(), testLocks[1].getEntityKey(),         testLocks[1].getLockType(), testLocks[1].getExpirationTime(), testLocks[1].getLockOwner());    // Update testLocks[1].    getLockStore().update(testLocks[1], newExpiration, new Integer(newType));    ((EntityLockImpl)testLocks[1]).setExpirationTime(newExpiration);    ((EntityLockImpl)testLocks[1]).setLockType(newType);    msg = "Check if the old version (lock1) still exists in store.";    print(msg);    assertTrue(msg, ! getService().existsInStore(lock1) );    msg = "Check if new version exists in store.";    print(msg);    IEntityLock lock2 = new EntityLockImpl        (lock1.getEntityType(), lock1.getEntityKey(), newType, newExpiration, lock1.getLockOwner());    assertTrue( msg, getService().existsInStore(lock2) );    print("Update only expiration on (updated) lock.");    newExpiration = new java.util.Date(now + tenMinutes);    getLockStore().update(lock2, newExpiration, null);    ((EntityLockImpl)lock2).setExpirationTime(newExpiration);    msg = "Check if un-updated lock still exists in store.";    print(msg);    assertTrue( msg, ! getService().existsInStore(testLocks[1]) );    msg = "Check if the doubly-updated lock exists in store.";    print(msg);    IEntityLock lock3 = new EntityLockImpl        (lock2.getEntityType(), lock2.getEntityKey(), lock2.getLockType(), newExpiration, lock2.getLockOwner());    assertTrue( msg, getService().existsInStore(lock3) );    testLocks[0] = lock3;}}

⌨️ 快捷键说明

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