Skip to content

Commit

Permalink
HBASE-26790 Addendum ensure test is not flaky due to async caching
Browse files Browse the repository at this point in the history
  • Loading branch information
bbeaudreault committed Jun 23, 2022
1 parent 50f1115 commit 59e5c61
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,9 @@ public void testDoNotCacheLocationWithNullServerNameWhenGetAllLocations() throws
regionLocator.clearRegionLocationCache();
regionLocator.getAllRegionLocations().get();

int tries = 3;
// expect all to be non-null at first
checkRegions(conn, regions, null);
checkRegionsWithRetries(conn, regions, null, tries);

// clear servername from region info
Put put = MetaTableAccessor.makePutFromRegionInfo(chosen, EnvironmentEdgeManager.currentTime());
Expand All @@ -511,7 +512,23 @@ public void testDoNotCacheLocationWithNullServerNameWhenGetAllLocations() throws
}

// expect all but chosen to be non-null. chosen should be null because serverName was null
checkRegions(conn, regions, chosen);
checkRegionsWithRetries(conn, regions, chosen, tries);
}

// caching of getAllRegionLocations is async. so we give it a couple tries
private void checkRegionsWithRetries(AsyncConnectionImpl conn, List<RegionInfo> regions,
RegionInfo chosen, int retries) throws InterruptedException {
while (true) {
try {
checkRegions(conn, regions, chosen);
break;
} catch (AssertionError e) {
if (retries-- <= 0) {
throw e;
}
Thread.sleep(500);
}
}
}

private void checkRegions(AsyncConnectionImpl conn, List<RegionInfo> regions, RegionInfo chosen) {
Expand Down

0 comments on commit 59e5c61

Please sign in to comment.