Skip to content

Commit

Permalink
LedgerManagerIteratorTest: avoid ledger collision
Browse files Browse the repository at this point in the history
For the non-LHLM managers, the ledger space seems to be small enough to
allow collisions to occasionally cause a test failure.  Remember
created ledgers to avoid collisions.

(bug W-5104859)
Signed-off-by: Samuel Just <sjustsalesforce.com>

Author: Samuel Just <sjust@salesforce.com>

Reviewers: Charan Reddy Guttapalem <reddycharan18@gmail.com>, Sijie Guo <sijie@apache.org>

This closes #1526 from athanatos/forupstream/wip-ledger-manager-iterator-test
  • Loading branch information
Samuel Just authored and sijie committed Jun 20, 2018
1 parent cf89f25 commit 28dee84
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.bookkeeper.util.MathUtils;
import org.apache.bookkeeper.util.ZkUtils;
import org.apache.bookkeeper.versioning.Version;
import org.apache.mina.util.ConcurrentHashSet;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooDefs;
import org.junit.After;
Expand Down Expand Up @@ -414,6 +415,7 @@ public void checkConcurrentModifications() throws Throwable {
final long start = MathUtils.nowInNano();
final CountDownLatch latch = new CountDownLatch(1);
ArrayList<Thread> threads = new ArrayList<>();
final ConcurrentHashSet<Long> createdLedgers = new ConcurrentHashSet<>();
for (int i = 0; i < numWriters; ++i) {
Thread thread = new Thread(safeWrapper(() -> {
LedgerManager writerLM = getIndependentLedgerManager();
Expand All @@ -431,7 +433,7 @@ public void checkConcurrentModifications() throws Throwable {
if (!longRange) {
candidate %= 1000000;
}
} while (mustExist.contains(candidate));
} while (mustExist.contains(candidate) || !createdLedgers.add(candidate));
try {
createLedger(writerLM, candidate, Optional.empty());
removeLedger(writerLM, candidate, Optional.empty());
Expand Down

0 comments on commit 28dee84

Please sign in to comment.