cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r796106 - in /incubator/cassandra/trunk: src/java/org/apache/cassandra/db/ test/unit/org/apache/cassandra/ test/unit/org/apache/cassandra/db/ test/unit/org/apache/cassandra/service/
Date Tue, 21 Jul 2009 01:35:47 GMT
Author: jbellis
Date: Tue Jul 21 01:35:47 2009
New Revision: 796106

URL: http://svn.apache.org/viewvc?rev=796106&view=rev
Log:
introduce column() compatibility layer to make writing tests a little less verbose.
patch by jbellis; reviewed by Sandeep Tata for CASSANDRA-185

Added:
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/Util.java
Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Column.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnComparatorFactoryTest.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/MultitableTest.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RecoveryManagerTest.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RowTest.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/SuperColumnTest.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/service/CassandraServerTest.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Column.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Column.java?rev=796106&r1=796105&r2=796106&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Column.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Column.java Tue Jul 21 01:35:47
2009
@@ -62,12 +62,12 @@
         this(name, value, 0);
     }
 
-    Column(String name, byte[] value, long timestamp)
+    public Column(String name, byte[] value, long timestamp)
     {
         this(name, value, timestamp, false);
     }
 
-    Column(String name, byte[] value, long timestamp, boolean isDeleted)
+    public Column(String name, byte[] value, long timestamp, boolean isDeleted)
     {
         assert name != null;
         assert value != null;

Added: incubator/cassandra/trunk/test/unit/org/apache/cassandra/Util.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/Util.java?rev=796106&view=auto
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/Util.java (added)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/Util.java Tue Jul 21 01:35:47
2009
@@ -0,0 +1,11 @@
+package org.apache.cassandra;
+
+import org.apache.cassandra.db.Column;
+
+public class Util
+{
+    public static Column column(String name, String value, long timestamp)
+    {
+        return new Column(name, value.getBytes(), timestamp);
+    }
+}

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnComparatorFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnComparatorFactoryTest.java?rev=796106&r1=796105&r2=796106&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnComparatorFactoryTest.java
(original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnComparatorFactoryTest.java
Tue Jul 21 01:35:47 2009
@@ -22,20 +22,22 @@
 
 import org.junit.Test;
 
+import static org.apache.cassandra.Util.column;
+
 public class ColumnComparatorFactoryTest {
     public Comparator<IColumn> nameComparator = ColumnComparatorFactory.getComparator(ColumnComparatorFactory.ComparatorType.NAME);
 
     @Test
     public void testLT() {
-        IColumn col1 = new Column("Column-8");
-        IColumn col2 = new Column("Column-9");
+        IColumn col1 = column("Column-8", "", 0);
+        IColumn col2 = column("Column-9", "", 0);
         assert nameComparator.compare(col1, col2) < 0;
     }
 
     @Test
     public void testGT() {
-        IColumn col1 = new Column("Column-9");
-        IColumn col2 = new Column("Column-10");
+        IColumn col1 = column("Column-9", "", 0);
+        IColumn col2 = column("Column-10", "", 0);
         // tricky -- remember we're comparing _lexically_
         assert nameComparator.compare(col1, col2) > 0;
 	}

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java?rev=796106&r1=796105&r2=796106&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java (original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java Tue
Jul 21 01:35:47 2009
@@ -29,6 +29,7 @@
 import org.apache.cassandra.io.DataInputBuffer;
 import org.apache.cassandra.io.DataOutputBuffer;
 import org.apache.cassandra.db.filter.QueryPath;
+import static org.apache.cassandra.Util.column;
 
 public class ColumnFamilyTest
 {
@@ -90,11 +91,10 @@
     public void testGetColumnCount()
     {
         ColumnFamily cf = ColumnFamily.create("Table1", "Standard1");
-        byte val[] = "sample value".getBytes();
 
-        cf.addColumn(QueryPath.column("col1"), val, 1);
-        cf.addColumn(QueryPath.column("col2"), val, 2);
-        cf.addColumn(QueryPath.column("col1"), val, 3);
+        cf.addColumn(column("col1", "", 1));
+        cf.addColumn(column("col2", "", 2));
+        cf.addColumn(column("col1", "", 3));
 
         assert 2 == cf.getColumnCount();
         assert 2 == cf.getAllColumns().size();
@@ -104,15 +104,12 @@
     public void testTimestamp()
     {
         ColumnFamily cf = ColumnFamily.create("Table1", "Standard1");
-        byte val1[] = "sample 1".getBytes();
-        byte val2[] = "sample 2".getBytes();
-        byte val3[] = "sample 3".getBytes();
-
-        cf.addColumn(QueryPath.column("col1"), val1, 2);
-        cf.addColumn(QueryPath.column("col1"), val2, 2); // same timestamp, new value
-        cf.addColumn(QueryPath.column("col1"), val3, 1); // older timestamp -- should be
ignored
 
-        assert Arrays.equals(val2, cf.getColumn("col1").value());
+        cf.addColumn(column("col1", "val1", 2));
+        cf.addColumn(column("col1", "val2", 2)); // same timestamp, new value
+        cf.addColumn(column("col1", "val3", 1)); // older timestamp -- should be ignored
+
+        assert Arrays.equals("val2".getBytes(), cf.getColumn("col1").value());
     }
 
     @Test
@@ -124,6 +121,7 @@
         byte val[] = "sample value".getBytes();
         byte val2[] = "x value ".getBytes();
 
+        // exercise addColumn(QueryPath, ...)
         cf_new.addColumn(QueryPath.column("col1"), val, 3);
         cf_new.addColumn(QueryPath.column("col2"), val, 4);
 

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/MultitableTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/MultitableTest.java?rev=796106&r1=796105&r2=796106&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/MultitableTest.java (original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/MultitableTest.java Tue Jul
21 01:35:47 2009
@@ -7,6 +7,7 @@
 
 import static org.apache.cassandra.db.TableTest.assertColumns;
 import org.apache.cassandra.CleanupHelper;
+import static org.apache.cassandra.Util.column;
 
 public class MultitableTest extends CleanupHelper
 {
@@ -21,13 +22,13 @@
 
         rm = new RowMutation("Table1", "keymulti");
         cf = ColumnFamily.create("Table1", "Standard1");
-        cf.addColumn(new Column("col1", "val1".getBytes(), 1L));
+        cf.addColumn(column("col1", "val1", 1L));
         rm.add(cf);
         rm.apply();
 
         rm = new RowMutation("Table2", "keymulti");
         cf = ColumnFamily.create("Table2", "Standard1");
-        cf.addColumn(new Column("col2", "val2".getBytes(), 1L));
+        cf.addColumn(column("col2", "val2", 1L));
         rm.add(cf);
         rm.apply();
 

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java?rev=796106&r1=796105&r2=796106&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java
(original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java
Tue Jul 21 01:35:47 2009
@@ -9,6 +9,7 @@
 import org.junit.Test;
 
 import org.apache.cassandra.CleanupHelper;
+import static org.apache.cassandra.Util.column;
 
 public class RecoveryManager2Test extends CleanupHelper
 {
@@ -23,7 +24,7 @@
             String key = "key" + i;
             RowMutation rm = new RowMutation("Table1", key);
             ColumnFamily cf = ColumnFamily.create("Table1", "Standard1");
-            cf.addColumn(new Column("col1", "val1".getBytes(), 1L));
+            cf.addColumn(column("col1", "val1", 1L));
             rm.add(cf);
             rm.apply();
             keys.add(key);

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RecoveryManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RecoveryManagerTest.java?rev=796106&r1=796105&r2=796106&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RecoveryManagerTest.java (original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RecoveryManagerTest.java Tue
Jul 21 01:35:47 2009
@@ -27,6 +27,7 @@
 import org.junit.Test;
 
 import org.apache.cassandra.CleanupHelper;
+import static org.apache.cassandra.Util.column;
 import static org.apache.cassandra.db.TableTest.assertColumns;
 
 public class RecoveryManagerTest extends CleanupHelper
@@ -49,13 +50,13 @@
 
         rm = new RowMutation("Table1", "keymulti");
         cf = ColumnFamily.create("Table1", "Standard1");
-        cf.addColumn(new Column("col1", "val1".getBytes(), 1L));
+        cf.addColumn(column("col1", "val1", 1L));
         rm.add(cf);
         rm.apply();
 
         rm = new RowMutation("Table2", "keymulti");
         cf = ColumnFamily.create("Table2", "Standard3");
-        cf.addColumn(new Column("col2", "val2".getBytes(), 1L));
+        cf.addColumn(column("col2", "val2", 1L));
         rm.add(cf);
         rm.apply();
 

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RowTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RowTest.java?rev=796106&r1=796105&r2=796106&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RowTest.java (original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RowTest.java Tue Jul 21 01:35:47
2009
@@ -24,6 +24,7 @@
 
 import static junit.framework.Assert.assertEquals;
 import org.apache.cassandra.db.filter.QueryPath;
+import static org.apache.cassandra.Util.column;
 
 public class RowTest
 {
@@ -31,7 +32,7 @@
     public void testDiffColumnFamily()
     {
         ColumnFamily cf1 = ColumnFamily.create("Table1", "Standard1");
-        cf1.addColumn(QueryPath.column("one"), "onev".getBytes(), 0);
+        cf1.addColumn(column("one", "onev", 0));
 
         ColumnFamily cf2 = ColumnFamily.create("Table1", "Standard1");
         cf2.delete(0, 0);
@@ -45,7 +46,7 @@
     public void testDiffSuperColumn()
     {
         SuperColumn sc1 = new SuperColumn("one");
-        sc1.addColumn(new Column("subcolumn", "A".getBytes(), 0));
+        sc1.addColumn(column("subcolumn", "A", 0));
 
         SuperColumn sc2 = new SuperColumn("one");
         sc2.markForDeleteAt(0, 0);
@@ -60,15 +61,15 @@
     {
         Row row1 = new Row();
         ColumnFamily cf1 = ColumnFamily.create("Table1", "Standard1");
-        cf1.addColumn(QueryPath.column("one"), "A".getBytes(), 0);
+        cf1.addColumn(column("one", "A", 0));
         row1.addColumnFamily(cf1);
 
         Row row2 = new Row();
         ColumnFamily cf2 = ColumnFamily.create("Table1", "Standard1");
-        cf2.addColumn(QueryPath.column("one"), "B".getBytes(), 1);
-        cf2.addColumn(QueryPath.column("two"), "C".getBytes(), 1);
+        cf2.addColumn(column("one", "B", 1));
+        cf2.addColumn(column("two", "C", 1));
         ColumnFamily cf3 = ColumnFamily.create("Table2", "Standard2");
-        cf3.addColumn(QueryPath.column("three"), "D".getBytes(), 1);
+        cf3.addColumn(column("three", "D", 1));
         row2.addColumnFamily(cf2);
         row2.addColumnFamily(cf3);
 

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/SuperColumnTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/SuperColumnTest.java?rev=796106&r1=796105&r2=796106&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/SuperColumnTest.java (original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/SuperColumnTest.java Tue Jul
21 01:35:47 2009
@@ -22,14 +22,14 @@
 
 import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertNull;
+import static org.apache.cassandra.Util.column;
 
 public class SuperColumnTest
 {   
     @Test
     public void testMissingSubcolumn() {
-    	byte[] val = "sample value".getBytes();
     	SuperColumn sc = new SuperColumn("sc1");
-    	sc.addColumn(new Column("col1",val,1L));
+    	sc.addColumn(column("col1","sample value",1L));
     	assertNotNull(sc.getSubColumn("col1"));
     	assertNull(sc.getSubColumn("col2"));
     }

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java?rev=796106&r1=796105&r2=796106&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java (original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java Tue Jul 21
01:35:47 2009
@@ -26,6 +26,7 @@
 
 import static junit.framework.Assert.*;
 import org.apache.cassandra.CleanupHelper;
+import static org.apache.cassandra.Util.column;
 import org.apache.cassandra.db.filter.NamesQueryFilter;
 import org.apache.cassandra.db.filter.QueryPath;
 import org.apache.cassandra.io.SSTableReader;
@@ -94,9 +95,9 @@
     	RowMutation rm = new RowMutation("Table1", key);
         ColumnFamily cf = ColumnFamily.create("Table1", "Standard1");
         // First write "a", "b", "c"
-        cf.addColumn(new Column("a", "val1".getBytes(), 1L));
-        cf.addColumn(new Column("b", "val2".getBytes(), 1L));
-        cf.addColumn(new Column("c", "val3".getBytes(), 1L));
+        cf.addColumn(column("a", "val1", 1L));
+        cf.addColumn(column("b", "val2", 1L));
+        cf.addColumn(column("c", "val3", 1L));
         rm.add(cf);
         rm.apply();
         
@@ -117,9 +118,9 @@
     {
         RowMutation rm = new RowMutation("Table1",TEST_KEY);
         ColumnFamily cf = ColumnFamily.create("Table1", "Standard1");
-        cf.addColumn(new Column("col1","val1".getBytes(), 1L));
-        cf.addColumn(new Column("col2","val2".getBytes(), 1L));
-        cf.addColumn(new Column("col3","val3".getBytes(), 1L));
+        cf.addColumn(column("col1","val1", 1L));
+        cf.addColumn(column("col2","val2", 1L));
+        cf.addColumn(column("col3","val3", 1L));
         rm.add(cf);
         return rm;
     }
@@ -130,7 +131,7 @@
         Table table = Table.open("Table1");
         RowMutation rm = new RowMutation("Table1", "row1000");
         ColumnFamily cf = ColumnFamily.create("Table1", "Standard2");
-        cf.addColumn(new Column("col1", "val1".getBytes(), 1));
+        cf.addColumn(column("col1", "val1", 1));
         rm.add(cf);
         rm.apply();
 
@@ -171,12 +172,12 @@
             {
                 RowMutation rm = new RowMutation("Table1", ROW);
                 ColumnFamily cf = ColumnFamily.create("Table1", "Standard1");
-                cf.addColumn(new Column("col1", "val1".getBytes(), 1L));
-                cf.addColumn(new Column("col3", "val3".getBytes(), 1L));
-                cf.addColumn(new Column("col4", "val4".getBytes(), 1L));
-                cf.addColumn(new Column("col5", "val5".getBytes(), 1L));
-                cf.addColumn(new Column("col7", "val7".getBytes(), 1L));
-                cf.addColumn(new Column("col9", "val9".getBytes(), 1L));
+                cf.addColumn(column("col1", "val1", 1L));
+                cf.addColumn(column("col3", "val3", 1L));
+                cf.addColumn(column("col4", "val4", 1L));
+                cf.addColumn(column("col5", "val5", 1L));
+                cf.addColumn(column("col7", "val7", 1L));
+                cf.addColumn(column("col9", "val9", 1L));
                 rm.add(cf);
                 rm.apply();
 
@@ -230,21 +231,21 @@
             {
                 RowMutation rm = new RowMutation("Table1", ROW);
                 ColumnFamily cf = ColumnFamily.create("Table1", "Standard1");
-                cf.addColumn(new Column("col1", "val1".getBytes(), 1L));
-                cf.addColumn(new Column("col2", "val2".getBytes(), 1L));
-                cf.addColumn(new Column("col3", "val3".getBytes(), 1L));
-                cf.addColumn(new Column("col4", "val4".getBytes(), 1L));
-                cf.addColumn(new Column("col5", "val5".getBytes(), 1L));
-                cf.addColumn(new Column("col6", "val6".getBytes(), 1L));
+                cf.addColumn(column("col1", "val1", 1L));
+                cf.addColumn(column("col2", "val2", 1L));
+                cf.addColumn(column("col3", "val3", 1L));
+                cf.addColumn(column("col4", "val4", 1L));
+                cf.addColumn(column("col5", "val5", 1L));
+                cf.addColumn(column("col6", "val6", 1L));
                 rm.add(cf);
                 rm.apply();
                 cfStore.forceBlockingFlush();
 
                 rm = new RowMutation("Table1", ROW);
                 cf = ColumnFamily.create("Table1", "Standard1");
-                cf.addColumn(new Column("col1", "valx".getBytes(), 2L));
-                cf.addColumn(new Column("col2", "valx".getBytes(), 2L));
-                cf.addColumn(new Column("col3", "valx".getBytes(), 2L));
+                cf.addColumn(column("col1", "valx", 2L));
+                cf.addColumn(column("col2", "valx", 2L));
+                cf.addColumn(column("col3", "valx", 2L));
                 rm.add(cf);
                 rm.apply();
             }
@@ -277,7 +278,7 @@
         RowMutation rm = new RowMutation("Table1", ROW);
         ColumnFamily cf = ColumnFamily.create("Table1", "Standard1");
         for (int i = 1000; i < 2000; i++)
-            cf.addColumn(new Column("col" + i, ("vvvvvvvvvvvvvvvv" + i).getBytes(), 1L));
+            cf.addColumn(column("col" + i, ("vvvvvvvvvvvvvvvv" + i), 1L));
         rm.add(cf);
         rm.apply();
         cfStore.forceBlockingFlush();
@@ -321,7 +322,7 @@
                 RowMutation rm = new RowMutation("Table1", ROW);
                 ColumnFamily cf = ColumnFamily.create("Table1", "Super1");
                 SuperColumn sc = new SuperColumn("sc1");
-                sc.addColumn(new Column("col1", "val1".getBytes(), 1L));
+                sc.addColumn(column("col1", "val1", 1L));
                 cf.addColumn(sc);
                 rm.add(cf);
                 rm.apply();

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/service/CassandraServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/service/CassandraServerTest.java?rev=796106&r1=796105&r2=796106&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/service/CassandraServerTest.java
(original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/service/CassandraServerTest.java
Tue Jul 21 01:35:47 2009
@@ -31,8 +31,8 @@
         server.start();
 
         try {
-            Column c1 = new Column("c1", "0", 0L);
-            Column c2 = new Column("c2", "0", 0L);
+            Column c1 = column("c1", "0", 0L);
+            Column c2 = column("c2", "0", 0L);
             List<Column> columns = new ArrayList<Column>();
             columns.add(c1);
             columns.add(c2);



Mime
View raw message