Skip to content

Commit e1f655b

Browse files
authored
fixes periodic failure with CompactionIT (apache#4201)
The test CompactionIT.testConcurrentSplit() would periodically fail because it relied on the old behavior of WaitFor. Changed the test to use custom code that waits up to three seconds for a condition to be met and then continues.
1 parent 1d51e46 commit e1f655b

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

test/src/main/java/org/apache/accumulo/test/functional/CompactionIT.java

+21-12
Original file line numberDiff line numberDiff line change
@@ -472,12 +472,17 @@ public void testConcurrentSplit() throws Exception {
472472
splits.add(new Text(String.format("r:%04d", i)));
473473
}
474474

475-
// wait a bit for some tablets to have files selected, it possible the compaction have
476-
// completed before this so do not wait long
477-
Wait.waitFor(
478-
() -> countTablets(tableName, tabletMetadata -> tabletMetadata.getSelectedFiles() != null)
479-
> 0,
480-
3000, 10);
475+
// Wait a bit for some tablets to have files selected, it possible the compaction have
476+
// completed before this so do not wait long. Once files are selected compactions can start.
477+
// This speed bump is an attempt to increase the chance that splits and compactions run
478+
// concurrently. Wait.waitFor() is not used here because it will throw an exception if the
479+
// time limit is exceeded.
480+
long startTime = System.nanoTime();
481+
while (System.nanoTime() - startTime < SECONDS.toNanos(3)
482+
&& countTablets(tableName, tabletMetadata -> tabletMetadata.getSelectedFiles() != null)
483+
== 0) {
484+
Thread.sleep(10);
485+
}
481486

482487
// add 10 more splits to the table
483488
c.tableOperations().addSplits(tableName, splits);
@@ -487,12 +492,16 @@ public void testConcurrentSplit() throws Exception {
487492
splits.add(new Text(String.format("r:%04d", i)));
488493
}
489494

490-
// wait a bit for some tablets to be compacted, it possible the compaction have completed
491-
// before this so do not wait long
492-
Wait.waitFor(
493-
() -> countTablets(tableName, tabletMetadata -> !tabletMetadata.getCompacted().isEmpty())
494-
> 0,
495-
3000, 10);
495+
// Wait a bit for some tablets to be compacted, it possible the compaction have completed
496+
// before this so do not wait long. Wait.waitFor() is not used here because it will throw an
497+
// exception if the time limit is exceeded. This is just a speed bump, its ok if the condition
498+
// is not met within the time limit.
499+
startTime = System.nanoTime();
500+
while (System.nanoTime() - startTime < SECONDS.toNanos(3)
501+
&& countTablets(tableName, tabletMetadata -> !tabletMetadata.getCompacted().isEmpty())
502+
== 0) {
503+
Thread.sleep(10);
504+
}
496505

497506
// add 80 more splits to the table
498507
c.tableOperations().addSplits(tableName, splits);

0 commit comments

Comments
 (0)