cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marc...@apache.org
Subject [1/2] cassandra git commit: Fix LeveledCompactionStrategyTest with compression
Date Wed, 15 Apr 2015 10:15:37 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 ca0761404 -> 306de09af


Fix LeveledCompactionStrategyTest with compression

Patch by marcuse; reviewed by thobbs for CASSANDRA-9139


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

Branch: refs/heads/cassandra-2.1
Commit: 1fab099892db08a0edb4b1ad48a8ffd6b3dfd5e8
Parents: a5bae1f
Author: Marcus Eriksson <marcuse@apache.org>
Authored: Fri Apr 10 09:34:55 2015 +0200
Committer: Marcus Eriksson <marcuse@apache.org>
Committed: Wed Apr 15 02:32:28 2015 +0200

----------------------------------------------------------------------
 .../org/apache/cassandra/io/sstable/SSTable.java    | 12 ++++++++++--
 .../compaction/LeveledCompactionStrategyTest.java   | 16 ++++++++++------
 2 files changed, 20 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/1fab0998/src/java/org/apache/cassandra/io/sstable/SSTable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTable.java b/src/java/org/apache/cassandra/io/sstable/SSTable.java
index 69c6521..6ec4ace 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTable.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTable.java
@@ -266,9 +266,17 @@ public abstract class SSTable
     {
         long sum = 0;
         for (SSTableReader sstable : sstables)
-        {
             sum += sstable.onDiskLength();
-        }
+
+        return sum;
+    }
+
+    public static long getTotalUncompressedBytes(Iterable<SSTableReader> sstables)
+    {
+        long sum = 0;
+        for (SSTableReader sstable : sstables)
+            sum += sstable.uncompressedLength();
+
         return sum;
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/1fab0998/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 b60f6d9..33de6f5 100644
--- a/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java
+++ b/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java
@@ -22,6 +22,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Random;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.UUID;
@@ -63,8 +64,9 @@ public class LeveledCompactionStrategyTest extends SchemaLoader
         String cfname = "StandardLeveled";
         Keyspace keyspace = Keyspace.open(ksname);
         ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);
-
-        ByteBuffer value = ByteBuffer.wrap(new byte[100 * 1024]); // 100 KB value, make it
easy to have multiple files
+        byte [] b = new byte[100 * 1024];
+        new Random().nextBytes(b);
+        ByteBuffer value = ByteBuffer.wrap(b); // 100 KB value, make it easy to have multiple
files
 
         // Enough data to have a level 1 and 2
         int rows = 20;
@@ -86,8 +88,8 @@ public class LeveledCompactionStrategyTest extends SchemaLoader
         waitForLeveling(cfs);
         LeveledCompactionStrategy strategy = (LeveledCompactionStrategy) cfs.getCompactionStrategy();
         // Checking we're not completely bad at math
-        assert strategy.getLevelSize(1) > 0;
-        assert strategy.getLevelSize(2) > 0;
+        assertTrue(strategy.getLevelSize(1) > 0);
+        assertTrue(strategy.getLevelSize(2) > 0);
 
         Range<Token> range = new Range<Token>(Util.token(""), Util.token(""));
         int gcBefore = keyspace.getColumnFamilyStore(cfname).gcBefore(System.currentTimeMillis());
@@ -116,7 +118,9 @@ public class LeveledCompactionStrategyTest extends SchemaLoader
         ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);
 
         // make sure we have SSTables in L1
-        ByteBuffer value = ByteBuffer.wrap(new byte[100 * 1024]);
+        byte [] b = new byte[100 * 1024];
+        new Random().nextBytes(b);
+        ByteBuffer value = ByteBuffer.wrap(b);
         int rows = 2;
         int columns = 10;
         for (int r = 0; r < rows; r++)
@@ -145,7 +149,7 @@ public class LeveledCompactionStrategyTest extends SchemaLoader
             scanner.next();
 
         // scanner.getCurrentPosition should be equal to total bytes of L1 sstables
-        assert scanner.getCurrentPosition() == SSTable.getTotalBytes(sstables);
+        assertEquals(scanner.getCurrentPosition(), SSTable.getTotalUncompressedBytes(sstables));
     }
 
     @Test


Mime
View raw message