You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sn...@apache.org on 2020/05/20 04:31:29 UTC

[cassandra] branch trunk updated: Fixed non-deterministic test in CasWriteTest

This is an automated email from the ASF dual-hosted git repository.

snazy 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 fdcd0df  Fixed non-deterministic test in CasWriteTest
fdcd0df is described below

commit fdcd0dff216d9e1ad242be1a7d5be3ef67044ac3
Author: Gianluca Righetto <gi...@menttis.com>
AuthorDate: Wed May 20 06:30:29 2020 +0200

    Fixed non-deterministic test in CasWriteTest
    
    patch by Gianluca Righetto; reviewed by Ekaterina Dimitrova & Yifan Cai for CASSANDRA-15676
---
 .../cassandra/distributed/test/CasWriteTest.java   | 40 +++++++++++++---------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/test/distributed/org/apache/cassandra/distributed/test/CasWriteTest.java b/test/distributed/org/apache/cassandra/distributed/test/CasWriteTest.java
index 1d886cf..81b52f7 100644
--- a/test/distributed/org/apache/cassandra/distributed/test/CasWriteTest.java
+++ b/test/distributed/org/apache/cassandra/distributed/test/CasWriteTest.java
@@ -32,6 +32,7 @@ import java.util.function.Consumer;
 import java.util.function.Function;
 import java.util.function.Supplier;
 
+import com.google.common.util.concurrent.Uninterruptibles;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Assert;
@@ -249,28 +250,33 @@ public class CasWriteTest extends TestBaseImpl
     @Test
     public void testWriteUnknownResult()
     {
-        while (true)
-        {
-            cluster.filters().reset();
-            int pk = pkGen.getAndIncrement();
-            cluster.filters().verbs(Verb.PAXOS_PROPOSE_REQ.id).from(1).to(3).messagesMatching((from, to, msg) -> {
+        cluster.filters().reset();
+        int pk = pkGen.getAndIncrement();
+        CountDownLatch ready = new CountDownLatch(1);
+        cluster.filters().verbs(Verb.PAXOS_PROPOSE_REQ.id).from(1).to(2, 3).messagesMatching((from, to, msg) -> {
+            if (to == 2)
+            {
                 // Inject a single CAS request in-between prepare and propose phases
                 cluster.coordinator(2).execute(mkCasInsertQuery((a) -> pk, 1, 2),
                                                ConsistencyLevel.QUORUM);
-                return false;
-            }).drop();
-
-            try
-            {
-                cluster.coordinator(1).execute(mkCasInsertQuery((a) -> pk, 1, 1), ConsistencyLevel.QUORUM);
-            }
-            catch (Throwable t)
-            {
-                Assert.assertEquals("Expecting cause to be CasWriteUncertainException",
-                                    CasWriteUnknownResultException.class.getCanonicalName(), t.getClass().getCanonicalName());
-                return;
+                ready.countDown();
+            } else {
+                Uninterruptibles.awaitUninterruptibly(ready);
             }
+            return false;
+        }).drop();
+
+        try
+        {
+            cluster.coordinator(1).execute(mkCasInsertQuery((a) -> pk, 1, 1), ConsistencyLevel.QUORUM);
+        }
+        catch (Throwable t)
+        {
+            Assert.assertEquals("Expecting cause to be CasWriteUnknownResultException",
+                                CasWriteUnknownResultException.class.getCanonicalName(), t.getClass().getCanonicalName());
+            return;
         }
+        Assert.fail("Expecting test to throw a CasWriteUnknownResultException");
     }
 
     // every invokation returns a query with an unique pk


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org