/** Test cache timeout */
public void testTimeOut() throws Exception {
String[] users = new String[] { "root", "nobody", "SYSTEM",
"Administrator", "Administrators", "Guest" };
String realUser = null;
UnixUserGroupInformation ugi = null;
ProxyUgiManager.clearCache();
for (String user : users) {
ugi = ProxyUgiManager.getUgiForUser(user);
if (ugi != null) {
realUser = user;
break;
}
}
if (realUser != null) {
ProxyUgiManager.setUgiLifetime(ugiLifetime);
ProxyUgiManager.clearCache();
UnixUserGroupInformation[] fakedUgis = generateUgi(ProxyUgiManager.CLEANUP_THRESHOLD);
for (int i = 0; i < ProxyUgiManager.CLEANUP_THRESHOLD; i++) {
ProxyUgiManager.saveToCache(fakedUgis[i]);
}
assertTrue(ProxyUgiManager.getCacheSize() == ProxyUgiManager.CLEANUP_THRESHOLD);
Thread.sleep(ugiLifetime + 1000L);
UnixUserGroupInformation newugi = ProxyUgiManager.getUgiForUser(realUser);
assertTrue(ProxyUgiManager.getCacheSize() == ProxyUgiManager.CLEANUP_THRESHOLD + 1);
assertEquals(newugi, ugi);
Thread.sleep(ugiLifetime + 1000L);
newugi = ProxyUgiManager.getUgiForUser(realUser);
assertTrue(ProxyUgiManager.getCacheSize() == 1);