@Test
public void testUserAuthentication()
throws Exception
{
LdapManager ldapManager = this.lookup(LdapManager.class);
// all systems are good
Assert.assertNotNull(ldapManager.authenticateUser("rwalker", "rwalker123"));
// stop the main server
mainConnector.stop();
// try again, this time it should hit the cache
Assert.assertNotNull(ldapManager.authenticateUser("rwalker", "rwalker123"));
// wait 2 sec cache should still be valid
Thread.sleep(1000 * 2);
Assert.assertNotNull(ldapManager.authenticateUser("rwalker", "rwalker123"));
// now wait another 2 seconds and cache should be cleared
Thread.sleep(1000 * 2);
// server down and cache cleared
try {
ldapManager.authenticateUser("rwalker", "rwalker123");
Assert.fail("expected NoSuchLdapUserException");
}
catch (AuthenticationException e) {
// expected
}