cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marc...@apache.org
Subject [02/10] cassandra git commit: Improve checking for minor compactions in CompactionsCQLTest
Date Thu, 11 Feb 2016 08:05:31 GMT
Improve checking for minor compactions in CompactionsCQLTest

Patch by marcuse; reviewed by Sylvain Lebresne for CASSANDRA-11080


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/393c6ec4
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/393c6ec4
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/393c6ec4

Branch: refs/heads/cassandra-2.2
Commit: 393c6ec4ff4a17aab2fb4d159d9f24f44394c3cd
Parents: 3ea34aa
Author: Marcus Eriksson <marcuse@apache.org>
Authored: Fri Jan 29 14:36:47 2016 +0100
Committer: Marcus Eriksson <marcuse@apache.org>
Committed: Thu Feb 11 08:56:14 2016 +0100

----------------------------------------------------------------------
 .../db/compaction/CompactionsCQLTest.java       | 48 ++++++++++----------
 1 file changed, 24 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/393c6ec4/test/unit/org/apache/cassandra/db/compaction/CompactionsCQLTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/compaction/CompactionsCQLTest.java b/test/unit/org/apache/cassandra/db/compaction/CompactionsCQLTest.java
index 46ade76..4553a45 100644
--- a/test/unit/org/apache/cassandra/db/compaction/CompactionsCQLTest.java
+++ b/test/unit/org/apache/cassandra/db/compaction/CompactionsCQLTest.java
@@ -26,9 +26,9 @@ import org.apache.cassandra.cql3.CQLTester;
 import org.apache.cassandra.cql3.UntypedResultSet;
 import org.apache.cassandra.db.ColumnFamilyStore;
 import org.apache.cassandra.db.Keyspace;
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 public class CompactionsCQLTest extends CQLTester
 {
@@ -41,8 +41,7 @@ public class CompactionsCQLTest extends CQLTester
         flush();
         execute("insert into %s (id) values ('1')");
         flush();
-        Thread.sleep(1000);
-        assertTrue(minorWasTriggered(KEYSPACE, currentTable()));
+        waitForMinor(KEYSPACE, currentTable(), 5000, true);
     }
 
     @Test
@@ -54,8 +53,7 @@ public class CompactionsCQLTest extends CQLTester
         flush();
         execute("insert into %s (id) values ('1')");
         flush();
-        Thread.sleep(1000);
-        assertTrue(minorWasTriggered(KEYSPACE, currentTable()));
+        waitForMinor(KEYSPACE, currentTable(), 5000, true);
     }
 
 
@@ -68,8 +66,7 @@ public class CompactionsCQLTest extends CQLTester
         flush();
         execute("insert into %s (id) values ('1')");
         flush();
-        Thread.sleep(1000);
-        assertTrue(minorWasTriggered(KEYSPACE, currentTable()));
+        waitForMinor(KEYSPACE, currentTable(), 5000, true);
     }
 
     @Test
@@ -81,8 +78,7 @@ public class CompactionsCQLTest extends CQLTester
         flush();
         execute("insert into %s (id) values ('1')");
         flush();
-        Thread.sleep(1000);
-        assertFalse(minorWasTriggered(KEYSPACE, currentTable()));
+        waitForMinor(KEYSPACE, currentTable(), 5000, false);
     }
 
     @Test
@@ -96,8 +92,7 @@ public class CompactionsCQLTest extends CQLTester
         flush();
         execute("insert into %s (id) values ('1')");
         flush();
-        Thread.sleep(1000);
-        assertTrue(minorWasTriggered(KEYSPACE, currentTable()));
+        waitForMinor(KEYSPACE, currentTable(), 5000, true);
     }
 
     @Test
@@ -111,8 +106,7 @@ public class CompactionsCQLTest extends CQLTester
         flush();
         execute("insert into %s (id) values ('1')");
         flush();
-        Thread.sleep(1000);
-        assertFalse(minorWasTriggered(KEYSPACE, currentTable()));
+        waitForMinor(KEYSPACE, currentTable(), 5000, false);
     }
 
     @Test
@@ -126,8 +120,7 @@ public class CompactionsCQLTest extends CQLTester
         flush();
         execute("insert into %s (id) values ('1')");
         flush();
-        Thread.sleep(1000);
-        assertFalse(minorWasTriggered(KEYSPACE, currentTable()));
+        waitForMinor(KEYSPACE, currentTable(), 5000, false);
     }
 
     @Test
@@ -141,8 +134,7 @@ public class CompactionsCQLTest extends CQLTester
         flush();
         execute("insert into %s (id) values ('1')");
         flush();
-        Thread.sleep(1000);
-        assertTrue(minorWasTriggered(KEYSPACE, currentTable()));
+        waitForMinor(KEYSPACE, currentTable(), 5000, true);
     }
 
     @Test
@@ -226,15 +218,23 @@ public class CompactionsCQLTest extends CQLTester
         return Keyspace.open(KEYSPACE).getColumnFamilyStore(currentTable());
     }
 
-    private boolean minorWasTriggered(String keyspace, String cf) throws Throwable
+    private void waitForMinor(String keyspace, String cf, long maxWaitTime, boolean shouldFind)
throws Throwable
     {
-        UntypedResultSet res = execute("SELECT * FROM system.compaction_history");
-        boolean minorWasTriggered = false;
-        for (UntypedResultSet.Row r : res)
+        long startTime = System.currentTimeMillis();
+        while (System.currentTimeMillis() - startTime < maxWaitTime)
         {
-            if (r.getString("keyspace_name").equals(keyspace) && r.getString("columnfamily_name").equals(cf))
-                minorWasTriggered = true;
+            UntypedResultSet res = execute("SELECT * FROM system.compaction_history");
+            for (UntypedResultSet.Row r : res)
+            {
+                if (r.getString("keyspace_name").equals(keyspace) && r.getString("columnfamily_name").equals(cf))
+                    if (shouldFind)
+                        return;
+                    else
+                        fail("Found minor compaction");
+            }
+            Thread.sleep(100);
         }
-        return minorWasTriggered;
+        if (shouldFind)
+            fail("No minor compaction triggered in "+maxWaitTime+"ms");
     }
 }


Mime
View raw message