peterxcli commented on code in PR #11319:
URL: https://github.com/apache/ozone/pull/11319#discussion_r4119904730
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestContainerStateMachine.java:
##########
@@ -209,16 +203,23 @@ public void testRatisSnapshotRetention() throws Exception
{
key.write(("ratis" + i).getBytes(UTF_8));
}
}
- files = parentPath.toFile().listFiles();
- assertThat(files).isNotNull();
- numSnapshots = files.length;
- assertThat(Math.abs(ratisServerConfiguration.getNumSnapshotsRetained() -
numSnapshots))
- .isLessThanOrEqualTo(1);
+ waitForSnapshotRetention(storage, lastAppliedIndex, retainedSnapshots);
}
- static Path getSnapshotPath(SimpleStateMachineStorage storage)
- throws IOException {
- return StatemachineImplTestUtil.findLatestSnapshot(storage)
- .getFile().getPath();
+ private static void waitForSnapshotRetention(
+ SimpleStateMachineStorage storage, long index, int retainedSnapshots)
+ throws Exception {
+ CheckedSupplier<Boolean, IOException> retentionSatisfied = () -> {
+ SingleFileSnapshotInfo snapshot =
+ StatemachineImplTestUtil.findLatestSnapshot(storage);
+ if (snapshot == null || snapshot.getTermIndex().getIndex() <= index) {
+ return false;
+ }
+ File[] files = snapshot.getFile().getPath().getParent().toFile()
+ .listFiles();
+ return files != null
+ && Math.abs(retainedSnapshots - files.length) <= 1;
+ };
Review Comment:
> `Math.abs(retainedSnapshots - files.length) <= 1;`
this should be moved to outside and do the assertion as original code do
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]