Make waiting for leveling more robust in LeveledCompactionStrategyTest

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


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

Branch: refs/heads/trunk
Commit: 3ea34aa3fdc69c8a9c4b9f2e33f96ee689d8aac8
Parents: 9654994
Author: Marcus Eriksson <marc...@apache.org>
Authored: Thu Feb 11 08:38:12 2016 +0100
Committer: Marcus Eriksson <marc...@apache.org>
Committed: Thu Feb 11 08:38:12 2016 +0100

----------------------------------------------------------------------
 .../LeveledCompactionStrategyTest.java          | 25 +++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/3ea34aa3/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java
----------------------------------------------------------------------
diff --git 
a/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java
 
b/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java
index cb9cbb4..7d33c11 100644
--- 
a/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java
+++ 
b/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java
@@ -119,10 +119,29 @@ public class LeveledCompactionStrategyTest extends 
SchemaLoader
      */
     private void waitForLeveling(ColumnFamilyStore cfs) throws 
InterruptedException
     {
-        WrappingCompactionStrategy strategy = (WrappingCompactionStrategy) 
cfs.getCompactionStrategy();
-        // L0 is the lowest priority, so when that's done, we know everything 
is done
-        while (strategy.getSSTableCountPerLevel()[0] > 1)
+        WrappingCompactionStrategy strategyManager = 
(WrappingCompactionStrategy)cfs.getCompactionStrategy();
+        while (true)
+        {
+            // since we run several compaction strategies we wait until L0 in 
all strategies is empty and
+            // atleast one L1+ is non-empty. In these tests we always run a 
single data directory with only unrepaired data
+            // so it should be good enough
+            boolean allL0Empty = true;
+            boolean anyL1NonEmpty = false;
+            for (AbstractCompactionStrategy strategy : 
strategyManager.getWrappedStrategies())
+            {
+                if (!(strategy instanceof LeveledCompactionStrategy))
+                    return;
+                // note that we check > 1 here, if there is too little data in 
L0, we don't compact it up to L1
+                if (((LeveledCompactionStrategy)strategy).getLevelSize(0) > 1)
+                    allL0Empty = false;
+                for (int i = 1; i < 5; i++)
+                    if (((LeveledCompactionStrategy)strategy).getLevelSize(i) 
> 0)
+                        anyL1NonEmpty = true;
+            }
+            if (allL0Empty && anyL1NonEmpty)
+                return;
             Thread.sleep(100);
+        }
     }
 
     @Test

Reply via email to