cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r890512 - /incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
Date Mon, 14 Dec 2009 22:37:49 GMT
Author: eevans
Date: Mon Dec 14 22:37:49 2009
New Revision: 890512

URL: http://svn.apache.org/viewvc?rev=890512&view=rev
Log:
unittest that demonstrates bug

Patch by Ramzi Rabah; reviewed by eevans for CASSANDRA-618

Modified:
    incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/tools/SSTableExportTest.java

Modified: incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/tools/SSTableExportTest.java?rev=890512&r1=890511&r2=890512&view=diff
==============================================================================
--- incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
(original)
+++ incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
Mon Dec 14 22:37:49 2009
@@ -25,16 +25,21 @@
 import java.util.Arrays;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.db.ColumnFamily;
+import org.apache.cassandra.db.filter.NamesQueryFilter;
 import org.apache.cassandra.db.filter.QueryPath;
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.io.DataOutputBuffer;
+import org.apache.cassandra.io.SSTableAccessor;
 import org.apache.cassandra.io.SSTableReader;
 import org.apache.cassandra.io.SSTableWriter;
 import static org.apache.cassandra.Util.createTemporarySSTable;
 import static org.apache.cassandra.utils.FBUtilities.hexToBytes;
+import static org.junit.Assert.assertTrue;
+
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 import org.json.simple.JSONValue;
+import org.json.simple.parser.ParseException;
 import org.junit.Test;
 
 public class SSTableExportTest
@@ -118,4 +123,38 @@
         assert Arrays.equals(hexToBytes((String)colA.get(1)), "valA".getBytes());
         assert !(Boolean)colA.get(3);       
     }
+    
+    @Test
+    public void testRoundTripStandardCf() throws IOException, ParseException
+    {
+        File tempSS = createTemporarySSTable("Keyspace1", "Standard1");
+        ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Standard1");
+        IPartitioner<?> partitioner = DatabaseDescriptor.getPartitioner();
+        DataOutputBuffer dob = new DataOutputBuffer();
+        SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2, partitioner);
+        
+        // Add rowA
+        cfamily.addColumn(new QueryPath("Standard1", null, "name".getBytes()), "val".getBytes(),
1, false);
+        ColumnFamily.serializer().serializeWithIndexes(cfamily, dob);
+        writer.append(partitioner.decorateKey("rowA"), dob);
+        dob.reset();
+        cfamily.clear();
+        
+        SSTableReader reader = writer.closeAndOpenReader(0);
+        
+        // Export to JSON and verify
+        File tempJson = File.createTempFile("Standard1", ".json");
+        SSTableExport.export(reader, new PrintStream(tempJson.getPath()));
+        
+        // Import JSON to another SSTable file
+        File tempSS2 = createTemporarySSTable("Keyspace1", "Standard1");
+        SSTableImport.importJson(tempJson.getPath(), "Keyspace1", "Standard1", tempSS2.getPath());
       
+        
+        reader = SSTableAccessor.getSSTableReader(tempSS2.getPath(), DatabaseDescriptor.getPartitioner());
+        NamesQueryFilter qf = new NamesQueryFilter("rowA", new QueryPath("Standard1", null,
null), "name".getBytes());
+        ColumnFamily cf = qf.getSSTableColumnIterator(reader).getColumnFamily();
+        assertTrue(cf != null);
+        assertTrue(Arrays.equals(cf.getColumn("name".getBytes()).value(), hexToBytes("76616c")));
+    }
+    
 }



Mime
View raw message