cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject svn commit: r1153210 [2/2] - in /cassandra/trunk: ./ interface/ interface/thrift/gen-java/org/apache/cassandra/thrift/ lib/ lib/licenses/ src/avro/ src/java/org/apache/cassandra/cli/ src/java/org/apache/cassandra/config/ src/java/org/apache/cassandra/d...
Date Tue, 02 Aug 2011 17:29:10 GMT
Modified: cassandra/trunk/test/unit/org/apache/cassandra/SchemaLoader.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/SchemaLoader.java?rev=1153210&r1=1153209&r2=1153210&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/SchemaLoader.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/SchemaLoader.java Tue Aug  2 17:28:55 2011
@@ -239,10 +239,24 @@ public class SchemaLoader
                 false,
                 standardCFMD(ks_nocommit, "Standard1")));
 
+
+        if (Boolean.parseBoolean(System.getProperty("cassandra.test.compression", "false")))
+            useCompression(schema);
         
         return schema;
     }
 
+    private static void useCompression(List<KSMetaData> schema)
+    {
+        for (KSMetaData ksm : schema)
+        {
+            for (CFMetaData cfm : ksm.cfMetaData().values())
+            {
+                cfm.compression(true);
+            }
+        }
+    }
+
     private static CFMetaData standardCFMD(String ksName, String cfName)
     {
         return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, BytesType.instance,
null).keyCacheSize(0);

Modified: cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java?rev=1153210&r1=1153209&r2=1153210&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java Tue Aug  2 17:28:55 2011
@@ -18,7 +18,6 @@
 
 package org.apache.cassandra.db;
 
-import java.io.File;
 import java.nio.ByteBuffer;
 import java.nio.charset.CharacterCodingException;
 import java.text.DecimalFormat;
@@ -406,7 +405,7 @@ public class TableTest extends CleanupHe
         // verify that we do indeed have multiple index entries
         SSTableReader sstable = cfStore.getSSTables().iterator().next();
         long position = sstable.getPosition(key, SSTableReader.Operator.EQ);
-        RandomAccessReader file = RandomAccessReader.open(new File(sstable.getFilename()));
+        RandomAccessReader file = sstable.openDataReader(false);
         file.seek(position);
         assert ByteBufferUtil.readWithShortLength(file).equals(key.key);
         SSTableReader.readRowSize(file, sstable.descriptor);

Added: cassandra/trunk/test/unit/org/apache/cassandra/io/compress/CompressedRandomAccessReaderTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/io/compress/CompressedRandomAccessReaderTest.java?rev=1153210&view=auto
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/io/compress/CompressedRandomAccessReaderTest.java
(added)
+++ cassandra/trunk/test/unit/org/apache/cassandra/io/compress/CompressedRandomAccessReaderTest.java
Tue Aug  2 17:28:55 2011
@@ -0,0 +1,90 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cassandra.io.compress;
+
+import java.io.*;
+
+import org.junit.Test;
+
+import org.apache.cassandra.io.util.*;
+
+public class CompressedRandomAccessReaderTest
+{
+    @Test
+    public void testResetAndTruncate() throws IOException
+    {
+        // test reset in current buffer or previous one
+        testResetAndTruncate(false, 10);
+        testResetAndTruncate(false, CompressedSequentialWriter.CHUNK_LENGTH);
+    }
+
+    @Test
+    public void testResetAndTruncateCompressed() throws IOException
+    {
+        // test reset in current buffer or previous one
+        testResetAndTruncate(true, 10);
+        testResetAndTruncate(true, CompressedSequentialWriter.CHUNK_LENGTH);
+    }
+
+    private void testResetAndTruncate(boolean compressed, int junkSize) throws IOException
+    {
+        String filename = "corruptFile";
+        File f = new File(filename);
+
+        try
+        {
+            SequentialWriter writer = compressed
+                ? new CompressedSequentialWriter(f, filename + ".metadata", false)
+                : new SequentialWriter(f, CompressedSequentialWriter.CHUNK_LENGTH, false);
+
+            writer.write("The quick ".getBytes());
+            FileMark mark = writer.mark();
+            writer.write("blue fox jumps over the lazy dog".getBytes());
+
+            // write enough to be sure to change chunk
+            for (int i = 0; i < junkSize; ++i)
+            {
+                writer.write((byte)1);
+            }
+
+            writer.resetAndTruncate(mark);
+            writer.write("brown fox jumps over the lazy dog".getBytes());
+            writer.close();
+
+            assert f.exists();
+            RandomAccessReader reader = compressed
+                ? new CompressedRandomAccessReader(filename, new CompressionMetadata(filename
+ ".metadata", f.length()), false)
+                : new RandomAccessReader(f, CompressedSequentialWriter.CHUNK_LENGTH, false);
+            String expected = "The quick brown fox jumps over the lazy dog";
+            assert reader.length() == expected.length();
+            byte[] b = new byte[expected.length()];
+            reader.readFully(b);
+            assert new String(b).equals(expected) : "Expecting '" + expected + "', got '"
+ new String(b) + "'";
+        }
+        finally
+        {
+            // cleanup
+            if (f.exists())
+                f.delete();
+            File metadata = new File(filename + ".metadata");
+            if (compressed && metadata.exists())
+                metadata.delete();
+        }
+    }
+}

