This is an automated email from the ASF dual-hosted git repository.
vinaychella pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push:
new 43c1987 Fix flaky test o.a.c.u.binlog.BinLogTest patch by Yifan Cai;
reviewed by Vinay Chella for CASSANDRA-15797
43c1987 is described below
commit 43c19878e38fbe260f9e6143aa43836e85cf2f44
Author: yifan-c <[email protected]>
AuthorDate: Thu May 21 00:56:52 2020 -0700
Fix flaky test o.a.c.u.binlog.BinLogTest
patch by Yifan Cai; reviewed by Vinay Chella for CASSANDRA-15797
---
.../apache/cassandra/utils/binlog/BinLogTest.java | 59 ++++++++--------------
1 file changed, 21 insertions(+), 38 deletions(-)
diff --git a/test/unit/org/apache/cassandra/utils/binlog/BinLogTest.java
b/test/unit/org/apache/cassandra/utils/binlog/BinLogTest.java
index 9919af3..dbce6a9 100644
--- a/test/unit/org/apache/cassandra/utils/binlog/BinLogTest.java
+++ b/test/unit/org/apache/cassandra/utils/binlog/BinLogTest.java
@@ -23,8 +23,11 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Supplier;
import org.junit.After;
import org.junit.Before;
@@ -40,6 +43,7 @@ import org.apache.cassandra.io.util.FileUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -115,9 +119,10 @@ public class BinLogTest
@Test
public void testBinLogStartStop() throws Exception
{
- Semaphore blockBinLog = new Semaphore(1);
AtomicInteger releaseCount = new AtomicInteger();
- binLog.put(new BinLog.ReleaseableWriteMarshallable()
+ CountDownLatch ready = new CountDownLatch(2);
+ Supplier<BinLog.ReleaseableWriteMarshallable> recordSupplier =
+ () -> new BinLog.ReleaseableWriteMarshallable()
{
public void release()
{
@@ -136,40 +141,13 @@ public class BinLogTest
public void writeMarshallablePayload(WireOut wire)
{
- try
- {
- blockBinLog.acquire();
- }
- catch (InterruptedException e)
- {
- throw new RuntimeException(e);
- }
- }
- });
- binLog.put(new BinLog.ReleaseableWriteMarshallable()
- {
- protected long version()
- {
- return 0;
- }
-
- protected String type()
- {
- return "test";
+ ready.countDown();
}
-
- public void writeMarshallablePayload(WireOut wire)
- {
-
- }
-
- public void release()
- {
- releaseCount.incrementAndGet();
- }
- });
- Thread.sleep(1000);
- assertEquals(2, releaseCount.get());
+ };
+ binLog.put(recordSupplier.get());
+ binLog.put(recordSupplier.get());
+ ready.await(1, TimeUnit.MINUTES);
+ Util.spinAssertEquals("Both records should be released", 2,
releaseCount::get, 10, TimeUnit.SECONDS);
Thread t = new Thread(() -> {
try
{
@@ -182,7 +160,7 @@ public class BinLogTest
});
t.start();
t.join(60 * 1000);
- assertEquals(t.getState(), Thread.State.TERMINATED);
+ assertEquals("BinLog should not take more than 1 minute to stop",
t.getState(), Thread.State.TERMINATED);
Util.spinAssertEquals(2, releaseCount::get, 60);
Util.spinAssertEquals(Thread.State.TERMINATED,
binLog.binLogThread::getState, 60);
@@ -426,9 +404,14 @@ public class BinLogTest
@Test
public void testPutAfterStop() throws Exception
{
+ final BinLog.ReleaseableWriteMarshallable unexpected =
record(testString);
binLog.stop();
- binLog.put(record(testString));
- assertEquals(null, binLog.sampleQueue.poll());
+ binLog.put(unexpected);
+ BinLog.ReleaseableWriteMarshallable record;
+ while (null != (record = binLog.sampleQueue.poll()))
+ {
+ assertNotEquals("A stopped BinLog should no longer accept",
unexpected, record);
+ }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]