This is an automated email from the ASF dual-hosted git repository.
thomasm pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new e6eddc36a3 OAK-11054 Oak AsyncCheckpointCreatorTest sometimes fails
(#1664)
e6eddc36a3 is described below
commit e6eddc36a3a8c0babaf370834c47e8fba737ff79
Author: Thomas Mueller <[email protected]>
AuthorDate: Tue Aug 27 14:50:24 2024 +0200
OAK-11054 Oak AsyncCheckpointCreatorTest sometimes fails (#1664)
---
.../oak/plugins/index/AsyncCheckpointCreator.java | 2 +-
.../plugins/index/AsyncCheckpointCreatorTest.java | 30 +++++++++++++++++++---
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git
a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncCheckpointCreator.java
b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncCheckpointCreator.java
index d4a1ab6de8..72d2f1b281 100644
---
a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncCheckpointCreator.java
+++
b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncCheckpointCreator.java
@@ -135,7 +135,7 @@ public class AsyncCheckpointCreator implements Runnable {
// If we don't decrement the counter in case of a failure while
trying to delete a checkpoint,
// the next iteration will try to delete a comparatively newer
checkpoint and keep the older one in the system (which we don't want).
// The checkpoint that failed to get deleted in this case should
get deleted in the next run.
- counter --;
+ counter--;
}
}
diff --git
a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncCheckpointCreatorTest.java
b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncCheckpointCreatorTest.java
index c569c78b59..497fd8fcaf 100644
---
a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncCheckpointCreatorTest.java
+++
b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncCheckpointCreatorTest.java
@@ -32,10 +32,12 @@ public class AsyncCheckpointCreatorTest {
NodeStore store = new MemoryNodeStore();
int minConcurrentCheckpoints = 3;
int maxConcurrentCheckpoints = 5;
- AsyncCheckpointCreator task = new AsyncCheckpointCreator(store,
"test", 1000, minConcurrentCheckpoints, maxConcurrentCheckpoints);
+ AsyncCheckpointCreator task = new AsyncCheckpointCreator(
+ store, "test", 1000, minConcurrentCheckpoints,
maxConcurrentCheckpoints);
Map<Integer, String> checkpointMap = new LinkedHashMap<>();
for (int i = 0; i < minConcurrentCheckpoints; i++) {
List<String> checkpointList = new ArrayList<>();
+ sleepOneMillisecond();
task.run();
for(String checkpoint : store.checkpoints()) {
if (!checkpointMap.containsValue(checkpoint)) {
@@ -47,14 +49,36 @@ public class AsyncCheckpointCreatorTest {
}
// Task run post the minConcurrentCheckpoints should not result in
additional
// checkpoints since the oldest checkpoint should get deleted
- for (int j = 0; j < 2 ; j++) {
+ for (int j = 0; j < 2; j++) {
List<String> checkpointList = new ArrayList<>();
+ sleepOneMillisecond();
task.run();
- for(String checkpoint : store.checkpoints()) {
+ for (String checkpoint : store.checkpoints()) {
checkpointList.add(checkpoint);
}
Assert.assertFalse(checkpointList.contains(checkpointMap.get(j +
1)));
Assert.assertEquals(minConcurrentCheckpoints,
checkpointList.size());
}
}
+
+ /**
+ * The "oldest" checkpoint is removed, but for this to work reliably, the
+ * checkpoints need to be at least 1 ms apart. So here we wait at least 1
ms,
+ * such that the checkpoints are not on the same millisecond. This is a
bit a
+ * hack, but I think it's safer to change the test case than to change the
code.
+ */
+ private static void sleepOneMillisecond() {
+ long start = System.currentTimeMillis();
+ while (true) {
+ try {
+ Thread.sleep(1);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ long time = System.currentTimeMillis();
+ if (time - start >= 1) {
+ break;
+ }
+ }
+ }
}