HADOOP-15614. TestGroupsCaching.testExceptionOnBackgroundRefreshHandled reliably fails. Contributed by Weiwei Yang.

(cherry picked from commit ccf2db7fc2)
This commit is contained in:
Kihwal Lee 2018-07-19 11:29:58 -05:00
parent 4c2ab22130
commit cf255dc01f
1 changed files with 11 additions and 6 deletions

View File

@ -561,23 +561,28 @@ public class TestGroupsCaching {
// Then expire that entry // Then expire that entry
timer.advance(4 * 1000); timer.advance(4 * 1000);
// Pause the getGroups operation and this will delay the cache refresh
FakeGroupMapping.pause();
// Now get the cache entry - it should return immediately // Now get the cache entry - it should return immediately
// with the old value and the cache will not have completed // with the old value and the cache will not have completed
// a request to getGroups yet. // a request to getGroups yet.
assertEquals(groups.getGroups("me").size(), 2); assertEquals(groups.getGroups("me").size(), 2);
assertEquals(startingRequestCount, FakeGroupMapping.getRequestCount()); assertEquals(startingRequestCount, FakeGroupMapping.getRequestCount());
// Resume the getGroups operation and the cache can get refreshed
FakeGroupMapping.resume();
// Now sleep for a short time and re-check the request count. It should have // Now wait for the refresh done, because of the exception, we expect
// increased, but the exception means the cache will not have updated // a onFailure callback gets called and the counter for failure is 1
Thread.sleep(50); waitForGroupCounters(groups, 0, 0, 0, 1);
FakeGroupMapping.setThrowException(false); FakeGroupMapping.setThrowException(false);
assertEquals(startingRequestCount + 1, FakeGroupMapping.getRequestCount()); assertEquals(startingRequestCount + 1, FakeGroupMapping.getRequestCount());
assertEquals(groups.getGroups("me").size(), 2); assertEquals(groups.getGroups("me").size(), 2);
// Now sleep another short time - the 3rd call to getGroups above // Now the 3rd call to getGroups above will have kicked off
// will have kicked off another refresh that updates the cache // another refresh that updates the cache, since it no longer gives
Thread.sleep(50); // exception, we now expect the counter for success is 1.
waitForGroupCounters(groups, 0, 0, 1, 1);
assertEquals(startingRequestCount + 2, FakeGroupMapping.getRequestCount()); assertEquals(startingRequestCount + 2, FakeGroupMapping.getRequestCount());
assertEquals(groups.getGroups("me").size(), 3); assertEquals(groups.getGroups("me").size(), 3);
} }