Modified: cassandra/trunk/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java?rev=1153210&r1=1153209&r2=1153210&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java Tue Aug  2
17:28:55 2011
@@ -19,7 +19,6 @@
 
 package org.apache.cassandra.io.sstable;
 
-import java.io.File;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.*;
@@ -51,7 +50,7 @@ public class SSTableTest extends Cleanup
 
     private void verifySingle(SSTableReader sstable, ByteBuffer bytes, ByteBuffer key) throws
IOException
     {
-        RandomAccessReader file = RandomAccessReader.open(new File(sstable.getFilename()));
+        RandomAccessReader file = sstable.openDataReader(false);
         file.seek(sstable.getPosition(sstable.partitioner.decorateKey(key), SSTableReader.Operator.EQ));
         assert key.equals(ByteBufferUtil.readWithShortLength(file));
         int size = (int)SSTableReader.readRowSize(file, sstable.descriptor);
@@ -88,7 +87,7 @@ public class SSTableTest extends Cleanup
     {
         List<ByteBuffer> keys = new ArrayList<ByteBuffer>(map.keySet());
         Collections.shuffle(keys);
-        RandomAccessReader file = RandomAccessReader.open(new File(sstable.getFilename()));
+        RandomAccessReader file = sstable.openDataReader(false);
         for (ByteBuffer key : keys)
         {
             file.seek(sstable.getPosition(sstable.partitioner.decorateKey(key), SSTableReader.Operator.EQ));

Modified: cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/Session.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/Session.java?rev=1153210&r1=1153209&r2=1153210&view=diff
==============================================================================
--- cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/Session.java (original)
+++ cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/Session.java Tue Aug  2 17:28:55
2011
@@ -77,6 +77,7 @@ public class Session implements Serializ
         availableOptions.addOption("W",  "no-replicate-on-write",false,  "Set replicate_on_write
to false for counters. Only counter add with CL=ONE will work");
         availableOptions.addOption("V",  "average-size-values",  false,  "Generate column
values of average rather than specific size");
         availableOptions.addOption("T",  "send-to",              true,   "Send this as a
request to the stress daemon at specified address.");
+        availableOptions.addOption("I",  "compression",          false,  "Use sstable compression
when creating schema");
     }
 
     private int numKeys          = 1000 * 1000;
@@ -92,6 +93,7 @@ public class Session implements Serializ
     private int retryTimes       = 10;
     private int port             = 9160;
     private int superColumns     = 1;
+    private boolean compression  = false;
 
     private int progressInterval  = 10;
     private int keysPerCall       = 1000;
@@ -258,6 +260,9 @@ public class Session implements Serializ
             if (cmd.hasOption("W"))
                 replicateOnWrite = false;
 
+            if (cmd.hasOption("I"))
+                compression = true;
+
             averageSizeValues = cmd.hasOption("V");
 
             try
@@ -412,7 +417,8 @@ public class Session implements Serializ
 
         // column family for standard columns
         CfDef standardCfDef = new CfDef("Keyspace1", "Standard1");
-        standardCfDef.setComparator_type("AsciiType").setDefault_validation_class("BytesType");
+        System.out.println("Compression = " + compression);
+        standardCfDef.setComparator_type("AsciiType").setDefault_validation_class("BytesType").setCompression(compression);
         if (indexType != null)
         {
             ColumnDef standardColumn = new ColumnDef(ByteBufferUtil.bytes("C1"), "BytesType");
@@ -422,13 +428,13 @@ public class Session implements Serializ
 
         // column family with super columns
         CfDef superCfDef = new CfDef("Keyspace1", "Super1").setColumn_type("Super");
-        superCfDef.setComparator_type("AsciiType").setSubcomparator_type("AsciiType").setDefault_validation_class("BytesType");
+        superCfDef.setComparator_type("AsciiType").setSubcomparator_type("AsciiType").setDefault_validation_class("BytesType").setCompression(compression);
 
         // column family for standard counters
-        CfDef counterCfDef = new CfDef("Keyspace1", "Counter1").setDefault_validation_class("CounterColumnType").setReplicate_on_write(replicateOnWrite);
+        CfDef counterCfDef = new CfDef("Keyspace1", "Counter1").setDefault_validation_class("CounterColumnType").setReplicate_on_write(replicateOnWrite).setCompression(compression);
 
         // column family with counter super columns
-        CfDef counterSuperCfDef = new CfDef("Keyspace1", "SuperCounter1").setDefault_validation_class("CounterColumnType").setReplicate_on_write(replicateOnWrite).setColumn_type("Super");
+        CfDef counterSuperCfDef = new CfDef("Keyspace1", "SuperCounter1").setDefault_validation_class("CounterColumnType").setReplicate_on_write(replicateOnWrite).setColumn_type("Super").setCompression(compression);
 
         keyspace.setName("Keyspace1");
         keyspace.setStrategy_class(replicationStrategy);



Mime
View raw message