use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class JpaAggregatedTabLookupDaoTest method testLoginAggregationLifecycle.
@Test
public void testLoginAggregationLifecycle() throws Exception {
when(portalJdbcOperations.queryForList("SELECT NAME FROM UP_LAYOUT_STRUCT where USER_ID = ? AND LAYOUT_ID = ? AND STRUCT_ID = ?", String.class, 1, 1, 1)).thenReturn(Collections.singletonList("TabName"));
when(portalJdbcOperations.queryForList("SELECT NAME FROM UP_LAYOUT_STRUCT where USER_ID = ? AND LAYOUT_ID = ? AND STRUCT_ID = ?", String.class, 1, 1, 2)).thenReturn(Collections.<String>emptyList());
when(portalJdbcOperations.queryForList("SELECT USER_NAME FROM UP_USER WHERE USER_ID=?", String.class, 1)).thenReturn(Collections.singletonList("FragmentName"));
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedTabMapping tabMappings = aggregatedTabLookupDao.getMappedTabForLayoutId("u1l1s1");
assertNotNull(tabMappings);
assertEquals("FragmentName", tabMappings.getFragmentName());
assertEquals("TabName", tabMappings.getTabName());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedTabMapping tabMappings = aggregatedTabLookupDao.getMappedTabForLayoutId("u1l1s2");
assertNotNull(tabMappings);
assertEquals("FragmentName", tabMappings.getFragmentName());
assertEquals("u1l1s2", tabMappings.getTabName());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedTabMapping tabMappings = aggregatedTabLookupDao.getMappedTabForLayoutId(null);
assertNotNull(tabMappings);
assertEquals(AggregatedTabMapping.MISSING_TAB_FRAGMENT_NAME, tabMappings.getFragmentName());
assertEquals(AggregatedTabMapping.MISSING_TAB_NAME, tabMappings.getTabName());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedTabMapping tabMappings = aggregatedTabLookupDao.getMappedTabForLayoutId("s1");
assertNotNull(tabMappings);
assertEquals(AggregatedTabMapping.PERSONAL_TAB_FRAGMENT_NAME, tabMappings.getFragmentName());
assertEquals(AggregatedTabMapping.PERSONAL_TAB_NAME, tabMappings.getTabName());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedTabMapping tabMappings = aggregatedTabLookupDao.getMappedTabForLayoutId("u1l1s1");
assertNotNull(tabMappings);
assertEquals("FragmentName", tabMappings.getFragmentName());
assertEquals("TabName", tabMappings.getTabName());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedTabMapping tabMappings = aggregatedTabLookupDao.getMappedTabForLayoutId("u1l1s2");
assertNotNull(tabMappings);
assertEquals("FragmentName", tabMappings.getFragmentName());
assertEquals("u1l1s2", tabMappings.getTabName());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedTabMapping tabMappings = aggregatedTabLookupDao.getMappedTabForLayoutId(null);
assertNotNull(tabMappings);
assertEquals(AggregatedTabMapping.MISSING_TAB_FRAGMENT_NAME, tabMappings.getFragmentName());
assertEquals(AggregatedTabMapping.MISSING_TAB_NAME, tabMappings.getTabName());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedTabMapping tabMappings = aggregatedTabLookupDao.getMappedTabForLayoutId("s1");
assertNotNull(tabMappings);
assertEquals(AggregatedTabMapping.PERSONAL_TAB_FRAGMENT_NAME, tabMappings.getFragmentName());
assertEquals(AggregatedTabMapping.PERSONAL_TAB_NAME, tabMappings.getTabName());
}
});
}
use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class JpaClusterLockDaoTest method testAbandoned.
/**
* Ignoring this test because it is nondeterministic.
*
* @throws Exception
*/
@Test
@Ignore
public void testAbandoned() throws Exception {
// Used to make a 'mutable string'
final AtomicReference<String> currentServer = new AtomicReference<String>("ServerA");
final String mutexName = "testNotAbandoned";
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() {
final ClusterMutex mutex = clusterLockDao.getClusterMutex(mutexName);
Assert.assertNotNull(mutex);
}
});
// lock serverA
currentServer.set("ServerA");
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final ClusterMutex mutex = clusterLockDao.getLock(mutexName);
Assert.assertNotNull(mutex);
}
});
final AtomicInteger lockFailCount = new AtomicInteger(0);
final AtomicBoolean serverBLocked = new AtomicBoolean(false);
currentServer.set("ServerB");
// test context configures a 100ms abandoned lock timeout, wait 110 between tests
for (int i = 0; i < 5 && !serverBLocked.get(); i++) {
// try lock ServerB
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final ClusterMutex mutex = clusterLockDao.getLock(mutexName);
if (mutex == null) {
lockFailCount.incrementAndGet();
} else {
serverBLocked.set(true);
}
}
});
TimeUnit.MILLISECONDS.sleep(110);
}
assertTrue(serverBLocked.get());
assertEquals(1, lockFailCount.get());
currentServer.set("ServerB");
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 JpaClusterLockDaoTest method testUnlockedRelease.
@Test(expected = IllegalMonitorStateException.class)
public void testUnlockedRelease() 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.releaseLock(mutexName);
}
});
}
use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class JpaClusterLockDaoTest method testNotAbandoned.
/**
* Ignoring this test because it is nondeterministic.
*
* @throws Exception
*/
@Test
@Ignore
public void testNotAbandoned() throws Exception {
// Used to make a 'mutable string'
final AtomicReference<String> currentServer = new AtomicReference<String>("ServerA");
final String mutexName = "testNotAbandoned";
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() {
final ClusterMutex mutex = clusterLockDao.getClusterMutex(mutexName);
assertNotNull(mutex);
}
});
// lock serverA
currentServer.set("ServerA");
final ClusterMutex lockedMutex = execute(new Callable<ClusterMutex>() {
@Override
public ClusterMutex call() throws Exception {
final ClusterMutex mutex = clusterLockDao.getLock(mutexName);
assertNotNull(mutex);
return mutex;
}
});
// 110ms
while (lockedMutex.getLockStart() + 110 > System.currentTimeMillis()) {
// try lock ServerB
currentServer.set("ServerB");
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final ClusterMutex mutex = clusterLockDao.getLock(mutexName);
assertNull(mutex);
}
});
TimeUnit.MILLISECONDS.sleep(1);
// ServerA update ping
currentServer.set("ServerA");
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
clusterLockDao.updateLock(mutexName);
}
});
TimeUnit.MILLISECONDS.sleep(1);
}
currentServer.set("ServerA");
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 JpaClusterLockDaoTest method testWrongServerUpdate.
@Test(expected = IllegalMonitorStateException.class)
public void testWrongServerUpdate() 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.getLock(mutexName);
}
});
currentServer.set("ServerB");
// get/create the mutex
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
clusterLockDao.updateLock(mutexName);
}
});
}
Aggregations