Author: jbellis
Date: Mon Jul 19 15:48:48 2010
New Revision: 965537

URL: http://svn.apache.org/viewvc?rev=965537&view=rev
Log:
clean up CFSTest code, and r/m wrapped-range query (see CASSANDRA-1042).  patch 
by jbellis

Modified:
    
cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java

Modified: 
cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java?rev=965537&r1=965536&r2=965537&view=diff
==============================================================================
--- 
cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
 (original)
+++ 
cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
 Mon Jul 19 15:48:48 2010
@@ -19,6 +19,7 @@
 package org.apache.cassandra.db;
 
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.util.*;
 import java.util.concurrent.ExecutionException;
 
@@ -29,6 +30,7 @@ import org.junit.Test;
 import static junit.framework.Assert.assertEquals;
 import org.apache.cassandra.CleanupHelper;
 import org.apache.cassandra.Util;
+import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.WrappedRunnable;
 
@@ -135,47 +137,46 @@ public class ColumnFamilyStoreTest exten
         testAntiCompaction("Standard1", 100);
     }
 
-    @Test
-    public void testWrappedRangeQuery() throws IOException, 
ExecutionException, InterruptedException
+    private RangeSliceReply getRangeSlice(ColumnFamilyStore cfs, Token start, 
Token end) throws IOException, ExecutionException, InterruptedException
     {
-        ColumnFamilyStore cfs = insertKey1Key2();
+        return cfs.getRangeSlice(ArrayUtils.EMPTY_BYTE_ARRAY,
+                                 new Range(start, end),
+                                 10,
+                                 null,
+                                 Arrays.asList("asdf".getBytes()));
+    }
 
-        IPartitioner p = StorageService.getPartitioner();
-        RangeSliceReply result = cfs.getRangeSlice(ArrayUtils.EMPTY_BYTE_ARRAY,
-                                                   new 
Range(p.getToken("key15"), p.getToken("key1")),
-                                                   10,
-                                                   null,
-                                                   
Arrays.asList("asdf".getBytes()));
-        assertEquals(2, result.rows.size());
+    private void assertKeys(List<Row> rows, List<String> keys) throws 
UnsupportedEncodingException
+    {
+        assertEquals(keys.size(), rows.size());
+        for (int i = 0; i < keys.size(); i++)
+        {
+            assertEquals(keys.get(i), rows.get(i).key);
+        }
     }
 
     @Test
     public void testSkipStartKey() throws IOException, ExecutionException, 
InterruptedException
     {
-        ColumnFamilyStore cfs = insertKey1Key2();
-
+        ColumnFamilyStore cfs = insert("key1", "key2");
         IPartitioner p = StorageService.getPartitioner();
-        RangeSliceReply result = cfs.getRangeSlice(ArrayUtils.EMPTY_BYTE_ARRAY,
-                                                   new 
Range(p.getToken("key1"), p.getToken("key2")),
-                                                   10,
-                                                   null,
-                                                   
Arrays.asList("asdf".getBytes()));
-        assertEquals(1, result.rows.size());
-        assert result.rows.get(0).key.equals("key2");
+
+        RangeSliceReply result = getRangeSlice(cfs, p.getToken("key1"), 
p.getToken("key2"));
+        assertKeys(result.rows, Arrays.asList("key2"));
     }
 
-    private ColumnFamilyStore insertKey1Key2() throws IOException, 
ExecutionException, InterruptedException
+    private ColumnFamilyStore insert(String... keys) throws IOException, 
ExecutionException, InterruptedException
     {
         List<RowMutation> rms = new LinkedList<RowMutation>();
         RowMutation rm;
-        rm = new RowMutation("Keyspace2", "key1");
-        rm.add(new QueryPath("Standard1", null, "Column1".getBytes()), 
"asdf".getBytes(), 0);
-        rms.add(rm);
-        Util.writeColumnFamily(rms);
+        for (String key : keys)
+        {
+            rm = new RowMutation("Keyspace2", key);
+            rm.add(new QueryPath("Standard1", null, "Column1".getBytes()), 
"asdf".getBytes(), 0);
+            rms.add(rm);
+        }
 
-        rm = new RowMutation("Keyspace2", "key2");
-        rm.add(new QueryPath("Standard1", null, "Column1".getBytes()), 
"asdf".getBytes(), 0);
-        rms.add(rm);
         return Util.writeColumnFamily(rms);
     }
+
 }


Reply via email to