use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class JpaClusterLockDaoTest method testConcurrentCreation.
@Test
public void testConcurrentCreation() throws InterruptedException {
reset(portalInfoProvider);
when(portalInfoProvider.getUniqueServerName()).thenReturn("ServerA");
final ThreadGroupRunner threadGroupRunner = new ThreadGroupRunner("JpaClusterLockDaoTest-", true);
threadGroupRunner.addTask(3, new ThrowingRunnable() {
@Override
public void runWithException() throws Throwable {
executeInTransaction(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
try {
final String mutexName = "testConcurrentCreation";
threadGroupRunner.tick(1);
ClusterMutex mutex = clusterLockDao.getClusterMutex(mutexName);
assertNotNull(mutex);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
}
});
threadGroupRunner.start();
threadGroupRunner.join();
}
use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class JpaClusterLockDaoTest method testUnlockedUpdate.
@Test(expected = IllegalMonitorStateException.class)
public void testUnlockedUpdate() throws Exception {
// Used to make a 'mutable string'
final AtomicReference<String> currentServer = new AtomicReference<String>("ServerA");
final String mutexName = "testUnlockedUpdate";
reset(portalInfoProvider);
when(portalInfoProvider.getUniqueServerName()).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return currentServer.get();
}
});
// get/create the mutex
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
clusterLockDao.updateLock(mutexName);
}
});
}
use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class JpaClusterLockDaoTest method testWrongServerRelease.
@Test(expected = IllegalMonitorStateException.class)
public void testWrongServerRelease() throws Exception {
// Used to make a 'mutable string'
final AtomicReference<String> currentServer = new AtomicReference<String>("ServerA");
final String mutexName = "testUnlockedRelease";
reset(portalInfoProvider);
when(portalInfoProvider.getUniqueServerName()).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return currentServer.get();
}
});
// get/create the mutex
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
clusterLockDao.getLock(mutexName);
}
});
currentServer.set("ServerB");
// get/create the mutex
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
clusterLockDao.releaseLock(mutexName);
}
});
}
use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class JpaClusterLockDaoTest method testConcurrentCreateLocking.
/**
* This test turns out to be nondeterministic under load and so can yield false-negatives
* (failures that don't seem to actually indicate a regression).
*
* @throws InterruptedException
*/
@Test
@Ignore
public void testConcurrentCreateLocking() throws InterruptedException {
reset(portalInfoProvider);
when(portalInfoProvider.getUniqueServerName()).thenReturn("ServerA");
final String mutexName = "testConcurrentLocking";
final ThreadGroupRunner threadGroupRunner = new ThreadGroupRunner("JpaClusterLockDaoTest-", true);
final AtomicInteger lockCounter = new AtomicInteger();
threadGroupRunner.addTask(3, new ThrowingRunnable() {
@Override
public void runWithException() throws Throwable {
executeInTransaction(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
try {
threadGroupRunner.tick(1);
try {
final ClusterMutex mutex = clusterLockDao.getLock(mutexName);
if (mutex != null) {
lockCounter.incrementAndGet();
}
} finally {
threadGroupRunner.tick(3);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
}
});
threadGroupRunner.start();
threadGroupRunner.join();
assertEquals(1, lockCounter.intValue());
ClusterMutex mutex = clusterLockDao.getClusterMutex(mutexName);
assertTrue(mutex.isLocked());
clusterLockDao.releaseLock(mutexName);
mutex = clusterLockDao.getClusterMutex(mutexName);
assertFalse(mutex.isLocked());
}
use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class JpaVersionDaoTest method testVersionBadSql.
@Test
public void testVersionBadSql() {
final String productName = "TEST_VERSION";
// Create
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
Version version = versionDao.getVersion(productName);
assertNull(version);
version = versionDao.setVersion(productName, 1, 2, 3, null);
assertNotNull(version);
assertEquals(1, version.getMajor());
assertEquals(2, version.getMinor());
assertEquals(3, version.getPatch());
assertNull(version.getLocal());
}
});
jdbcOperations.execute("ALTER TABLE UP_VERSION DROP LOCAL_VER");
try {
// Doesn't exist
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final Version version = versionDao.getVersion(productName);
assertNotNull(version);
assertEquals(1, version.getMajor());
assertEquals(2, version.getMinor());
assertEquals(3, version.getPatch());
assertNull(version.getLocal());
}
});
} finally {
jdbcOperations.execute("ALTER TABLE UP_VERSION ADD COLUMN LOCAL_VER INTEGER");
}
}
Aggregations