http://git-wip-us.apache.org/repos/asf/cassandra/blob/a991b648/test/unit/org/apache/cassandra/cql3/CQLTester.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/CQLTester.java 
b/test/unit/org/apache/cassandra/cql3/CQLTester.java
index 4b4631e..2e8f3b3 100644
--- a/test/unit/org/apache/cassandra/cql3/CQLTester.java
+++ b/test/unit/org/apache/cassandra/cql3/CQLTester.java
@@ -18,6 +18,7 @@
 package org.apache.cassandra.cql3;
 
 import java.io.File;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.net.InetAddress;
@@ -29,20 +30,14 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import com.datastax.driver.core.*;
+import com.datastax.driver.core.ResultSet;
 import com.google.common.base.Objects;
 import com.google.common.collect.ImmutableSet;
 import org.junit.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static junit.framework.Assert.assertNotNull;
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.ColumnDefinitions;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ProtocolVersion;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.datastax.driver.core.Session;
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.concurrent.ScheduledExecutors;
 import org.apache.cassandra.config.CFMetaData;
@@ -50,15 +45,13 @@ import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.cql3.functions.FunctionName;
 import org.apache.cassandra.cql3.statements.ParsedStatement;
-import org.apache.cassandra.db.Directories;
-import org.apache.cassandra.db.Keyspace;
-import org.apache.cassandra.db.SystemKeyspace;
+import org.apache.cassandra.db.*;
+import org.apache.cassandra.db.commitlog.CommitLog;
 import org.apache.cassandra.db.marshal.*;
 import org.apache.cassandra.db.marshal.TupleType;
-import org.apache.cassandra.exceptions.CassandraException;
-import org.apache.cassandra.exceptions.ConfigurationException;
-import org.apache.cassandra.exceptions.SyntaxException;
 import org.apache.cassandra.dht.Murmur3Partitioner;
+import org.apache.cassandra.exceptions.*;
+import org.apache.cassandra.gms.Gossiper;
 import org.apache.cassandra.io.util.FileUtils;
 import org.apache.cassandra.serializers.TypeSerializer;
 import org.apache.cassandra.service.ClientState;
@@ -69,6 +62,8 @@ import org.apache.cassandra.transport.Server;
 import org.apache.cassandra.transport.messages.ResultMessage;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
+import static junit.framework.Assert.assertNotNull;
+
 /**
  * Base class for CQL tests.
  */
@@ -88,8 +83,11 @@ public abstract class CQLTester
     private static final Cluster[] cluster;
     private static final Session[] session;
 
+    private static boolean isServerPrepared = false;
+
     public static int maxProtocolVersion;
-    static {
+    static
+    {
         int version;
         for (version = 1; version <= Server.CURRENT_VERSION; )
         {
@@ -108,7 +106,7 @@ public abstract class CQLTester
         session = new Session[maxProtocolVersion];
 
         // Once per-JVM is enough
-        SchemaLoader.prepareServer();
+        prepareServer(true);
 
         nativeAddr = InetAddress.getLoopbackAddress();
 
@@ -137,13 +135,90 @@ public abstract class CQLTester
     // is not expected to be the same without preparation)
     private boolean usePrepared = USE_PREPARED_VALUES;
 
+    public static void prepareServer(boolean checkInit)
+    {
+        if (checkInit && isServerPrepared)
+            return;
+
+        // Cleanup first
+        try
+        {
+            cleanupAndLeaveDirs();
+        }
+        catch (IOException e)
+        {
+            logger.error("Failed to cleanup and recreate directories.");
+            throw new RuntimeException(e);
+        }
+
+        Thread.setDefaultUncaughtExceptionHandler(new 
Thread.UncaughtExceptionHandler()
+        {
+            public void uncaughtException(Thread t, Throwable e)
+            {
+                logger.error("Fatal exception in thread " + t, e);
+            }
+        });
+
+        Keyspace.setInitialized();
+        isServerPrepared = true;
+    }
+
+    public static void cleanupAndLeaveDirs() throws IOException
+    {
+        // We need to stop and unmap all CLS instances prior to cleanup() or 
we'll get failures on Windows.
+        CommitLog.instance.stopUnsafe(true);
+        mkdirs();
+        cleanup();
+        mkdirs();
+        CommitLog.instance.startUnsafe();
+    }
+
+    public static void cleanup()
+    {
+        // clean up commitlog
+        String[] directoryNames = { DatabaseDescriptor.getCommitLogLocation(), 
};
+        for (String dirName : directoryNames)
+        {
+            File dir = new File(dirName);
+            if (!dir.exists())
+                throw new RuntimeException("No such directory: " + 
dir.getAbsolutePath());
+            FileUtils.deleteRecursive(dir);
+        }
+
+        cleanupSavedCaches();
+
+        // clean up data directory which are stored as data 
directory/keyspace/data files
+        for (String dirName : DatabaseDescriptor.getAllDataFileLocations())
+        {
+            File dir = new File(dirName);
+            if (!dir.exists())
+                throw new RuntimeException("No such directory: " + 
dir.getAbsolutePath());
+            FileUtils.deleteRecursive(dir);
+        }
+    }
+
+    public static void mkdirs()
+    {
+        DatabaseDescriptor.createAllDirectories();
+    }
+
+    public static void cleanupSavedCaches()
+    {
+        File cachesDir = new File(DatabaseDescriptor.getSavedCachesLocation());
+
+        if (!cachesDir.exists() || !cachesDir.isDirectory())
+            return;
+
+        FileUtils.delete(cachesDir.listFiles());
+    }
+
     @BeforeClass
     public static void setUpClass()
     {
         if (ROW_CACHE_SIZE_IN_MB > 0)
             DatabaseDescriptor.setRowCacheSizeInMB(ROW_CACHE_SIZE_IN_MB);
 
-        DatabaseDescriptor.setPartitioner(Murmur3Partitioner.instance);
+        
StorageService.instance.setPartitionerUnsafe(Murmur3Partitioner.instance);
     }
 
     @AfterClass
@@ -271,13 +346,21 @@ public abstract class CQLTester
         return list.isEmpty() ? Collections.<String>emptyList() : new 
ArrayList<>(list);
     }
 
+    public ColumnFamilyStore getCurrentColumnFamilyStore()
+    {
+        String currentTable = currentTable();
+        return currentTable == null
+             ? null
+             : Keyspace.open(KEYSPACE).getColumnFamilyStore(currentTable);
+    }
+
     public void flush()
     {
         try
         {
-            String currentTable = currentTable();
-            if (currentTable != null)
-                
Keyspace.open(KEYSPACE).getColumnFamilyStore(currentTable).forceFlush().get();
+            ColumnFamilyStore store = getCurrentColumnFamilyStore();
+            if (store != null)
+                store.forceFlush().get();
         }
         catch (InterruptedException | ExecutionException e)
         {
@@ -570,17 +653,22 @@ public abstract class CQLTester
         UntypedResultSet rs;
         if (usePrepared)
         {
-            logger.info("Executing: {} with values {}", query, 
formatAllValues(values));
+            if (logger.isDebugEnabled())
+                logger.debug("Executing: {} with values {}", query, 
formatAllValues(values));
             rs = QueryProcessor.executeOnceInternal(query, 
transformValues(values));
         }
         else
         {
             query = replaceValues(query, values);
-            logger.info("Executing: {}", query);
+            if (logger.isDebugEnabled())
+                logger.debug("Executing: {}", query);
             rs = QueryProcessor.executeOnceInternal(query);
         }
         if (rs != null)
-            logger.info("Got {} rows", rs.size());
+        {
+            if (logger.isDebugEnabled())
+                logger.debug("Got {} rows", rs.size());
+        }
         return rs;
     }
 
@@ -642,7 +730,7 @@ public abstract class CQLTester
                                         rows.length>i ? "less" : "more", 
rows.length, i, protocolVersion), i == rows.length);
     }
 
