You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2011/09/05 11:23:55 UTC
svn commit: r1165218 - in
/cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/io/sstable:
SSTableSimpleWriterTest.java SSTableWriterTest.java
Author: slebresne
Date: Mon Sep 5 09:23:54 2011
New Revision: 1165218
URL: http://svn.apache.org/viewvc?rev=1165218&view=rev
Log:
Add missing file and fix type from CASSANDRA-3122 commit
Added:
cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/io/sstable/SSTableSimpleWriterTest.java
Modified:
cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTest.java
Added: cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/io/sstable/SSTableSimpleWriterTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/io/sstable/SSTableSimpleWriterTest.java?rev=1165218&view=auto
==============================================================================
--- cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/io/sstable/SSTableSimpleWriterTest.java (added)
+++ cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/io/sstable/SSTableSimpleWriterTest.java Mon Sep 5 09:23:54 2011
@@ -0,0 +1,104 @@
+/**
+ * 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.sstable;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import org.apache.cassandra.CleanupHelper;
+import org.apache.cassandra.Util;
+import org.apache.cassandra.db.*;
+import org.apache.cassandra.db.marshal.IntegerType;
+import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
+import static org.apache.cassandra.utils.ByteBufferUtil.toInt;
+
+public class SSTableSimpleWriterTest extends CleanupHelper
+{
+ @Test
+ public void testSSTableSimpleUnsortedWriter() throws Exception
+ {
+ final int INC = 5;
+ final int NBCOL = 10;
+
+
+ String tablename = "Keyspace1";
+ String cfname = "StandardInteger1";
+
+ Table t = Table.open(tablename); // make sure we create the directory
+ File dir = new File(t.getDataFileLocation(0));
+ assert dir.exists();
+
+ SSTableSimpleUnsortedWriter writer = new SSTableSimpleUnsortedWriter(dir, tablename, cfname, IntegerType.instance, null, 16);
+
+ int k = 0;
+
+ // Adding a few rows first
+ for (; k < 10; ++k)
+ {
+ writer.newRow(bytes("Key" + k));
+ writer.addColumn(bytes(1), bytes("v"), 0);
+ writer.addColumn(bytes(2), bytes("v"), 0);
+ writer.addColumn(bytes(3), bytes("v"), 0);
+ }
+
+
+ // Testing multiple opening of the same row
+ // We'll write column 0, 5, 10, .., on the first row, then 1, 6, 11, ... on the second one, etc.
+ for (int i = 0; i < INC; ++i)
+ {
+ writer.newRow(bytes("Key" + k));
+ for (int j = 0; j < NBCOL; ++j)
+ {
+ writer.addColumn(bytes(i + INC * j), bytes("v"), 1);
+ }
+ }
+ k++;
+
+ // Adding a few more rows
+ for (; k < 20; ++k)
+ {
+ writer.newRow(bytes("Key" + k));
+ writer.addColumn(bytes(1), bytes("v"), 0);
+ writer.addColumn(bytes(2), bytes("v"), 0);
+ writer.addColumn(bytes(3), bytes("v"), 0);
+ }
+
+ writer.close();
+
+ // Now add that newly created files to the column family
+ ColumnFamilyStore cfs = t.getColumnFamilyStore(cfname);
+ cfs.loadNewSSTables();
+
+ // Check we get expected results
+ ColumnFamily cf = Util.getColumnFamily(t, Util.dk("Key10"), cfname);
+ assert cf.getColumnCount() == INC * NBCOL : "expecting " + (INC * NBCOL) + " columns, got " + cf.getColumnCount();
+ int i = 0;
+ for (IColumn c : cf)
+ {
+ assert toInt(c.name()) == i : "Column name should be " + i + ", got " + toInt(c.name());
+ assert c.value().equals(bytes("v"));
+ assert c.timestamp() == 1;
+ ++i;
+ }
+
+ cf = Util.getColumnFamily(t, Util.dk("Key19"), cfname);
+ assert cf.getColumnCount() == 3 : "expecting 3 columns, got " + cf.getColumnCount();
+ }
+}
Modified: cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTest.java?rev=1165218&r1=1165217&r2=1165218&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTest.java (original)
+++ cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTest.java Mon Sep 5 09:23:54 2011
@@ -82,7 +82,7 @@ public class SSTableWriterTest extends C
assert sstr != null;
ColumnFamilyStore cfs = Table.open("Keyspace1").getColumnFamilyStore("Indexed1");
cfs.addSSTable(sstr);
- cfs.buildSecondaryIndexes(cfs.getSSTables(), cfs.getIndexedColumns());
+ cfs.maybeBuildSecondaryIndexes(cfs.getSSTables(), cfs.getIndexedColumns());
IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(1L));
IndexClause clause = new IndexClause(Arrays.asList(expr), ByteBufferUtil.EMPTY_BYTE_BUFFER, 100);