use of alluxio.master.file.meta.UfsAbsentPathCache in project alluxio by Alluxio.
the class LoadMetadataIntegrationTest method checkFunctionCall.
private Object checkFunctionCall(final String path, CheckedBiFunction<String, Message, Object> function, Message options, boolean expectExistsAlluxio, boolean expectExistsUfs, int expectedAccesses) throws Exception {
long startMs = CommonUtils.getCurrentMs();
Object result = null;
try {
result = function.apply(path, options);
UfsAbsentPathCache cache = getUfsAbsentPathCache();
if (!expectExistsAlluxio) {
Assert.fail("Path is not expected to exist: " + path);
}
} catch (FileDoesNotExistException e) {
if (expectExistsAlluxio) {
throw e;
}
}
long durationMs = CommonUtils.getCurrentMs() - startMs;
assertTrue("Expected to be take between " + expectedAccesses * SLEEP_MS + " and " + (expectedAccesses + 0.5) * SLEEP_MS + ". actual duration (ms): " + durationMs, durationMs >= expectedAccesses * SLEEP_MS && durationMs < (expectedAccesses + 0.5) * SLEEP_MS);
if (!expectExistsUfs) {
// The metadata is loaded from Ufs, but the path does not exist, so it will be added to the
// absent cache. Wait until the path shows up in the absent cache.
UfsAbsentPathCache cache = getUfsAbsentPathCache();
try {
CommonUtils.waitFor("path (" + path + ") to be added to absent cache", () -> cache.isAbsentSince(new AlluxioURI(path), UfsAbsentPathCache.ALWAYS), WaitForOptions.defaults().setTimeoutMs(60000));
} catch (TimeoutException e) {
fail("Absent Path Cache addition timed out");
}
}
if (expectExistsUfs) {
// The metadata is loaded from Ufs, and the path exists, so it will be removed from the
// absent cache. Wait until the path is removed.
UfsAbsentPathCache cache = getUfsAbsentPathCache();
try {
CommonUtils.waitFor("path (" + path + ") to be removed from absent cache", () -> {
if (cache.isAbsentSince(new AlluxioURI(path), UfsAbsentPathCache.ALWAYS)) {
return false;
}
return true;
}, WaitForOptions.defaults().setTimeoutMs(60000));
} catch (TimeoutException e) {
fail("Absent Path Cache removal timed out");
}
}
return result;
}
Aggregations