-    protected void assertRows(UntypedResultSet result, Object[]... rows)
+    public static void assertRows(UntypedResultSet result, Object[]... rows)
     {
         if (result == null)
         {
@@ -690,7 +778,7 @@ public abstract class CQLTester
                 iter.next();
                 i++;
             }
-            Assert.fail(String.format("Got less rows than expected. Expected 
%d but got %d.", rows.length, i));
+            Assert.fail(String.format("Got more rows than expected. Expected 
%d but got %d.", rows.length, i));
         }
 
         Assert.assertTrue(String.format("Got %s rows than expected. Expected 
%d but got %d", rows.length>i ? "less" : "more", rows.length, i), i == 
rows.length);
@@ -778,7 +866,7 @@ public abstract class CQLTester
         assertRows(execute("SELECT * FROM %s"), rows);
     }
 
-    protected Object[] row(Object... expected)
+    public static Object[] row(Object... expected)
     {
         return expected;
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a991b648/test/unit/org/apache/cassandra/cql3/ColumnConditionTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/ColumnConditionTest.java 
b/test/unit/org/apache/cassandra/cql3/ColumnConditionTest.java
index c8b3a2f..9a768de 100644
--- a/test/unit/org/apache/cassandra/cql3/ColumnConditionTest.java
+++ b/test/unit/org/apache/cassandra/cql3/ColumnConditionTest.java
@@ -17,27 +17,28 @@
  */
 package org.apache.cassandra.cql3;
 
+import java.nio.ByteBuffer;
+import java.util.*;
+
+import org.junit.Test;
+
 import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.config.ColumnDefinition;
-import org.apache.cassandra.db.BufferCell;
-import org.apache.cassandra.db.Cell;
-import org.apache.cassandra.db.composites.*;
+import org.apache.cassandra.db.LivenessInfo;
+import org.apache.cassandra.db.rows.AbstractCell;
+import org.apache.cassandra.db.rows.Cell;
+import org.apache.cassandra.db.rows.CellPath;
 import org.apache.cassandra.db.marshal.*;
 import org.apache.cassandra.exceptions.InvalidRequestException;
 import org.apache.cassandra.serializers.Int32Serializer;
 import org.apache.cassandra.utils.ByteBufferUtil;
-import org.junit.Test;
-
-import java.nio.ByteBuffer;
-import java.util.*;
 
-import static org.apache.cassandra.utils.ByteBufferUtil.UNSET_BYTE_BUFFER;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
 public class ColumnConditionTest
 {
+    public static ByteBuffer UNSET_BYTE_BUFFER = ByteBuffer.wrap(new byte[]{});
+
     public static final ByteBuffer ZERO = Int32Type.instance.fromString("0");
     public static final ByteBuffer ONE = Int32Type.instance.fromString("1");
     public static final ByteBuffer TWO = Int32Type.instance.fromString("2");
@@ -50,11 +51,10 @@ public class ColumnConditionTest
         Cell cell = null;
         if (columnValue != null)
         {
-            CompoundSparseCellNameType nameType = new 
CompoundSparseCellNameType(Collections.EMPTY_LIST);
-            ColumnDefinition definition = new ColumnDefinition("ks", "cf", new 
ColumnIdentifier("c", true), Int32Type.instance, null, null, null, null, null);
-            cell = new BufferCell(nameType.create(Composites.EMPTY, 
definition), columnValue);
+            ColumnDefinition definition = ColumnDefinition.regularDef("ks", 
"cf", "c", ListType.getInstance(Int32Type.instance, true), null);
+            cell = new TestCell(definition, null, columnValue, 
LivenessInfo.NONE);
         }
-        return bound.isSatisfiedByValue(conditionValue, cell, 
Int32Type.instance, bound.operator, 1234);
+        return bound.isSatisfiedByValue(conditionValue, cell, 
Int32Type.instance, bound.operator);
     }
 
     private static void assertThrowsIRE(ColumnCondition.Bound bound, 
ByteBuffer conditionValue, ByteBuffer columnValue)
@@ -69,7 +69,7 @@ public class ColumnConditionTest
     @Test
     public void testSimpleBoundIsSatisfiedByValue() throws 
InvalidRequestException
     {
-        ColumnDefinition definition = new ColumnDefinition("ks", "cf", new 
ColumnIdentifier("c", true), Int32Type.instance, null, null, null, null, null);
+        ColumnDefinition definition = ColumnDefinition.regularDef("ks", "cf", 
"c", ListType.getInstance(Int32Type.instance, true), null);
 
         // EQ
         ColumnCondition condition = ColumnCondition.condition(definition, new 
Constants.Value(ONE), Operator.EQ);
@@ -83,7 +83,6 @@ public class ColumnConditionTest
         assertTrue(isSatisfiedBy(bound, null, null));
         assertFalse(isSatisfiedBy(bound, ONE, null));
         assertFalse(isSatisfiedBy(bound, null, ONE));
-        assertThrowsIRE(bound, UNSET_BYTE_BUFFER, ONE);
 
         // NEQ
         condition = ColumnCondition.condition(definition, new 
Constants.Value(ONE), Operator.NEQ);
@@ -97,7 +96,6 @@ public class ColumnConditionTest
         assertFalse(isSatisfiedBy(bound, null, null));
         assertTrue(isSatisfiedBy(bound, ONE, null));
         assertTrue(isSatisfiedBy(bound, null, ONE));
-        assertThrowsIRE(bound, UNSET_BYTE_BUFFER, ONE);
 
         // LT
         condition = ColumnCondition.condition(definition, new 
Constants.Value(ONE), Operator.LT);
@@ -110,7 +108,6 @@ public class ColumnConditionTest
         assertFalse(isSatisfiedBy(bound, ByteBufferUtil.EMPTY_BYTE_BUFFER, 
ByteBufferUtil.EMPTY_BYTE_BUFFER));
         assertThrowsIRE(bound, null, ONE);
         assertFalse(isSatisfiedBy(bound, ONE, null));
-        assertThrowsIRE(bound, UNSET_BYTE_BUFFER, ONE);
 
         // LTE
         condition = ColumnCondition.condition(definition, new 
Constants.Value(ONE), Operator.LTE);
@@ -123,7 +120,6 @@ public class ColumnConditionTest
         assertTrue(isSatisfiedBy(bound, ByteBufferUtil.EMPTY_BYTE_BUFFER, 
ByteBufferUtil.EMPTY_BYTE_BUFFER));
         assertThrowsIRE(bound, null, ONE);
         assertFalse(isSatisfiedBy(bound, ONE, null));
-        assertThrowsIRE(bound, UNSET_BYTE_BUFFER, ONE);
 
         // GT
         condition = ColumnCondition.condition(definition, new 
Constants.Value(ONE), Operator.GT);
@@ -136,7 +132,6 @@ public class ColumnConditionTest
         assertFalse(isSatisfiedBy(bound, ByteBufferUtil.EMPTY_BYTE_BUFFER, 
ByteBufferUtil.EMPTY_BYTE_BUFFER));
         assertThrowsIRE(bound, null, ONE);
         assertFalse(isSatisfiedBy(bound, ONE, null));
-        assertThrowsIRE(bound, UNSET_BYTE_BUFFER, ONE);
 
         // GT
         condition = ColumnCondition.condition(definition, new 
Constants.Value(ONE), Operator.GTE);
@@ -149,7 +144,6 @@ public class ColumnConditionTest
         assertTrue(isSatisfiedBy(bound, ByteBufferUtil.EMPTY_BYTE_BUFFER, 
ByteBufferUtil.EMPTY_BYTE_BUFFER));
         assertThrowsIRE(bound, null, ONE);
         assertFalse(isSatisfiedBy(bound, ONE, null));
-        assertThrowsIRE(bound, UNSET_BYTE_BUFFER, ONE);
     }
 
     private static List<ByteBuffer> list(ByteBuffer... values)
@@ -162,7 +156,7 @@ public class ColumnConditionTest
         CFMetaData cfm = CFMetaData.compile("create table foo(a int PRIMARY 
KEY, b int, c list<int>)", "ks");
         Map<ByteBuffer, CollectionType> typeMap = new HashMap<>();
         typeMap.put(ByteBufferUtil.bytes("c"), 
ListType.getInstance(Int32Type.instance, true));
-        CompoundSparseCellNameType.WithCollection nameType = new 
CompoundSparseCellNameType.WithCollection(Collections.EMPTY_LIST, 
ColumnToCollectionType.getInstance(typeMap));
+
         ColumnDefinition definition = new ColumnDefinition(cfm, 
ByteBufferUtil.bytes("c"), ListType.getInstance(Int32Type.instance, true), 0, 
ColumnDefinition.Kind.REGULAR);
 
         List<Cell> cells = new ArrayList<>(columnValues.size());
@@ -172,7 +166,7 @@ public class ColumnConditionTest
             {
                 ByteBuffer key = Int32Serializer.instance.serialize(i);
                 ByteBuffer value = columnValues.get(i);
-                cells.add(new BufferCell(nameType.create(Composites.EMPTY, 
definition, key), value));
+                cells.add(new TestCell(definition, CellPath.create(key), 
value, LivenessInfo.NONE));
             };
         }
 
@@ -183,7 +177,7 @@ public class ColumnConditionTest
     // sets use the same check as lists
     public void testListCollectionBoundAppliesTo() throws 
InvalidRequestException
     {
-        ColumnDefinition definition = new ColumnDefinition("ks", "cf", new 
ColumnIdentifier("c", true), ListType.getInstance(Int32Type.instance, true), 
null, null, null, null, null);
+        ColumnDefinition definition = ColumnDefinition.regularDef("ks", "cf", 
"c", ListType.getInstance(Int32Type.instance, true), null);
 
         // EQ
         ColumnCondition condition = ColumnCondition.condition(definition, 
null, new Lists.Value(Arrays.asList(ONE)), Operator.EQ);
@@ -294,7 +288,6 @@ public class ColumnConditionTest
         CFMetaData cfm = CFMetaData.compile("create table foo(a int PRIMARY 
KEY, b int, c set<int>)", "ks");
         Map<ByteBuffer, CollectionType> typeMap = new HashMap<>();
         typeMap.put(ByteBufferUtil.bytes("c"), 
SetType.getInstance(Int32Type.instance, true));
-        CompoundSparseCellNameType.WithCollection nameType = new 
CompoundSparseCellNameType.WithCollection(Collections.EMPTY_LIST, 
ColumnToCollectionType.getInstance(typeMap));
         ColumnDefinition definition = new ColumnDefinition(cfm, 
ByteBufferUtil.bytes("c"), SetType.getInstance(Int32Type.instance, true), 0, 
ColumnDefinition.Kind.REGULAR);
 
         List<Cell> cells = new ArrayList<>(columnValues.size());
@@ -303,7 +296,7 @@ public class ColumnConditionTest
             for (int i = 0; i < columnValues.size(); i++)
             {
                 ByteBuffer key = columnValues.get(i);
-                cells.add(new BufferCell(nameType.create(Composites.EMPTY, 
definition, key), ByteBufferUtil.EMPTY_BYTE_BUFFER));
+                cells.add(new TestCell(definition, CellPath.create(key), 
ByteBufferUtil.EMPTY_BYTE_BUFFER, LivenessInfo.NONE));
             };
         }
 
@@ -313,7 +306,7 @@ public class ColumnConditionTest
     @Test
     public void testSetCollectionBoundAppliesTo() throws 
InvalidRequestException
     {
-        ColumnDefinition definition = new ColumnDefinition("ks", "cf", new 
ColumnIdentifier("c", true), SetType.getInstance(Int32Type.instance, true), 
null, null, null, null, null);
+        ColumnDefinition definition = ColumnDefinition.regularDef("ks", "cf", 
"c", ListType.getInstance(Int32Type.instance, true), null);
 
         // EQ
         ColumnCondition condition = ColumnCondition.condition(definition, 
null, new Sets.Value(set(ONE)), Operator.EQ);
@@ -427,14 +420,13 @@ public class ColumnConditionTest
         CFMetaData cfm = CFMetaData.compile("create table foo(a int PRIMARY 
KEY, b map<int, int>)", "ks");
         Map<ByteBuffer, CollectionType> typeMap = new HashMap<>();
         typeMap.put(ByteBufferUtil.bytes("b"), 
MapType.getInstance(Int32Type.instance, Int32Type.instance, true));
-        CompoundSparseCellNameType.WithCollection nameType = new 
CompoundSparseCellNameType.WithCollection(Collections.EMPTY_LIST, 
ColumnToCollectionType.getInstance(typeMap));
         ColumnDefinition definition = new ColumnDefinition(cfm, 
ByteBufferUtil.bytes("b"), MapType.getInstance(Int32Type.instance, 
Int32Type.instance, true), 0, ColumnDefinition.Kind.REGULAR);
 
         List<Cell> cells = new ArrayList<>(columnValues.size());
         if (columnValues != null)
         {
             for (Map.Entry<ByteBuffer, ByteBuffer> entry : 
columnValues.entrySet())
-                cells.add(new BufferCell(nameType.create(Composites.EMPTY, 
definition, entry.getKey()), entry.getValue()));
+                cells.add(new TestCell(definition, 
CellPath.create(entry.getKey()), entry.getValue(), LivenessInfo.NONE));
         }
 
         return bound.mapAppliesTo(MapType.getInstance(Int32Type.instance, 
Int32Type.instance, true), cells.iterator(), conditionValues, bound.operator);
@@ -443,7 +435,7 @@ public class ColumnConditionTest
     @Test
     public void testMapCollectionBoundIsSatisfiedByValue() throws 
InvalidRequestException
     {
-        ColumnDefinition definition = new ColumnDefinition("ks", "cf", new 
ColumnIdentifier("b", true), MapType.getInstance(Int32Type.instance, 
Int32Type.instance, true), null, null, null, null, null);
+        ColumnDefinition definition = ColumnDefinition.regularDef("ks", "cf", 
"c", ListType.getInstance(Int32Type.instance, true), null);
 
         Map<ByteBuffer, ByteBuffer> placeholderMap = new TreeMap<>();
         placeholderMap.put(ONE, ONE);
@@ -581,4 +573,45 @@ public class ColumnConditionTest
         assertTrue(mapAppliesTo(bound, map(ByteBufferUtil.EMPTY_BYTE_BUFFER, 
ONE), map(ByteBufferUtil.EMPTY_BYTE_BUFFER, ONE)));
         assertTrue(mapAppliesTo(bound, map(ONE, 
ByteBufferUtil.EMPTY_BYTE_BUFFER), map(ONE, ByteBufferUtil.EMPTY_BYTE_BUFFER)));
     }
-}
\ No newline at end of file
+
+    static class TestCell extends AbstractCell
+    {
+        private final ColumnDefinition column;
+        private final CellPath path;
+        private final ByteBuffer value;
+        private final LivenessInfo info;
+
+        public TestCell(ColumnDefinition column, CellPath path, ByteBuffer 
value, LivenessInfo info)
+        {
+            this.column = column;
+            this.path = path;
+            this.value = value;
+            this.info = info.takeAlias();
+        }
+
+        public ColumnDefinition column()
+        {
+            return column;
+        }
+
+        public boolean isCounterCell()
+        {
+            return false;
+        }
+
+        public ByteBuffer value()
+        {
+            return value;
+        }
+
+        public LivenessInfo livenessInfo()
+        {
+            return info;
+        }
+
+        public CellPath path()
+        {
+            return path;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a991b648/test/unit/org/apache/cassandra/cql3/DeleteTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/DeleteTest.java 
b/test/unit/org/apache/cassandra/cql3/DeleteTest.java
index 812d729..0b88586 100644
--- a/test/unit/org/apache/cassandra/cql3/DeleteTest.java
+++ b/test/unit/org/apache/cassandra/cql3/DeleteTest.java
@@ -18,6 +18,11 @@
 package org.apache.cassandra.cql3;
 
 
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
 import com.datastax.driver.core.Cluster;
 import com.datastax.driver.core.PreparedStatement;
 import com.datastax.driver.core.ResultSetFuture;
@@ -26,10 +31,6 @@ import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.service.EmbeddedCassandraService;
-import org.junit.Assert;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
 
 public class DeleteTest extends SchemaLoader
 {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a991b648/test/unit/org/apache/cassandra/cql3/IndexQueryPagingTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/IndexQueryPagingTest.java 
b/test/unit/org/apache/cassandra/cql3/IndexQueryPagingTest.java
new file mode 100644
index 0000000..45994c7
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/IndexQueryPagingTest.java
@@ -0,0 +1,88 @@
+package org.apache.cassandra.cql3;
+
+import org.junit.Test;
+
+import com.datastax.driver.core.Session;
+import com.datastax.driver.core.SimpleStatement;
+import com.datastax.driver.core.Statement;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.dht.Murmur3Partitioner;
+
+public class IndexQueryPagingTest extends CQLTester
+{
+    /*
+     * Some simple tests to verify the behaviour of paging during
+     * 2i queries. We only use a single index type (CompositesIndexOnRegular)
+     * as the code we want to exercise here is in their abstract
+     * base class.
+     */
+
+    @Test
+    public void pagingOnRegularColumn() throws Throwable
+    {
+        createTable("CREATE TABLE %s (" +
+                    " k1 int," +
+                    " v1 int," +
+                    "PRIMARY KEY (k1))");
+        createIndex("CREATE INDEX ON %s(v1)");
+
+        int rowCount = 3;
+        for (int i=0; i<rowCount; i++)
+            execute("INSERT INTO %s (k1, v1) VALUES (?, ?)", i, 0);
+
+        executePagingQuery("SELECT * FROM %s WHERE v1=0", rowCount);
+    }
+
+    @Test
+    public void pagingOnRegularColumnWithPartitionRestriction() throws 
Throwable
+    {
+        createTable("CREATE TABLE %s (" +
+                    " k1 int," +
+                    " c1 int," +
+                    " v1 int," +
+                    "PRIMARY KEY (k1, c1))");
+        createIndex("CREATE INDEX ON %s(v1)");
+
+        int partitions = 3;
+        int rowCount = 3;
+        for (int i=0; i<partitions; i++)
+            for (int j=0; j<rowCount; j++)
+                execute("INSERT INTO %s (k1, c1, v1) VALUES (?, ?, ?)", i, j, 
0);
+
+        executePagingQuery("SELECT * FROM %s WHERE k1=0 AND v1=0", rowCount);
+    }
+
+    @Test
+    public void pagingOnRegularColumnWithClusteringRestrictions() throws 
Throwable
+    {
+        createTable("CREATE TABLE %s (" +
+                    " k1 int," +
+                    " c1 int," +
+                    " v1 int," +
+                    "PRIMARY KEY (k1, c1))");
+        createIndex("CREATE INDEX ON %s(v1)");
+
+        int partitions = 3;
+        int rowCount = 3;
+        for (int i=0; i<partitions; i++)
+            for (int j=0; j<rowCount; j++)
+                execute("INSERT INTO %s (k1, c1, v1) VALUES (?, ?, ?)", i, j, 
0);
+
+        executePagingQuery("SELECT * FROM %s WHERE k1=0 AND c1>=0 AND c1<=3 
AND v1=0", rowCount);
+    }
+
+    private void executePagingQuery(String cql, int rowCount)
+    {
+        // Execute an index query which should return all rows,
+        // setting the fetch size < than the row count. Assert
+        // that all rows are returned, so we know that paging
+        // of the results was involved.
+        Session session = sessionNet(maxProtocolVersion);
+        Statement stmt = new SimpleStatement(String.format(cql, KEYSPACE + "." 
+ currentTable()));
+        stmt.setFetchSize(rowCount - 1);
+        assertEquals(rowCount, session.execute(stmt).all().size());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a991b648/test/unit/org/apache/cassandra/cql3/NonNativeTimestampTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/NonNativeTimestampTest.java 
b/test/unit/org/apache/cassandra/cql3/NonNativeTimestampTest.java
index 80c5e3b..37dc560 100644
--- a/test/unit/org/apache/cassandra/cql3/NonNativeTimestampTest.java
+++ b/test/unit/org/apache/cassandra/cql3/NonNativeTimestampTest.java
@@ -23,63 +23,31 @@ import java.nio.charset.CharacterCodingException;
 import java.util.Arrays;
 import java.util.Collections;
 
-import org.junit.BeforeClass;
 import org.junit.Test;
 
-import org.apache.cassandra.SchemaLoader;
-import org.apache.cassandra.config.Schema;
-import org.apache.cassandra.db.ConsistencyLevel;
-import org.apache.cassandra.exceptions.RequestExecutionException;
-import org.apache.cassandra.exceptions.RequestValidationException;
-import org.apache.cassandra.service.EmbeddedCassandraService;
-import org.apache.cassandra.service.QueryState;
-import org.apache.cassandra.utils.ByteBufferUtil;
-
 import static junit.framework.Assert.assertEquals;
 import static junit.framework.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-public class NonNativeTimestampTest extends SchemaLoader
+public class NonNativeTimestampTest extends CQLTester
 {
-    @BeforeClass
-    public static void setup() throws Exception
-    {
-        Schema.instance.clear();
-        EmbeddedCassandraService cassandra = new EmbeddedCassandraService();
-        cassandra.start();
-    }
-
     @Test
-    public void setServerTimestampForNonCqlNativeStatements() throws 
RequestValidationException, RequestExecutionException
+    public void setServerTimestampForNonCqlNativeStatements() throws Throwable
     {
-        String createKsCQL = "CREATE KEYSPACE non_native_ts_test" +
-                             " WITH REPLICATION = { 'class' : 
'SimpleStrategy', 'replication_factor' : 1 };";
-        String createTableCQL = "CREATE TABLE non_native_ts_test.table_0 (k 
int PRIMARY KEY, v int)";
-        String insertCQL = "INSERT INTO non_native_ts_test.table_0 (k, v) 
values (1, ?)";
-        String selectCQL = "SELECT v, writetime(v) AS wt FROM 
non_native_ts_test.table_0 WHERE k = 1";
+        createTable("CREATE TABLE %s (k int PRIMARY KEY, v int)");
+
+        execute("INSERT INTO %s (k, v) values (1, ?)", 2);
 
-        QueryProcessor.instance.process(createKsCQL,
-                                        QueryState.forInternalCalls(),
-                                        
QueryOptions.forInternalCalls(Collections.<ByteBuffer>emptyList()));
-        QueryProcessor.instance.process(createTableCQL,
-                                        QueryState.forInternalCalls(),
-                                        
QueryOptions.forInternalCalls(Collections.<ByteBuffer>emptyList()));
-        QueryProcessor.instance.process(insertCQL,
-                                        QueryState.forInternalCalls(),
-                                        
QueryOptions.forInternalCalls(ConsistencyLevel.ONE,
-                                                                      
Arrays.asList(ByteBufferUtil.bytes(2))));
-        UntypedResultSet.Row row = 
QueryProcessor.instance.executeInternal(selectCQL).one();
+        UntypedResultSet.Row row = execute("SELECT v, writetime(v) AS wt FROM 
%s WHERE k = 1").one();
         assertEquals(2, row.getInt("v"));
         long timestamp1 = row.getLong("wt");
         assertFalse(timestamp1 == -1l);
 
         // per CASSANDRA-8246 the two updates will have the same (incorrect)
         // timestamp, so reconcilliation is by value and the "older" update 
wins
-        QueryProcessor.instance.process(insertCQL,
-                                        QueryState.forInternalCalls(),
-                                        
QueryOptions.forInternalCalls(ConsistencyLevel.ONE,
-                                                                      
Arrays.asList(ByteBufferUtil.bytes(1))));
-        row = QueryProcessor.executeInternal(selectCQL).one();
+        execute("INSERT INTO %s (k, v) values (1, ?)", 1);
+
+        row = execute("SELECT v, writetime(v) AS wt FROM %s WHERE k = 
1").one();
         assertEquals(1, row.getInt("v"));
         assertTrue(row.getLong("wt") > timestamp1);
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a991b648/test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java 
b/test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java
new file mode 100644
index 0000000..ad0dd7b
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java
@@ -0,0 +1,532 @@
+/*
+ * 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.cql3;
+
+import java.util.*;
+import org.junit.Test;
+
+import static junit.framework.Assert.*;
+
+public class SimpleQueryTest extends CQLTester
+{
+    @Test
+    public void testStaticCompactTables() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k text PRIMARY KEY, v1 int, v2 text) 
WITH COMPACT STORAGE");
+
+        execute("INSERT INTO %s (k, v1, v2) values (?, ?, ?)", "first", 1, 
"value1");
+        execute("INSERT INTO %s (k, v1, v2) values (?, ?, ?)", "second", 2, 
"value2");
+        execute("INSERT INTO %s (k, v1, v2) values (?, ?, ?)", "third", 3, 
"value3");
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ?", "first"),
+            row("first", 1, "value1")
+        );
+
+        assertRows(execute("SELECT v2 FROM %s WHERE k = ?", "second"),
+            row("value2")
+        );
+
+        // Murmur3 order
+        assertRows(execute("SELECT * FROM %s"),
+            row("third",  3, "value3"),
+            row("second", 2, "value2"),
+            row("first",  1, "value1")
+        );
+    }
+
+    @Test
+    public void testDynamicCompactTables() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k text, t int, v text, PRIMARY KEY (k, 
t));");
+
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key", 1, "v11");
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key", 2, "v12");
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key", 3, "v13");
+
+        flush();
+
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key", 4, "v14");
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key", 5, "v15");
+
+        assertRows(execute("SELECT * FROM %s"),
+            row("key",  1, "v11"),
+            row("key",  2, "v12"),
+            row("key",  3, "v13"),
+            row("key",  4, "v14"),
+            row("key",  5, "v15")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t > ?", "key", 3),
+            row("key",  4, "v14"),
+            row("key",  5, "v15")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t >= ? AND t < 
?", "key", 2, 4),
+            row("key",  2, "v12"),
+            row("key",  3, "v13")
+        );
+
+        // Reversed queries
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? ORDER BY t DESC", 
"key"),
+            row("key",  5, "v15"),
+            row("key",  4, "v14"),
+            row("key",  3, "v13"),
+            row("key",  2, "v12"),
+            row("key",  1, "v11")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t > ? ORDER BY t 
DESC", "key", 3),
+            row("key",  5, "v15"),
+            row("key",  4, "v14")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t >= ? AND t < ? 
ORDER BY t DESC", "key", 2, 4),
+            row("key",  3, "v13"),
+            row("key",  2, "v12")
+        );
+    }
+
+    @Test
+    public void testTableWithoutClustering() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k text PRIMARY KEY, v1 int, v2 text);");
+
+        execute("INSERT INTO %s (k, v1, v2) values (?, ?, ?)", "first", 1, 
"value1");
+        execute("INSERT INTO %s (k, v1, v2) values (?, ?, ?)", "second", 2, 
"value2");
+        execute("INSERT INTO %s (k, v1, v2) values (?, ?, ?)", "third", 3, 
"value3");
+
+        flush();
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ?", "first"),
+            row("first", 1, "value1")
+        );
+
+        assertRows(execute("SELECT v2 FROM %s WHERE k = ?", "second"),
+            row("value2")
+        );
+
+        assertRows(execute("SELECT * FROM %s"),
+            row("third",  3, "value3"),
+            row("second", 2, "value2"),
+            row("first",  1, "value1")
+        );
+    }
+
+    @Test
+    public void testTableWithOneClustering() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k text, t int, v1 text, v2 text, PRIMARY 
KEY (k, t));");
+
+        execute("INSERT INTO %s (k, t, v1, v2) values (?, ?, ?, ?)", "key", 1, 
"v11", "v21");
+        execute("INSERT INTO %s (k, t, v1, v2) values (?, ?, ?, ?)", "key", 2, 
"v12", "v22");
+        execute("INSERT INTO %s (k, t, v1, v2) values (?, ?, ?, ?)", "key", 3, 
"v13", "v23");
+
+        flush();
+
+        execute("INSERT INTO %s (k, t, v1, v2) values (?, ?, ?, ?)", "key", 4, 
"v14", "v24");
+        execute("INSERT INTO %s (k, t, v1, v2) values (?, ?, ?, ?)", "key", 5, 
"v15", "v25");
+
+        assertRows(execute("SELECT * FROM %s"),
+            row("key",  1, "v11", "v21"),
+            row("key",  2, "v12", "v22"),
+            row("key",  3, "v13", "v23"),
+            row("key",  4, "v14", "v24"),
+            row("key",  5, "v15", "v25")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t > ?", "key", 3),
+            row("key",  4, "v14", "v24"),
+            row("key",  5, "v15", "v25")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t >= ? AND t < 
?", "key", 2, 4),
+            row("key",  2, "v12", "v22"),
+            row("key",  3, "v13", "v23")
+        );
+
+        // Reversed queries
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? ORDER BY t DESC", 
"key"),
+            row("key",  5, "v15", "v25"),
+            row("key",  4, "v14", "v24"),
+            row("key",  3, "v13", "v23"),
+            row("key",  2, "v12", "v22"),
+            row("key",  1, "v11", "v21")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t > ? ORDER BY t 
DESC", "key", 3),
+            row("key",  5, "v15", "v25"),
+            row("key",  4, "v14", "v24")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t >= ? AND t < ? 
ORDER BY t DESC", "key", 2, 4),
+            row("key",  3, "v13", "v23"),
+            row("key",  2, "v12", "v22")
+        );
+    }
+
+    @Test
+    public void testTableWithReverseClusteringOrder() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k text, t int, v1 text, v2 text, PRIMARY 
KEY (k, t)) WITH CLUSTERING ORDER BY (t DESC);");
+
+        execute("INSERT INTO %s (k, t, v1, v2) values (?, ?, ?, ?)", "key", 1, 
"v11", "v21");
+        execute("INSERT INTO %s (k, t, v1, v2) values (?, ?, ?, ?)", "key", 2, 
"v12", "v22");
+        execute("INSERT INTO %s (k, t, v1, v2) values (?, ?, ?, ?)", "key", 3, 
"v13", "v23");
+
+        flush();
+
+        execute("INSERT INTO %s (k, t, v1, v2) values (?, ?, ?, ?)", "key", 4, 
"v14", "v24");
+        execute("INSERT INTO %s (k, t, v1, v2) values (?, ?, ?, ?)", "key", 5, 
"v15", "v25");
+
+        assertRows(execute("SELECT * FROM %s"),
+            row("key",  5, "v15", "v25"),
+            row("key",  4, "v14", "v24"),
+            row("key",  3, "v13", "v23"),
+            row("key",  2, "v12", "v22"),
+            row("key",  1, "v11", "v21")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? ORDER BY t ASC", 
"key"),
+            row("key",  1, "v11", "v21"),
+            row("key",  2, "v12", "v22"),
+            row("key",  3, "v13", "v23"),
+            row("key",  4, "v14", "v24"),
+            row("key",  5, "v15", "v25")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t > ?", "key", 3),
+            row("key",  5, "v15", "v25"),
+            row("key",  4, "v14", "v24")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t >= ? AND t < 
?", "key", 2, 4),
+            row("key",  3, "v13", "v23"),
+            row("key",  2, "v12", "v22")
+        );
+
+        // Reversed queries
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? ORDER BY t DESC", 
"key"),
+            row("key",  5, "v15", "v25"),
+            row("key",  4, "v14", "v24"),
+            row("key",  3, "v13", "v23"),
+            row("key",  2, "v12", "v22"),
+            row("key",  1, "v11", "v21")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t > ? ORDER BY t 
DESC", "key", 3),
+            row("key",  5, "v15", "v25"),
+            row("key",  4, "v14", "v24")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t >= ? AND t < ? 
ORDER BY t DESC", "key", 2, 4),
+            row("key",  3, "v13", "v23"),
+            row("key",  2, "v12", "v22")
+        );
+    }
+
+    @Test
+    public void testTableWithTwoClustering() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k text, t1 text, t2 int, v text, PRIMARY 
KEY (k, t1, t2));");
+
+        execute("INSERT INTO %s (k, t1, t2, v) values (?, ?, ?, ?)", "key", 
"v1", 1, "v1");
+        execute("INSERT INTO %s (k, t1, t2, v) values (?, ?, ?, ?)", "key", 
"v1", 2, "v2");
+        execute("INSERT INTO %s (k, t1, t2, v) values (?, ?, ?, ?)", "key", 
"v2", 1, "v3");
+        execute("INSERT INTO %s (k, t1, t2, v) values (?, ?, ?, ?)", "key", 
"v2", 2, "v4");
+        execute("INSERT INTO %s (k, t1, t2, v) values (?, ?, ?, ?)", "key", 
"v2", 3, "v5");
+        flush();
+
+        assertRows(execute("SELECT * FROM %s"),
+            row("key",  "v1", 1, "v1"),
+            row("key",  "v1", 2, "v2"),
+            row("key",  "v2", 1, "v3"),
+            row("key",  "v2", 2, "v4"),
+            row("key",  "v2", 3, "v5")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t1 >= ?", "key", 
"v2"),
+            row("key",  "v2", 1, "v3"),
+            row("key",  "v2", 2, "v4"),
+            row("key",  "v2", 3, "v5")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t1 >= ? ORDER BY 
t1 DESC", "key", "v2"),
+            row("key",  "v2", 3, "v5"),
+            row("key",  "v2", 2, "v4"),
+            row("key",  "v2", 1, "v3")
+        );
+    }
+
+    @Test
+    public void testTableWithLargePartition() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k text, t1 int, t2 int, v text, PRIMARY 
KEY (k, t1, t2));");
+
+        for (int t1 = 0; t1 < 20; t1++)
+            for (int t2 = 0; t2 < 10; t2++)
+                execute("INSERT INTO %s (k, t1, t2, v) values (?, ?, ?, ?)", 
"key", t1, t2, "someSemiLargeTextForValue_" + t1 + "_" + t2);
+
+        flush();
+
+        Object[][] expected = new Object[10][];
+        for (int t2 = 0; t2 < 10; t2++)
+            expected[t2] = row("key", 15, t2);
+
+        assertRows(execute("SELECT k, t1, t2 FROM %s WHERE k=? AND t1=?", 
"key", 15), expected);
+
+        Object[][] expectedReverse = new Object[10][];
+        for (int t2 = 9; t2 >= 0; t2--)
+            expectedReverse[9 - t2] = row("key", 15, t2);
+
+        assertRows(execute("SELECT k, t1, t2 FROM %s WHERE k=? AND t1=? ORDER 
BY t1 DESC, t2 DESC", "key", 15), expectedReverse);
+    }
+
+    @Test
+    public void testRowDeletion() throws Throwable
+    {
+        int N = 4;
+
+        createTable("CREATE TABLE %s (k text, t int, v1 text, v2 int, PRIMARY 
KEY (k, t));");
+
+        for (int t = 0; t < N; t++)
+                execute("INSERT INTO %s (k, t, v1, v2) values (?, ?, ?, ?)", 
"key", t, "v" + t, t + 10);
+
+        flush();
+
+        for (int i = 0; i < N / 2; i++)
+            execute("DELETE FROM %s WHERE k=? AND t=?", "key", i * 2);
+
+        Object[][] expected = new Object[N/2][];
+        for (int i = 0; i < N / 2; i++)
+        {
+            int t = i * 2 + 1;
+            expected[i] = row("key", t, "v" + t, t + 10);
+        }
+
+        assertRows(execute("SELECT * FROM %s"), expected);
+    }
+
+    @Test
+    public void testRangeTombstones() throws Throwable
+    {
+        int N = 100;
+
+        createTable("CREATE TABLE %s (k text, t1 int, t2 int, v text, PRIMARY 
KEY (k, t1, t2));");
+
+        for (int t1 = 0; t1 < 3; t1++)
+            for (int t2 = 0; t2 < N; t2++)
+                execute("INSERT INTO %s (k, t1, t2, v) values (?, ?, ?, ?)", 
"key", t1, t2, "someSemiLargeTextForValue_" + t1 + "_" + t2);
+
+        flush();
+
+        execute("DELETE FROM %s WHERE k=? AND t1=?", "key", 1);
+
+        flush();
+
+        Object[][] expected = new Object[2*N][];
+        for (int t2 = 0; t2 < N; t2++)
+        {
+            expected[t2] = row("key", 0, t2, "someSemiLargeTextForValue_0_" + 
t2);
+            expected[N + t2] = row("key", 2, t2, 
"someSemiLargeTextForValue_2_" + t2);
+        }
+
+        assertRows(execute("SELECT * FROM %s"), expected);
+    }
+
+    @Test
+    public void test2ndaryIndexes() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k text, t int, v text, PRIMARY KEY (k, 
t));");
+
+        execute("CREATE INDEX ON %s(v)");
+
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key1", 1, "foo");
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key1", 2, "bar");
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key2", 1, "foo");
+
+        flush();
+
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key2", 2, "foo");
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key2", 3, "bar");
+
+        assertRows(execute("SELECT * FROM %s WHERE v = ?", "foo"),
+            row("key1",  1, "foo"),
+            row("key2",  1, "foo"),
+            row("key2",  2, "foo")
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE v = ?", "bar"),
+            row("key1",  2, "bar"),
+            row("key2",  3, "bar")
+        );
+    }
+
+    @Test
+    public void testStaticColumns() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k text, t int, s text static, v text, 
PRIMARY KEY (k, t));");
+
+        execute("INSERT INTO %s (k, t, v, s) values (?, ?, ?, ?)", "key1", 1, 
"foo1", "st1");
+        execute("INSERT INTO %s (k, t, v, s) values (?, ?, ?, ?)", "key1", 2, 
"foo2", "st2");
+
+        flush();
+
+        execute("INSERT INTO %s (k, t, v, s) values (?, ?, ?, ?)", "key1", 3, 
"foo3", "st3");
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key1", 4, 
"foo4");
+
+        assertRows(execute("SELECT * FROM %s"),
+            row("key1",  1, "st3", "foo1"),
+            row("key1",  2, "st3", "foo2"),
+            row("key1",  3, "st3", "foo3"),
+            row("key1",  4, "st3", "foo4")
+        );
+
+        assertRows(execute("SELECT s FROM %s WHERE k = ?", "key1"),
+            row("st3"),
+            row("st3"),
+            row("st3"),
+            row("st3")
+        );
+
+        assertRows(execute("SELECT DISTINCT s FROM %s WHERE k = ?", "key1"),
+            row("st3")
+        );
+    }
+
+    @Test
+    public void testDistinct() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k text, t int, v text, PRIMARY KEY (k, 
t));");
+
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key1", 1, 
"foo1");
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key1", 2, 
"foo2");
+
+        flush();
+
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key1", 3, 
"foo3");
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key2", 4, 
"foo4");
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key2", 5, 
"foo5");
+
+        assertRows(execute("SELECT DISTINCT k FROM %s"),
+            row("key1"),
+            row("key2")
+        );
+    }
+
+    @Test
+    public void collectionDeletionTest() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k text PRIMARY KEY, s set<int>);");
+
+        execute("INSERT INTO %s (k, s) VALUES (?, ?)", 1, set(1));
+
+        flush();
+
+        execute("INSERT INTO %s (k, s) VALUES (?, ?)", 1, set(2));
+
+        assertRows(execute("SELECT s FROM %s WHERE k = ?", 1),
+            row(set(2))
+        );
+    }
+
+    @Test
+    public void limitWithMultigetTest() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k int PRIMARY KEY, v int);");
+
+        execute("INSERT INTO %s (k, v) VALUES (?, ?)", 0, 0);
+        execute("INSERT INTO %s (k, v) VALUES (?, ?)", 1, 1);
+        execute("INSERT INTO %s (k, v) VALUES (?, ?)", 2, 2);
+        execute("INSERT INTO %s (k, v) VALUES (?, ?)", 3, 3);
+
+        assertRows(execute("SELECT v FROM %s WHERE k IN ? LIMIT ?", list(0, 1, 
2, 3), 2),
+            row(0),
+            row(1)
+        );
+    }
+
+    @Test
+    public void staticDistinctTest() throws Throwable
+    {
+        createTable("CREATE TABLE %s ( k int, p int, s int static, PRIMARY KEY 
(k, p))");
+
+        execute("INSERT INTO %s (k, p) VALUES (?, ?)", 1, 1);
+        execute("INSERT INTO %s (k, p) VALUES (?, ?)", 1, 2);
+
+        assertRows(execute("SELECT k, s FROM %s"),
+            row(1, null),
+            row(1, null)
+        );
+        assertRows(execute("SELECT DISTINCT k, s FROM %s"),
+            row(1, null)
+        );
+        assertRows(execute("SELECT DISTINCT s FROM %s WHERE k=?", 1),
+            row((Object)null)
+        );
+        assertEmpty(execute("SELECT DISTINCT s FROM %s WHERE k=?", 2));
+    }
+
+    @Test
+    public void testCompactStorageUpdateWithNull() throws Throwable
+    {
+        createTable("CREATE TABLE %s (partitionKey int," +
+                "clustering_1 int," +
+                "value int," +
+                " PRIMARY KEY (partitionKey, clustering_1)) WITH COMPACT 
STORAGE");
+
+        execute("INSERT INTO %s (partitionKey, clustering_1, value) VALUES (0, 
0, 0)");
+        execute("INSERT INTO %s (partitionKey, clustering_1, value) VALUES (0, 
1, 1)");
+
+        flush();
+
+        execute("UPDATE %s SET value = ? WHERE partitionKey = ? AND 
clustering_1 = ?", null, 0, 0);
+
+        assertRows(execute("SELECT * FROM %s WHERE partitionKey = ? AND 
(clustering_1) IN ((?), (?))", 0, 0, 1),
+            row(0, 1, 1)
+        );
+    }
+
+    @Test
+    public void test2ndaryIndexBug() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k int, c1 int, c2 int, v int, PRIMARY 
KEY(k, c1, c2))");
+
+        execute("CREATE INDEX v_idx ON %s(v)");
+
+        execute("INSERT INTO %s (k, c1, c2, v) VALUES (?, ?, ?, ?)", 0, 0, 0, 
0);
+        execute("INSERT INTO %s (k, c1, c2, v) VALUES (?, ?, ?, ?)", 0, 1, 0, 
0);
+
+        assertRows(execute("SELECT * FROM %s WHERE v=?", 0),
+            row(0, 0, 0, 0),
+            row(0, 1, 0, 0)
+        );
+
+        flush();
+
+        execute("DELETE FROM %s WHERE k=? AND c1=?", 0, 1);
+
+        flush();
+
+        assertRows(execute("SELECT * FROM %s WHERE v=?", 0),
+            row(0, 0, 0, 0)
+        );
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a991b648/test/unit/org/apache/cassandra/cql3/ThriftCompatibilityTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/ThriftCompatibilityTest.java 
b/test/unit/org/apache/cassandra/cql3/ThriftCompatibilityTest.java
index 7b72ef8..17e50b3 100644
--- a/test/unit/org/apache/cassandra/cql3/ThriftCompatibilityTest.java
+++ b/test/unit/org/apache/cassandra/cql3/ThriftCompatibilityTest.java
@@ -17,14 +17,15 @@
  */
 package org.apache.cassandra.cql3;
 
-import org.apache.cassandra.config.KSMetaData;
-import org.apache.cassandra.db.marshal.Int32Type;
-import org.apache.cassandra.locator.SimpleStrategy;
-import org.apache.cassandra.utils.ByteBufferUtil;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import org.apache.cassandra.SchemaLoader;
+import org.apache.cassandra.config.KSMetaData;
+import org.apache.cassandra.config.Schema;
+import org.apache.cassandra.db.marshal.Int32Type;
+import org.apache.cassandra.locator.SimpleStrategy;
+import org.apache.cassandra.utils.ByteBufferUtil;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
@@ -36,10 +37,10 @@ public class ThriftCompatibilityTest extends SchemaLoader
     {
         // The before class annotation of SchemaLoader will prepare the 
service so no need to do it here
         SchemaLoader.createKeyspace("thriftcompat",
-                                    SimpleStrategy.class,
-                                    KSMetaData.optsWithRF(1),
-                                    jdbcSparseCFMD("thriftcompat", 
"JdbcInteger", Int32Type.instance)
-                                            
.addColumnDefinition(integerColumn("thriftcompat", "JdbcInteger")));
+                SimpleStrategy.class,
+                KSMetaData.optsWithRF(1),
+                SchemaLoader.jdbcCFMD("thriftcompat", "JdbcInteger", 
Int32Type.instance)
+                            .addColumnDefinition(integerColumn("thriftcompat", 
"JdbcInteger")));
     }
 
     private static UntypedResultSet execute(String query)

Reply via email to