Author: thomasm Date: Thu Oct 13 07:33:31 2016 New Revision: 1764611 URL: http://svn.apache.org/viewvc?rev=1764611&view=rev Log: OAK-4522 Improve CommitRateLimiter to optionally block some commits (fix test case; this is actually unrelated to changes in OAK-4522)
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/CommitRateLimiterTest.java Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/CommitRateLimiterTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/CommitRateLimiterTest.java?rev=1764611&r1=1764610&r2=1764611&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/CommitRateLimiterTest.java (original) +++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/CommitRateLimiterTest.java Thu Oct 13 07:33:31 2016 @@ -24,6 +24,7 @@ import static org.junit.Assert.assertSam import static org.junit.Assert.assertTrue; import java.util.concurrent.Callable; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; @@ -60,13 +61,31 @@ public class CommitRateLimiterTest { @Test(expected = CommitFailedException.class) public void blockCommits() throws CommitFailedException, InterruptedException { + // using a latch to avoid having to rely on timing + final CountDownLatch latch = new CountDownLatch(1); + CommitRateLimiter limiter = new CommitRateLimiter() { + @Override + public boolean getBlockCommits() { + // this method is called in the 'try' loop, so it + // that InterruptedException will be converted + // to CommitFailedException as expected + // (sure, this is an implementation detail, + // but I don't see a good alternative here) + latch.countDown(); + return super.getBlockCommits(); + } + }; limiter.blockCommits(); final Thread mainThread = Thread.currentThread(); Thread t = new Thread() { @Override public void run() { try { - Thread.sleep(1000); + // wait forever to avoid timing problems + // (if the CommitRateLimiter is changed to not call + // getBlockCommits(), then this wouldn't work - but + // how could it not call getBlockCommits()?) + latch.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }