Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SearchableSnapshotDirectoryStatsTests.testReadBytesContiguously() #58912

Merged
merged 1 commit into from
Jul 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,27 @@ public void testCachedBytesReadsAndWrites() {

final long cachedBytesWriteCount = TestUtils.numberOfRanges(length, rangeSize.getBytes());

assertThat(inputStats.getCachedBytesWritten(), notNullValue());
assertThat(inputStats.getCachedBytesWritten().total(), equalTo(length));
assertThat(inputStats.getCachedBytesWritten().count(), equalTo(cachedBytesWriteCount));
assertThat(inputStats.getCachedBytesWritten().min(), greaterThan(0L));
assertThat(
inputStats.getCachedBytesWritten().max(),
(length < rangeSize.getBytes()) ? equalTo(length) : equalTo(rangeSize.getBytes())
);
assertThat(
inputStats.getCachedBytesWritten().totalNanoseconds(),
allOf(
// each read takes at least FAKE_CLOCK_ADVANCE_NANOS time
greaterThanOrEqualTo(FAKE_CLOCK_ADVANCE_NANOS * cachedBytesWriteCount),

// worst case: we start all reads before finishing any of them
lessThanOrEqualTo(FAKE_CLOCK_ADVANCE_NANOS * cachedBytesWriteCount * cachedBytesWriteCount)
)
);
// cache writes are executed in a different thread pool and can take some time to be processed
assertBusy(() -> {
assertThat(inputStats.getCachedBytesWritten(), notNullValue());
assertThat(inputStats.getCachedBytesWritten().total(), equalTo(length));
assertThat(inputStats.getCachedBytesWritten().count(), equalTo(cachedBytesWriteCount));
assertThat(inputStats.getCachedBytesWritten().min(), greaterThan(0L));
assertThat(
inputStats.getCachedBytesWritten().max(),
(length < rangeSize.getBytes()) ? equalTo(length) : equalTo(rangeSize.getBytes())
);
assertThat(
inputStats.getCachedBytesWritten().totalNanoseconds(),
allOf(
// each read takes at least FAKE_CLOCK_ADVANCE_NANOS time
greaterThanOrEqualTo(FAKE_CLOCK_ADVANCE_NANOS * cachedBytesWriteCount),

// worst case: we start all reads before finishing any of them
lessThanOrEqualTo(FAKE_CLOCK_ADVANCE_NANOS * cachedBytesWriteCount * cachedBytesWriteCount)
)
);
});

assertThat(inputStats.getCachedBytesRead(), notNullValue());
assertThat(inputStats.getCachedBytesRead().total(), greaterThanOrEqualTo(length));
Expand All @@ -145,7 +148,7 @@ public void testCachedBytesReadsAndWrites() {
assertCounter(inputStats.getOptimizedBytesRead(), 0L, 0L, 0L, 0L);
assertThat(inputStats.getOptimizedBytesRead().totalNanoseconds(), equalTo(0L));

} catch (IOException e) {
} catch (Exception e) {
throw new AssertionError(e);
}
});
Expand Down Expand Up @@ -336,15 +339,17 @@ public void testReadBytesContiguously() {
}
}

// cache file has been written in a single chunk
assertCounter(inputStats.getCachedBytesWritten(), input.length(), 1L, input.length(), input.length());
assertThat(inputStats.getCachedBytesWritten().totalNanoseconds(), equalTo(FAKE_CLOCK_ADVANCE_NANOS));
// cache file has been written in a single chunk in a different thread pool and can take some time to be processed
assertBusy(() -> {
assertCounter(inputStats.getCachedBytesWritten(), input.length(), 1L, input.length(), input.length());
assertThat(inputStats.getCachedBytesWritten().totalNanoseconds(), equalTo(FAKE_CLOCK_ADVANCE_NANOS));
});

assertCounter(inputStats.getNonContiguousReads(), 0L, 0L, 0L, 0L);
assertCounter(inputStats.getDirectBytesRead(), 0L, 0L, 0L, 0L);
assertThat(inputStats.getDirectBytesRead().totalNanoseconds(), equalTo(0L));

} catch (IOException e) {
} catch (Exception e) {
throw new AssertionError(e);
}
});
Expand Down