cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stefa...@apache.org
Subject [2/3] cassandra git commit: Fixed flacky SSTablesIteratedTest
Date Tue, 02 Aug 2016 07:55:51 GMT
Fixed flacky SSTablesIteratedTest

patch by Stefania Alborghetti; reviewed by Sylvain Lebresne for CASSANDRA-12282


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

Branch: refs/heads/trunk
Commit: f5078b19c509d52d32659aef714bf9288540bfc4
Parents: e89028d
Author: Stefania Alborghetti <stefania.alborghetti@datastax.com>
Authored: Thu Jul 28 17:17:30 2016 +0800
Committer: Stefania Alborghetti <stefania.alborghetti@datastax.com>
Committed: Tue Aug 2 15:53:05 2016 +0800

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../org/apache/cassandra/cql3/CQLTester.java    | 39 ++++++++++++++++----
 .../miscellaneous/SSTablesIteratedTest.java     | 25 +++++++++++--
 3 files changed, 53 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5078b19/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 0f6bc50..5647cd4 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.9
+ * Fixed flacky SSTablesIteratedTest (CASSANDRA-12282)
  * Fixed flacky SSTableRewriterTest: check file counts before calling validateCFS (CASSANDRA-12348)
  * cqlsh: Fix handling of $$-escaped strings (CASSANDRA-12189)
  * Fix SSL JMX requiring truststore containing server cert (CASSANDRA-12109)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5078b19/test/unit/org/apache/cassandra/cql3/CQLTester.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/CQLTester.java b/test/unit/org/apache/cassandra/cql3/CQLTester.java
index 7e1516a..19e40d2 100644
--- a/test/unit/org/apache/cassandra/cql3/CQLTester.java
+++ b/test/unit/org/apache/cassandra/cql3/CQLTester.java
@@ -377,10 +377,15 @@ public abstract class CQLTester
 
     public ColumnFamilyStore getCurrentColumnFamilyStore()
     {
+        return getCurrentColumnFamilyStore(KEYSPACE);
+    }
+
+    public ColumnFamilyStore getCurrentColumnFamilyStore(String keyspace)
+    {
         String currentTable = currentTable();
         return currentTable == null
              ? null
-             : Keyspace.open(KEYSPACE).getColumnFamilyStore(currentTable);
+             : Keyspace.open(keyspace).getColumnFamilyStore(currentTable);
     }
 
     public void flush(boolean forceFlush)
@@ -391,14 +396,19 @@ public abstract class CQLTester
 
     public void flush()
     {
-        ColumnFamilyStore store = getCurrentColumnFamilyStore();
+        flush(KEYSPACE);
+    }
+
+    public void flush(String keyspace)
+    {
+        ColumnFamilyStore store = getCurrentColumnFamilyStore(keyspace);
         if (store != null)
             store.forceBlockingFlush();
     }
 
-    public void disableCompaction()
+    public void disableCompaction(String keyspace)
     {
-        ColumnFamilyStore store = getCurrentColumnFamilyStore();
+        ColumnFamilyStore store = getCurrentColumnFamilyStore(keyspace);
         store.disableAutoCompaction();
     }
 
@@ -546,8 +556,13 @@ public abstract class CQLTester
 
     protected String createTable(String query)
     {
+        return createTable(KEYSPACE, query);
+    }
+
+    protected String createTable(String keyspace, String query)
+    {
         String currentTable = createTableName();
-        String fullQuery = formatQuery(query);
+        String fullQuery = formatQuery(keyspace, query);
         logger.info(fullQuery);
         schemaChange(fullQuery);
         return currentTable;
@@ -697,10 +712,15 @@ public abstract class CQLTester
         return sessions.get(protocolVersion);
     }
 
-    private String formatQuery(String query)
+    protected String formatQuery(String query)
+    {
+        return formatQuery(KEYSPACE, query);
+    }
+
+    protected String formatQuery(String keyspace, String query)
     {
         String currentTable = currentTable();
-        return currentTable == null ? query : String.format(query, KEYSPACE + "." + currentTable);
+        return currentTable == null ? query : String.format(query, keyspace + "." + currentTable);
     }
 
     protected ResultMessage.Prepared prepare(String query) throws Throwable
@@ -710,8 +730,11 @@ public abstract class CQLTester
 
     protected UntypedResultSet execute(String query, Object... values) throws Throwable
     {
-        query = formatQuery(query);
+        return executeFormattedQuery(formatQuery(query), values);
+    }
 
+    protected UntypedResultSet executeFormattedQuery(String query, Object... values) throws
Throwable
+    {
         UntypedResultSet rs;
         if (usePrepared)
         {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5078b19/test/unit/org/apache/cassandra/cql3/validation/miscellaneous/SSTablesIteratedTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/miscellaneous/SSTablesIteratedTest.java
b/test/unit/org/apache/cassandra/cql3/validation/miscellaneous/SSTablesIteratedTest.java
index ad7bd15..fd9f221 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/miscellaneous/SSTablesIteratedTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/miscellaneous/SSTablesIteratedTest.java
@@ -25,6 +25,7 @@ import org.junit.Test;
 import static org.junit.Assert.assertEquals;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.cql3.UntypedResultSet;
 import org.apache.cassandra.db.ColumnFamilyStore;
 import org.apache.cassandra.metrics.ClearableHistogram;
 
@@ -36,23 +37,39 @@ public class SSTablesIteratedTest extends CQLTester
 {
     private void executeAndCheck(String query, int numSSTables, Object[]... rows) throws
Throwable
     {
-        ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
+        ColumnFamilyStore cfs = getCurrentColumnFamilyStore(KEYSPACE_PER_TEST);
 
         ((ClearableHistogram) cfs.metric.sstablesPerReadHistogram.cf).clear(); // resets
counts
 
         assertRows(execute(query), rows);
 
-        assertEquals(numSSTables, cfs.metric.sstablesPerReadHistogram.cf.getSnapshot().getMax());
// max sstables read
+        long numSSTablesIterated = cfs.metric.sstablesPerReadHistogram.cf.getSnapshot().getMax();
// max sstables read
+        assertEquals(String.format("Expected %d sstables iterated but got %d instead, with
%d live sstables",
+                                   numSSTables, numSSTablesIterated, cfs.getLiveSSTables().size()),
+                     numSSTables,
+                     numSSTablesIterated);
     }
 
     @Override
     protected String createTable(String query)
     {
-        String ret = super.createTable(query);
-        disableCompaction();
+        String ret = super.createTable(KEYSPACE_PER_TEST, query);
+        disableCompaction(KEYSPACE_PER_TEST);
         return ret;
     }
 
+    @Override
+    protected UntypedResultSet execute(String query, Object... values) throws Throwable
+    {
+        return executeFormattedQuery(formatQuery(KEYSPACE_PER_TEST, query), values);
+    }
+
+    @Override
+    public void flush()
+    {
+        super.flush(KEYSPACE_PER_TEST);
+    }
+
     @Test
     public void testSSTablesOnlyASC() throws Throwable
     {


Mime
View raw message