You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jm...@apache.org on 2015/06/24 18:14:45 UTC
[06/31] cassandra git commit: Migrate CQL tests from dtest to unit
tests
http://git-wip-us.apache.org/repos/asf/cassandra/blob/f797bfa4/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 662800b..6f0e439 100644
--- a/test/unit/org/apache/cassandra/cql3/ThriftCompatibilityTest.java
+++ b/test/unit/org/apache/cassandra/cql3/ThriftCompatibilityTest.java
@@ -23,6 +23,7 @@ import org.junit.Test;
import org.apache.cassandra.SchemaLoader;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
public class ThriftCompatibilityTest extends SchemaLoader
{
http://git-wip-us.apache.org/repos/asf/cassandra/blob/f797bfa4/test/unit/org/apache/cassandra/cql3/TimestampTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/TimestampTest.java b/test/unit/org/apache/cassandra/cql3/TimestampTest.java
deleted file mode 100644
index 6673904..0000000
--- a/test/unit/org/apache/cassandra/cql3/TimestampTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 org.junit.Test;
-
-public class TimestampTest extends CQLTester
-{
- @Test
- public void testNegativeTimestamps() throws Throwable
- {
- createTable("CREATE TABLE %s (k int PRIMARY KEY, v int)");
-
- execute("INSERT INTO %s (k, v) VALUES (?, ?) USING TIMESTAMP ?", 1, 1, -42L);
- assertRows(execute("SELECT writetime(v) FROM %s WHERE k = ?", 1),
- row(-42L)
- );
-
- assertInvalid("INSERT INTO %s (k, v) VALUES (?, ?) USING TIMESTAMP ?", 2, 2, Long.MIN_VALUE);
- }
-}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/f797bfa4/test/unit/org/apache/cassandra/cql3/TupleTypeTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/TupleTypeTest.java b/test/unit/org/apache/cassandra/cql3/TupleTypeTest.java
deleted file mode 100644
index ce935e3..0000000
--- a/test/unit/org/apache/cassandra/cql3/TupleTypeTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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 org.junit.Test;
-
-public class TupleTypeTest extends CQLTester
-{
- @Test
- public void testTuplePutAndGet() throws Throwable
- {
- String[] valueTypes = {"frozen<tuple<int, text, double>>", "tuple<int, text, double>"};
- for (String valueType : valueTypes)
- {
- createTable("CREATE TABLE %s (k int PRIMARY KEY, t " + valueType + ")");
-
- execute("INSERT INTO %s (k, t) VALUES (?, ?)", 0, tuple(3, "foo", 3.4));
- execute("INSERT INTO %s (k, t) VALUES (?, ?)", 1, tuple(8, "bar", 0.2));
- assertAllRows(
- row(0, tuple(3, "foo", 3.4)),
- row(1, tuple(8, "bar", 0.2))
- );
-
- // nulls
- execute("INSERT INTO %s (k, t) VALUES (?, ?)", 2, tuple(5, null, 3.4));
- assertRows(execute("SELECT * FROM %s WHERE k=?", 2),
- row(2, tuple(5, null, 3.4))
- );
-
- // incomplete tuple
- execute("INSERT INTO %s (k, t) VALUES (?, ?)", 3, tuple(5, "bar"));
- assertRows(execute("SELECT * FROM %s WHERE k=?", 3),
- row(3, tuple(5, "bar"))
- );
- }
- }
-
- @Test
- public void testNestedTuple() throws Throwable
- {
- createTable("CREATE TABLE %s (k int PRIMARY KEY, t frozen<tuple<int, tuple<text, double>>>)");
-
- execute("INSERT INTO %s (k, t) VALUES (?, ?)", 0, tuple(3, tuple("foo", 3.4)));
- execute("INSERT INTO %s (k, t) VALUES (?, ?)", 1, tuple(8, tuple("bar", 0.2)));
- assertAllRows(
- row(0, tuple(3, tuple("foo", 3.4))),
- row(1, tuple(8, tuple("bar", 0.2)))
- );
- }
-
- @Test
- public void testTupleInPartitionKey() throws Throwable
- {
- createTable("CREATE TABLE %s (t frozen<tuple<int, text>> PRIMARY KEY)");
-
- execute("INSERT INTO %s (t) VALUES (?)", tuple(3, "foo"));
- assertAllRows(row(tuple(3, "foo")));
- }
-
- @Test
- public void testTupleInClusteringKey() throws Throwable
- {
- createTable("CREATE TABLE %s (k int, t frozen<tuple<int, text>>, PRIMARY KEY (k, t))");
-
- execute("INSERT INTO %s (k, t) VALUES (?, ?)", 0, tuple(5, "bar"));
- execute("INSERT INTO %s (k, t) VALUES (?, ?)", 0, tuple(3, "foo"));
- execute("INSERT INTO %s (k, t) VALUES (?, ?)", 0, tuple(6, "bar"));
- execute("INSERT INTO %s (k, t) VALUES (?, ?)", 0, tuple(5, "foo"));
-
- assertAllRows(
- row(0, tuple(3, "foo")),
- row(0, tuple(5, "bar")),
- row(0, tuple(5, "foo")),
- row(0, tuple(6, "bar"))
- );
- }
-
- @Test
- public void testInvalidQueries() throws Throwable
- {
- createTable("CREATE TABLE %s (k int PRIMARY KEY, t frozen<tuple<int, text, double>>)");
-
- assertInvalidSyntax("INSERT INTO %s (k, t) VALUES (0, ())");
- assertInvalid("INSERT INTO %s (k, t) VALUES (0, (2, 'foo', 3.1, 'bar'))");
- }
-}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/f797bfa4/test/unit/org/apache/cassandra/cql3/TypeTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/TypeTest.java b/test/unit/org/apache/cassandra/cql3/TypeTest.java
deleted file mode 100644
index ec82d41..0000000
--- a/test/unit/org/apache/cassandra/cql3/TypeTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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 org.apache.cassandra.exceptions.ConfigurationException;
-import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-public class TypeTest extends CQLTester
-{
- @Test
- public void testNowToUUIDCompatibility() throws Throwable
- {
- createTable("CREATE TABLE %s (a int, b uuid, PRIMARY KEY (a, b))");
- execute("INSERT INTO %s (a, b) VALUES (0, now())");
- UntypedResultSet results = execute("SELECT * FROM %s WHERE a=0 AND b < now()");
- assertEquals(1, results.size());
- }
-
- @Test
- public void testDateCompatibility() throws Throwable
- {
- createTable("CREATE TABLE %s (a int, b timestamp, c bigint, d varint, PRIMARY KEY (a, b, c, d))");
- execute("INSERT INTO %s (a, b, c, d) VALUES (0, unixTimestampOf(now()), dateOf(now()), dateOf(now()))");
- UntypedResultSet results = execute("SELECT * FROM %s WHERE a=0 AND b < unixTimestampOf(now())");
- assertEquals(1, results.size());
- }
-
- @Test
- public void testReversedTypeCompatibility() throws Throwable
- {
- createTable("CREATE TABLE %s (a int, b timeuuid, PRIMARY KEY (a, b)) WITH CLUSTERING ORDER BY (b DESC)");
- execute("INSERT INTO %s (a, b) VALUES (0, now())");
- UntypedResultSet results = execute("SELECT * FROM %s WHERE a=0 AND b < now()");
- assertEquals(1, results.size());
- }
-
- @Test
- // tests CASSANDRA-7797
- public void testAlterReversedColumn() throws Throwable
- {
- createTable("CREATE TABLE IF NOT EXISTS %s (a int, b 'org.apache.cassandra.db.marshal.DateType', PRIMARY KEY (a, b)) WITH CLUSTERING ORDER BY (b DESC)");
- alterTable("ALTER TABLE %s ALTER b TYPE 'org.apache.cassandra.db.marshal.ReversedType(org.apache.cassandra.db.marshal.TimestampType)'");
- }
-
- @Test
- public void testIncompatibleReversedTypes() throws Throwable
- {
- createTable("CREATE TABLE IF NOT EXISTS %s (a int, b 'org.apache.cassandra.db.marshal.DateType', PRIMARY KEY (a, b)) WITH CLUSTERING ORDER BY (b DESC)");
- try
- {
- alterTable("ALTER TABLE %s ALTER b TYPE 'org.apache.cassandra.db.marshal.ReversedType(org.apache.cassandra.db.marshal.TimeUUIDType)'");
- fail("Expected error for ALTER statement");
- }
- catch (RuntimeException e) { }
- }
-
- @Test
- public void testReversedAndNonReversed() throws Throwable
- {
- createTable("CREATE TABLE IF NOT EXISTS %s (a int, b 'org.apache.cassandra.db.marshal.DateType', PRIMARY KEY (a, b))");
- try
- {
- alterTable("ALTER TABLE %s ALTER b TYPE 'org.apache.cassandra.db.marshal.ReversedType(org.apache.cassandra.db.marshal.DateType)'");
- fail("Expected error for ALTER statement");
- }
- catch (RuntimeException e) { }
- }
-}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/f797bfa4/test/unit/org/apache/cassandra/cql3/UseStatementTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/UseStatementTest.java b/test/unit/org/apache/cassandra/cql3/UseStatementTest.java
deleted file mode 100644
index 66b4b42..0000000
--- a/test/unit/org/apache/cassandra/cql3/UseStatementTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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 org.junit.Test;
-
-public class UseStatementTest extends CQLTester
-{
- @Test
- public void testUseStatementWithBindVariable() throws Throwable
- {
- assertInvalidSyntaxMessage("Bind variables cannot be used for keyspace names", "USE ?");
- }
-}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/f797bfa4/test/unit/org/apache/cassandra/cql3/UserTypesTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/UserTypesTest.java b/test/unit/org/apache/cassandra/cql3/UserTypesTest.java
deleted file mode 100644
index c820ece..0000000
--- a/test/unit/org/apache/cassandra/cql3/UserTypesTest.java
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
- * 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 org.junit.Test;
-
-public class UserTypesTest extends CQLTester
-{
- @Test
- public void testInvalidField() throws Throwable
- {
- String myType = createType("CREATE TYPE %s (f int)");
- createTable("CREATE TABLE %s (k int PRIMARY KEY, v frozen<" + myType + ">)");
-
- // 's' is not a field of myType
- assertInvalid("INSERT INTO %s (k, v) VALUES (?, {s : ?})", 0, 1);
- }
-
- @Test
- public void testCassandra8105() throws Throwable
- {
- String ut1 = createType("CREATE TYPE %s (a int, b int)");
- String ut2 = createType("CREATE TYPE %s (j frozen<" + KEYSPACE + "." + ut1 + ">, k int)");
- createTable("CREATE TABLE %s (x int PRIMARY KEY, y set<frozen<" + KEYSPACE + "." + ut2 + ">>)");
- execute("INSERT INTO %s (x, y) VALUES (1, { { k: 1 } })");
-
- String ut3 = createType("CREATE TYPE %s (a int, b int)");
- String ut4 = createType("CREATE TYPE %s (j frozen<" + KEYSPACE + "." + ut3 + ">, k int)");
- createTable("CREATE TABLE %s (x int PRIMARY KEY, y list<frozen<" + KEYSPACE + "." + ut4 + ">>)");
- execute("INSERT INTO %s (x, y) VALUES (1, [ { k: 1 } ])");
-
- String ut5 = createType("CREATE TYPE %s (a int, b int)");
- String ut6 = createType("CREATE TYPE %s (i int, j frozen<" + KEYSPACE + "." + ut5 + ">)");
- createTable("CREATE TABLE %s (x int PRIMARY KEY, y set<frozen<" + KEYSPACE + "." + ut6 + ">>)");
- execute("INSERT INTO %s (x, y) VALUES (1, { { i: 1 } })");
- }
-
- @Test
- public void testFor7684() throws Throwable
- {
- String myType = createType("CREATE TYPE %s (x double)");
- createTable("CREATE TABLE %s (k int, v frozen<" + myType + ">, b boolean static, PRIMARY KEY (k, v))");
-
- execute("INSERT INTO %s(k, v) VALUES (?, {x:?})", 1, -104.99251);
- execute("UPDATE %s SET b = ? WHERE k = ?", true, 1);
-
- assertRows(execute("SELECT v.x FROM %s WHERE k = ? AND v = {x:?}", 1, -104.99251),
- row(-104.99251)
- );
-
- flush();
-
- assertRows(execute("SELECT v.x FROM %s WHERE k = ? AND v = {x:?}", 1, -104.99251),
- row(-104.99251)
- );
- }
-
- @Test
- public void testCreateInvalidTablesWithUDT() throws Throwable
- {
- String myType = createType("CREATE TYPE %s (f int)");
-
- // Using a UDT without frozen shouldn't work
- assertInvalidMessage("Non-frozen User-Defined types are not supported, please use frozen<>",
- "CREATE TABLE " + KEYSPACE + ".wrong (k int PRIMARY KEY, v " + KEYSPACE + '.' + myType + ")");
-
- assertInvalidMessage("Statement on keyspace " + KEYSPACE + " cannot refer to a user type in keyspace otherkeyspace;" +
- " user types can only be used in the keyspace they are defined in",
- "CREATE TABLE " + KEYSPACE + ".wrong (k int PRIMARY KEY, v frozen<otherKeyspace.myType>)");
-
- assertInvalidMessage("Unknown type " + KEYSPACE + ".unknowntype",
- "CREATE TABLE " + KEYSPACE + ".wrong (k int PRIMARY KEY, v frozen<" + KEYSPACE + '.' + "unknownType>)");
- }
-
- @Test
- public void testAlterUDT() throws Throwable
- {
- String myType = KEYSPACE + '.' + createType("CREATE TYPE %s (a int)");
- createTable("CREATE TABLE %s (a int PRIMARY KEY, b frozen<" + myType + ">)");
- execute("INSERT INTO %s (a, b) VALUES (1, {a: 1})");
-
- assertRows(execute("SELECT b.a FROM %s"), row(1));
-
- flush();
-
- execute("ALTER TYPE " + myType + " ADD b int");
- execute("INSERT INTO %s (a, b) VALUES (2, {a: 2, b :2})");
-
- assertRows(execute("SELECT b.a, b.b FROM %s"),
- row(1, null),
- row(2, 2));
-
- flush();
-
- assertRows(execute("SELECT b.a, b.b FROM %s"),
- row(1, null),
- row(2, 2));
- }
-
- @Test
- public void testAlteringUserTypeNestedWithinMap() throws Throwable
- {
- // test frozen and non-frozen collections
- String[] columnTypePrefixes = {"frozen<map<text, ", "map<text, frozen<"};
- for (String columnTypePrefix : columnTypePrefixes)
- {
- String ut1 = createType("CREATE TYPE %s (a int)");
- String columnType = columnTypePrefix + KEYSPACE + "." + ut1 + ">>";
-
- createTable("CREATE TABLE %s (x int PRIMARY KEY, y " + columnType + ")");
-
- execute("INSERT INTO %s (x, y) VALUES(1, {'firstValue':{a:1}})");
- assertRows(execute("SELECT * FROM %s"), row(1, map("firstValue", userType(1))));
- flush();
-
- execute("ALTER TYPE " + KEYSPACE + "." + ut1 + " ADD b int");
- execute("INSERT INTO %s (x, y) VALUES(2, {'secondValue':{a:2, b:2}})");
- execute("INSERT INTO %s (x, y) VALUES(3, {'thirdValue':{a:3}})");
- execute("INSERT INTO %s (x, y) VALUES(4, {'fourthValue':{b:4}})");
-
- assertRows(execute("SELECT * FROM %s"),
- row(1, map("firstValue", userType(1))),
- row(2, map("secondValue", userType(2, 2))),
- row(3, map("thirdValue", userType(3, null))),
- row(4, map("fourthValue", userType(null, 4))));
-
- flush();
-
- assertRows(execute("SELECT * FROM %s"),
- row(1, map("firstValue", userType(1))),
- row(2, map("secondValue", userType(2, 2))),
- row(3, map("thirdValue", userType(3, null))),
- row(4, map("fourthValue", userType(null, 4))));
- }
- }
-
- @Test
- public void testAlteringUserTypeNestedWithinSet() throws Throwable
- {
- // test frozen and non-frozen collections
- String[] columnTypePrefixes = {"frozen<set<", "set<frozen<"};
- for (String columnTypePrefix : columnTypePrefixes)
- {
- String ut1 = createType("CREATE TYPE %s (a int)");
- String columnType = columnTypePrefix + KEYSPACE + "." + ut1 + ">>";
-
- createTable("CREATE TABLE %s (x int PRIMARY KEY, y " + columnType + ")");
-
- execute("INSERT INTO %s (x, y) VALUES(1, {1} )");
- assertRows(execute("SELECT * FROM %s"), row(1, set(userType(1))));
- flush();
-
- execute("ALTER TYPE " + KEYSPACE + "." + ut1 + " ADD b int");
- execute("INSERT INTO %s (x, y) VALUES(2, {{a:2, b:2}})");
- execute("INSERT INTO %s (x, y) VALUES(3, {{a:3}})");
- execute("INSERT INTO %s (x, y) VALUES(4, {{b:4}})");
-
- assertRows(execute("SELECT * FROM %s"),
- row(1, set(userType(1))),
- row(2, set(userType(2, 2))),
- row(3, set(userType(3, null))),
- row(4, set(userType(null, 4))));
-
- flush();
-
- assertRows(execute("SELECT * FROM %s"),
- row(1, set(userType(1))),
- row(2, set(userType(2, 2))),
- row(3, set(userType(3, null))),
- row(4, set(userType(null, 4))));
- }
- }
-
- @Test
- public void testAlteringUserTypeNestedWithinList() throws Throwable
- {
- // test frozen and non-frozen collections
- String[] columnTypePrefixes = {"frozen<list<", "list<frozen<"};
- for (String columnTypePrefix : columnTypePrefixes)
- {
- String ut1 = createType("CREATE TYPE %s (a int)");
- String columnType = columnTypePrefix + KEYSPACE + "." + ut1 + ">>";
-
- createTable("CREATE TABLE %s (x int PRIMARY KEY, y " + columnType + ")");
-
- execute("INSERT INTO %s (x, y) VALUES(1, [1] )");
- assertRows(execute("SELECT * FROM %s"), row(1, list(userType(1))));
- flush();
-
- execute("ALTER TYPE " + KEYSPACE + "." + ut1 + " ADD b int");
- execute("INSERT INTO %s (x, y) VALUES(2, [{a:2, b:2}])");
- execute("INSERT INTO %s (x, y) VALUES(3, [{a:3}])");
- execute("INSERT INTO %s (x, y) VALUES(4, [{b:4}])");
-
- assertRows(execute("SELECT * FROM %s"),
- row(1, list(userType(1))),
- row(2, list(userType(2, 2))),
- row(3, list(userType(3, null))),
- row(4, list(userType(null, 4))));
-
- flush();
-
- assertRows(execute("SELECT * FROM %s"),
- row(1, list(userType(1))),
- row(2, list(userType(2, 2))),
- row(3, list(userType(3, null))),
- row(4, list(userType(null, 4))));
- }
- }
-
- @Test
- public void testAlteringUserTypeNestedWithinTuple() throws Throwable
- {
- String type = createType("CREATE TYPE %s (a int, b int)");
-
- createTable("CREATE TABLE %s (a int PRIMARY KEY, b frozen<tuple<int, " + KEYSPACE + "." + type + ">>)");
-
- execute("INSERT INTO %s (a, b) VALUES(1, (1, {a:1, b:1}))");
- assertRows(execute("SELECT * FROM %s"), row(1, tuple(1, userType(1, 1))));
- flush();
-
- execute("ALTER TYPE " + KEYSPACE + "." + type + " ADD c int");
- execute("INSERT INTO %s (a, b) VALUES(2, (2, {a: 2, b: 2, c: 2}))");
- execute("INSERT INTO %s (a, b) VALUES(3, (3, {a: 3, b: 3}))");
- execute("INSERT INTO %s (a, b) VALUES(4, (4, {b:4}))");
-
- assertRows(execute("SELECT * FROM %s"),
- row(1, tuple(1, userType(1, 1))),
- row(2, tuple(2, userType(2, 2, 2))),
- row(3, tuple(3, userType(3, 3, null))),
- row(4, tuple(4, userType(null, 4, null))));
-
- flush();
-
- assertRows(execute("SELECT * FROM %s"),
- row(1, tuple(1, userType(1, 1))),
- row(2, tuple(2, userType(2, 2, 2))),
- row(3, tuple(3, userType(3, 3, null))),
- row(4, tuple(4, userType(null, 4, null))));
- }
-
- @Test
- public void testAlteringUserTypeNestedWithinNestedTuple() throws Throwable
- {
- String type = createType("CREATE TYPE %s (a int, b int)");
-
- createTable("CREATE TABLE %s (a int PRIMARY KEY, b frozen<tuple<int, tuple<int, " + KEYSPACE + "." + type + ">>>)");
-
- execute("INSERT INTO %s (a, b) VALUES(1, (1, (1, {a:1, b:1})))");
- assertRows(execute("SELECT * FROM %s"), row(1, tuple(1, tuple(1, userType(1, 1)))));
- flush();
-
- execute("ALTER TYPE " + KEYSPACE + "." + type + " ADD c int");
- execute("INSERT INTO %s (a, b) VALUES(2, (2, (1, {a: 2, b: 2, c: 2})))");
- execute("INSERT INTO %s (a, b) VALUES(3, (3, (1, {a: 3, b: 3})))");
- execute("INSERT INTO %s (a, b) VALUES(4, (4, (1, {b:4})))");
-
- assertRows(execute("SELECT * FROM %s"),
- row(1, tuple(1, tuple(1, userType(1, 1)))),
- row(2, tuple(2, tuple(1, userType(2, 2, 2)))),
- row(3, tuple(3, tuple(1, userType(3, 3, null)))),
- row(4, tuple(4, tuple(1, userType(null, 4, null)))));
-
- flush();
-
- assertRows(execute("SELECT * FROM %s"),
- row(1, tuple(1, tuple(1, userType(1, 1)))),
- row(2, tuple(2, tuple(1, userType(2, 2, 2)))),
- row(3, tuple(3, tuple(1, userType(3, 3, null)))),
- row(4, tuple(4, tuple(1, userType(null, 4, null)))));
- }
-
- @Test
- public void testAlteringUserTypeNestedWithinUserType() throws Throwable
- {
- String type = createType("CREATE TYPE %s (a int, b int)");
- String otherType = createType("CREATE TYPE %s (x frozen<" + KEYSPACE + "." + type + ">)");
-
- createTable("CREATE TABLE %s (a int PRIMARY KEY, b frozen<" + KEYSPACE + "." + otherType + ">)");
-
- execute("INSERT INTO %s (a, b) VALUES(1, {x: {a:1, b:1}})");
- assertRows(execute("SELECT b.x.a, b.x.b FROM %s"), row(1, 1));
- flush();
-
- execute("ALTER TYPE " + KEYSPACE + "." + type + " ADD c int");
- execute("INSERT INTO %s (a, b) VALUES(2, {x: {a: 2, b: 2, c: 2}})");
- execute("INSERT INTO %s (a, b) VALUES(3, {x: {a: 3, b: 3}})");
- execute("INSERT INTO %s (a, b) VALUES(4, {x: {b:4}})");
-
- assertRows(execute("SELECT b.x.a, b.x.b, b.x.c FROM %s"),
- row(1, 1, null),
- row(2, 2, 2),
- row(3, 3, null),
- row(null, 4, null));
-
- flush();
-
- assertRows(execute("SELECT b.x.a, b.x.b, b.x.c FROM %s"),
- row(1, 1, null),
- row(2, 2, 2),
- row(3, 3, null),
- row(null, 4, null));
- }
-}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/f797bfa4/test/unit/org/apache/cassandra/cql3/statements/SelectionColumnMappingTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/statements/SelectionColumnMappingTest.java b/test/unit/org/apache/cassandra/cql3/statements/SelectionColumnMappingTest.java
index 09b2bdd..ccd3570 100644
--- a/test/unit/org/apache/cassandra/cql3/statements/SelectionColumnMappingTest.java
+++ b/test/unit/org/apache/cassandra/cql3/statements/SelectionColumnMappingTest.java
@@ -3,12 +3,15 @@ package org.apache.cassandra.cql3.statements;
import java.util.ArrayList;
import java.util.List;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.apache.cassandra.config.ColumnDefinition;
+import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.config.Schema;
import org.apache.cassandra.cql3.*;
import org.apache.cassandra.db.marshal.*;
+import org.apache.cassandra.dht.ByteOrderedPartitioner;
import org.apache.cassandra.exceptions.RequestValidationException;
import org.apache.cassandra.service.ClientState;
@@ -20,6 +23,12 @@ public class SelectionColumnMappingTest extends CQLTester
String tableName;
String typeName;
+ @BeforeClass
+ public static void setUpClass()
+ {
+ DatabaseDescriptor.setPartitioner(new ByteOrderedPartitioner());
+ }
+
@Test
public void testSelectionColumnMapping() throws Throwable
{
http://git-wip-us.apache.org/repos/asf/cassandra/blob/f797bfa4/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
new file mode 100644
index 0000000..0241d4f
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
@@ -0,0 +1,488 @@
+/*
+ * 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.validation.entities;
+
+import java.util.UUID;
+
+import org.junit.Test;
+
+import org.apache.cassandra.cql3.CQLTester;
+
+public class CollectionsTest extends CQLTester
+{
+ @Test
+ public void testMapBulkRemoval() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, m map<text, text>)");
+
+ execute("INSERT INTO %s(k, m) VALUES (?, ?)", 0, map("k1", "v1", "k2", "v2", "k3", "v3"));
+
+ assertRows(execute("SELECT * FROM %s"),
+ row(0, map("k1", "v1", "k2", "v2", "k3", "v3"))
+ );
+
+ execute("UPDATE %s SET m = m - ? WHERE k = ?", set("k2"), 0);
+
+ assertRows(execute("SELECT * FROM %s"),
+ row(0, map("k1", "v1", "k3", "v3"))
+ );
+
+ execute("UPDATE %s SET m = m + ?, m = m - ? WHERE k = ?", map("k4", "v4"), set("k3"), 0);
+
+ assertRows(execute("SELECT * FROM %s"),
+ row(0, map("k1", "v1", "k4", "v4"))
+ );
+ }
+
+ @Test
+ public void testInvalidCollectionsMix() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, l list<text>, s set<text>, m map<text, text>)");
+
+ // Note: we force the non-prepared form for some of those tests because a list and a set
+ // have the same serialized format in practice and CQLTester don't validate that the type
+ // of what's passed as a value in the prepared case, so the queries would work (which is ok,
+ // CQLTester is just a "dumb" client).
+
+ assertInvalid("UPDATE %s SET l = l + { 'a', 'b' } WHERE k = 0");
+ assertInvalid("UPDATE %s SET l = l - { 'a', 'b' } WHERE k = 0");
+ assertInvalid("UPDATE %s SET l = l + ? WHERE k = 0", map("a", "b", "c", "d"));
+ assertInvalid("UPDATE %s SET l = l - ? WHERE k = 0", map("a", "b", "c", "d"));
+
+ assertInvalid("UPDATE %s SET s = s + [ 'a', 'b' ] WHERE k = 0");
+ assertInvalid("UPDATE %s SET s = s - [ 'a', 'b' ] WHERE k = 0");
+ assertInvalid("UPDATE %s SET s = s + ? WHERE k = 0", map("a", "b", "c", "d"));
+ assertInvalid("UPDATE %s SET s = s - ? WHERE k = 0", map("a", "b", "c", "d"));
+
+ assertInvalid("UPDATE %s SET m = m + ? WHERE k = 0", list("a", "b"));
+ assertInvalid("UPDATE %s SET m = m - [ 'a', 'b' ] WHERE k = 0");
+ assertInvalid("UPDATE %s SET m = m + ? WHERE k = 0", set("a", "b"));
+ assertInvalid("UPDATE %s SET m = m - ? WHERE k = 0", map("a", "b", "c", "d"));
+ }
+
+ @Test
+ public void testSets() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, s set<text>)");
+
+ execute("INSERT INTO %s(k, s) VALUES (0, ?)", set("v1", "v2", "v3", "v4"));
+
+ assertRows(execute("SELECT s FROM %s WHERE k = 0"),
+ row(set("v1", "v2", "v3", "v4"))
+ );
+
+ execute("DELETE s[?] FROM %s WHERE k = 0", "v1");
+
+ assertRows(execute("SELECT s FROM %s WHERE k = 0"),
+ row(set("v2", "v3", "v4"))
+ );
+
+ // Full overwrite
+ execute("UPDATE %s SET s = ? WHERE k = 0", set("v6", "v5"));
+
+ assertRows(execute("SELECT s FROM %s WHERE k = 0"),
+ row(set("v5", "v6"))
+ );
+
+ execute("UPDATE %s SET s = s + ? WHERE k = 0", set("v7"));
+
+ assertRows(execute("SELECT s FROM %s WHERE k = 0"),
+ row(set("v5", "v6", "v7"))
+ );
+
+ execute("UPDATE %s SET s = s - ? WHERE k = 0", set("v6", "v5"));
+
+ assertRows(execute("SELECT s FROM %s WHERE k = 0"),
+ row(set("v7"))
+ );
+
+ execute("DELETE s[?] FROM %s WHERE k = 0", set("v7"));
+
+ // Deleting an element that does not exist will succeed
+ execute("DELETE s[?] FROM %s WHERE k = 0", set("v7"));
+
+ execute("DELETE s FROM %s WHERE k = 0");
+
+ assertRows(execute("SELECT s FROM %s WHERE k = 0"),
+ row((Object) null)
+ );
+ }
+
+ @Test
+ public void testMaps() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, m map<text, int>)");
+
+ execute("INSERT INTO %s(k, m) VALUES (0, ?)", map("v1", 1, "v2", 2));
+
+ assertRows(execute("SELECT m FROM %s WHERE k = 0"),
+ row(map("v1", 1, "v2", 2))
+ );
+
+ execute("UPDATE %s SET m[?] = ?, m[?] = ? WHERE k = 0", "v3", 3, "v4", 4);
+
+ assertRows(execute("SELECT m FROM %s WHERE k = 0"),
+ row(map("v1", 1, "v2", 2, "v3", 3, "v4", 4))
+ );
+
+ execute("DELETE m[?] FROM %s WHERE k = 0", "v1");
+
+ assertRows(execute("SELECT m FROM %s WHERE k = 0"),
+ row(map("v2", 2, "v3", 3, "v4", 4))
+ );
+
+ // Full overwrite
+ execute("UPDATE %s SET m = ? WHERE k = 0", map("v6", 6, "v5", 5));
+
+ assertRows(execute("SELECT m FROM %s WHERE k = 0"),
+ row(map("v5", 5, "v6", 6))
+ );
+
+ execute("UPDATE %s SET m = m + ? WHERE k = 0", map("v7", 7));
+
+ assertRows(execute("SELECT m FROM %s WHERE k = 0"),
+ row(map("v5", 5, "v6", 6, "v7", 7))
+ );
+
+ execute("DELETE m[?] FROM %s WHERE k = 0", "v7");
+
+ assertRows(execute("SELECT m FROM %s WHERE k = 0"),
+ row(map("v5", 5, "v6", 6))
+ );
+
+ execute("DELETE m[?] FROM %s WHERE k = 0", "v6");
+
+ assertRows(execute("SELECT m FROM %s WHERE k = 0"),
+ row(map("v5", 5))
+ );
+
+ execute("DELETE m[?] FROM %s WHERE k = 0", "v5");
+
+ assertRows(execute("SELECT m FROM %s WHERE k = 0"),
+ row((Object) null)
+ );
+
+ // Deleting a non-existing key should succeed
+ execute("DELETE m[?] FROM %s WHERE k = 0", "v5");
+
+ assertRows(execute("SELECT m FROM %s WHERE k = 0"),
+ row((Object) null)
+ );
+
+ // The empty map is parsed as an empty set (because we don't have enough info at parsing
+ // time when we see a {}) and special cased later. This test checks this work properly
+ execute("UPDATE %s SET m = {} WHERE k = 0");
+
+ assertRows(execute("SELECT m FROM %s WHERE k = 0"),
+ row((Object)null)
+ );
+ }
+
+ @Test
+ public void testLists() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, l list<text>)");
+
+ execute("INSERT INTO %s(k, l) VALUES (0, ?)", list("v1", "v2", "v3"));
+
+ assertRows(execute("SELECT l FROM %s WHERE k = 0"), row(list("v1", "v2", "v3")));
+
+ execute("DELETE l[?] FROM %s WHERE k = 0", 1);
+
+ assertRows(execute("SELECT l FROM %s WHERE k = 0"), row(list("v1", "v3")));
+
+ execute("UPDATE %s SET l[?] = ? WHERE k = 0", 1, "v4");
+
+ assertRows(execute("SELECT l FROM %s WHERE k = 0"), row(list("v1", "v4")));
+
+ // Full overwrite
+ execute("UPDATE %s SET l = ? WHERE k = 0", list("v6", "v5"));
+
+ assertRows(execute("SELECT l FROM %s WHERE k = 0"), row(list("v6", "v5")));
+
+ execute("UPDATE %s SET l = l + ? WHERE k = 0", list("v7", "v8"));
+
+ assertRows(execute("SELECT l FROM %s WHERE k = 0"), row(list("v6", "v5", "v7", "v8")));
+
+ execute("UPDATE %s SET l = ? + l WHERE k = 0", list("v9"));
+
+ assertRows(execute("SELECT l FROM %s WHERE k = 0"), row(list("v9", "v6", "v5", "v7", "v8")));
+
+ execute("UPDATE %s SET l = l - ? WHERE k = 0", list("v5", "v8"));
+
+ assertRows(execute("SELECT l FROM %s WHERE k = 0"), row(list("v9", "v6", "v7")));
+
+ execute("DELETE l FROM %s WHERE k = 0");
+
+ assertRows(execute("SELECT l FROM %s WHERE k = 0"), row((Object) null));
+
+ assertInvalidMessage("Attempted to delete an element from a list which is null",
+ "DELETE l[0] FROM %s WHERE k=0 ");
+
+ assertInvalidMessage("Attempted to set an element on a list which is null",
+ "UPDATE %s SET l[0] = ? WHERE k=0", list("v10"));
+
+ execute("UPDATE %s SET l = l - ? WHERE k=0 ", list("v11"));
+
+ assertRows(execute("SELECT l FROM %s WHERE k = 0"), row((Object) null));
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.set_test()
+ */
+ @Test
+ public void testSet() throws Throwable
+ {
+ createTable("CREATE TABLE %s ( fn text, ln text, tags set<text>, PRIMARY KEY (fn, ln) )");
+
+ execute("UPDATE %s SET tags = tags + { 'foo' } WHERE fn='Tom' AND ln='Bombadil'");
+ execute("UPDATE %s SET tags = tags + { 'bar' } WHERE fn='Tom' AND ln='Bombadil'");
+ execute("UPDATE %s SET tags = tags + { 'foo' } WHERE fn='Tom' AND ln='Bombadil'");
+ execute("UPDATE %s SET tags = tags + { 'foobar' } WHERE fn='Tom' AND ln='Bombadil'");
+ execute("UPDATE %s SET tags = tags - { 'bar' } WHERE fn='Tom' AND ln='Bombadil'");
+
+ assertRows(execute("SELECT tags FROM %s"),
+ row(set("foo", "foobar")));
+
+ execute("UPDATE %s SET tags = { 'a', 'c', 'b' } WHERE fn='Bilbo' AND ln='Baggins'");
+ assertRows(execute("SELECT tags FROM %s WHERE fn='Bilbo' AND ln='Baggins'"),
+ row(set("a", "b", "c")));
+
+ execute("UPDATE %s SET tags = { 'm', 'n' } WHERE fn='Bilbo' AND ln='Baggins'");
+ assertRows(execute("SELECT tags FROM %s WHERE fn='Bilbo' AND ln='Baggins'"),
+ row(set("m", "n")));
+
+ execute("DELETE tags['m'] FROM %s WHERE fn='Bilbo' AND ln='Baggins'");
+ assertRows(execute("SELECT tags FROM %s WHERE fn='Bilbo' AND ln='Baggins'"),
+ row(set("n")));
+
+ execute("DELETE tags FROM %s WHERE fn='Bilbo' AND ln='Baggins'");
+ assertEmpty(execute("SELECT tags FROM %s WHERE fn='Bilbo' AND ln='Baggins'"));
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.map_test()
+ */
+ @Test
+ public void testMap() throws Throwable
+ {
+ createTable("CREATE TABLE %s (fn text, ln text, m map<text, int>, PRIMARY KEY (fn, ln))");
+
+ execute("UPDATE %s SET m['foo'] = 3 WHERE fn='Tom' AND ln='Bombadil'");
+ execute("UPDATE %s SET m['bar'] = 4 WHERE fn='Tom' AND ln='Bombadil'");
+ execute("UPDATE %s SET m['woot'] = 5 WHERE fn='Tom' AND ln='Bombadil'");
+ execute("UPDATE %s SET m['bar'] = 6 WHERE fn='Tom' AND ln='Bombadil'");
+ execute("DELETE m['foo'] FROM %s WHERE fn='Tom' AND ln='Bombadil'");
+
+ assertRows(execute("SELECT m FROM %s"),
+ row(map("bar", 6, "woot", 5)));
+
+ execute("UPDATE %s SET m = { 'a' : 4 , 'c' : 3, 'b' : 2 } WHERE fn='Bilbo' AND ln='Baggins'");
+ assertRows(execute("SELECT m FROM %s WHERE fn='Bilbo' AND ln='Baggins'"),
+ row(map("a", 4, "b", 2, "c", 3)));
+
+ execute("UPDATE %s SET m = { 'm' : 4 , 'n' : 1, 'o' : 2 } WHERE fn='Bilbo' AND ln='Baggins'");
+ assertRows(execute("SELECT m FROM %s WHERE fn='Bilbo' AND ln='Baggins'"),
+ row(map("m", 4, "n", 1, "o", 2)));
+
+ execute("UPDATE %s SET m = {} WHERE fn='Bilbo' AND ln='Baggins'");
+ assertEmpty(execute("SELECT m FROM %s WHERE fn='Bilbo' AND ln='Baggins'"));
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.list_test()
+ */
+ @Test
+ public void testList() throws Throwable
+ {
+ createTable("CREATE TABLE %s (fn text, ln text, tags list<text>, PRIMARY KEY (fn, ln))");
+
+ execute("UPDATE %s SET tags = tags + [ 'foo' ] WHERE fn='Tom' AND ln='Bombadil'");
+ execute("UPDATE %s SET tags = tags + [ 'bar' ] WHERE fn='Tom' AND ln='Bombadil'");
+ execute("UPDATE %s SET tags = tags + [ 'foo' ] WHERE fn='Tom' AND ln='Bombadil'");
+ execute("UPDATE %s SET tags = tags + [ 'foobar' ] WHERE fn='Tom' AND ln='Bombadil'");
+
+ assertRows(execute("SELECT tags FROM %s"),
+ row(list("foo", "bar", "foo", "foobar")));
+
+ execute("UPDATE %s SET tags = [ 'a', 'c', 'b', 'c' ] WHERE fn='Bilbo' AND ln='Baggins'");
+ assertRows(execute("SELECT tags FROM %s WHERE fn='Bilbo' AND ln='Baggins'"),
+ row(list("a", "c", "b", "c")));
+
+ execute("UPDATE %s SET tags = [ 'm', 'n' ] + tags WHERE fn='Bilbo' AND ln='Baggins'");
+ assertRows(execute("SELECT tags FROM %s WHERE fn='Bilbo' AND ln='Baggins'"),
+ row(list("m", "n", "a", "c", "b", "c")));
+
+ execute("UPDATE %s SET tags[2] = 'foo', tags[4] = 'bar' WHERE fn='Bilbo' AND ln='Baggins'");
+ assertRows(execute("SELECT tags FROM %s WHERE fn='Bilbo' AND ln='Baggins'"),
+ row(list("m", "n", "foo", "c", "bar", "c")));
+
+ execute("DELETE tags[2] FROM %s WHERE fn='Bilbo' AND ln='Baggins'");
+ assertRows(execute("SELECT tags FROM %s WHERE fn='Bilbo' AND ln='Baggins'"),
+ row(list("m", "n", "c", "bar", "c")));
+
+ execute("UPDATE %s SET tags = tags - [ 'bar' ] WHERE fn='Bilbo' AND ln='Baggins'");
+ assertRows(execute("SELECT tags FROM %s WHERE fn='Bilbo' AND ln='Baggins'"),
+ row(list("m", "n", "c", "c")));
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.multi_collection_test()
+ */
+ @Test
+ public void testMultiCollections() throws Throwable
+ {
+ UUID id = UUID.fromString("b017f48f-ae67-11e1-9096-005056c00008");
+
+ createTable("CREATE TABLE %s (k uuid PRIMARY KEY, L list<int>, M map<text, int>, S set<int> )");
+
+ execute("UPDATE %s SET L = [1, 3, 5] WHERE k = ?", id);
+ execute("UPDATE %s SET L = L + [7, 11, 13] WHERE k = ?;", id);
+ execute("UPDATE %s SET S = {1, 3, 5} WHERE k = ?", id);
+ execute("UPDATE %s SET S = S + {7, 11, 13} WHERE k = ?", id);
+ execute("UPDATE %s SET M = {'foo': 1, 'bar' : 3} WHERE k = ?", id);
+ execute("UPDATE %s SET M = M + {'foobar' : 4} WHERE k = ?", id);
+
+ assertRows(execute("SELECT L, M, S FROM %s WHERE k = ?", id),
+ row(list(1, 3, 5, 7, 11, 13),
+ map("bar", 3, "foo", 1, "foobar", 4),
+ set(1, 3, 5, 7, 11, 13)));
+ }
+
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.collection_and_regular_test()
+ */
+ @Test
+ public void testCollectionAndRegularColumns() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, l list<int>, c int)");
+
+ execute("INSERT INTO %s (k, l, c) VALUES(3, [0, 1, 2], 4)");
+ execute("UPDATE %s SET l[0] = 1, c = 42 WHERE k = 3");
+ assertRows(execute("SELECT l, c FROM %s WHERE k = 3"),
+ row(list(1, 1, 2), 42));
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.multi_list_set_test()
+ */
+ @Test
+ public void testMultipleLists() throws Throwable
+ {
+ createTable(" CREATE TABLE %s (k int PRIMARY KEY, l1 list<int>, l2 list<int>)");
+
+ execute("INSERT INTO %s (k, l1, l2) VALUES (0, [1, 2, 3], [4, 5, 6])");
+ execute("UPDATE %s SET l2[1] = 42, l1[1] = 24 WHERE k = 0");
+
+ assertRows(execute("SELECT l1, l2 FROM %s WHERE k = 0"),
+ row(list(1, 24, 3), list(4, 42, 6)));
+ }
+
+ /**
+ * Test you can add columns in a table with collections (#4982 bug),
+ * migrated from cql_tests.py:TestCQL.alter_with_collections_test()
+ */
+ @Test
+ public void testAlterCollections() throws Throwable
+ {
+ createTable("CREATE TABLE %s (key int PRIMARY KEY, aset set<text>)");
+ execute("ALTER TABLE %s ADD c text");
+ execute("ALTER TABLE %s ADD alist list<text>");
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.collection_compact_test()
+ */
+ @Test
+ public void testCompactCollections() throws Throwable
+ {
+ String tableName = KEYSPACE + "." + createTableName();
+ assertInvalid(String.format("CREATE TABLE %s (user ascii PRIMARY KEY, mails list < text >) WITH COMPACT STORAGE;", tableName));
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.collection_function_test()
+ */
+ @Test
+ public void testFunctionsOnCollections() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, l set<int>)");
+
+ assertInvalid("SELECT ttl(l) FROM %s WHERE k = 0");
+ assertInvalid("SELECT writetime(l) FROM %s WHERE k = 0");
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.bug_5376()
+ */
+ @Test
+ public void testInClauseWithCollections() throws Throwable
+ {
+ createTable("CREATE TABLE %s (key text, c bigint, v text, x set < text >, PRIMARY KEY(key, c) )");
+
+ assertInvalid("select * from %s where key = 'foo' and c in (1,3,4)");
+ }
+
+ /**
+ * Test for bug #5795,
+ * migrated from cql_tests.py:TestCQL.nonpure_function_collection_test()
+ */
+ @Test
+ public void testNonPureFunctionCollection() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, v list<timeuuid>)");
+
+ // we just want to make sure this doesn't throw
+ execute("INSERT INTO %s (k, v) VALUES (0, [now()])");
+ }
+
+ /**
+ * Test for 5805 bug,
+ * migrated from cql_tests.py:TestCQL.collection_flush_test()
+ */
+ @Test
+ public void testCollectionFlush() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, s set<int>)");
+
+ execute("INSERT INTO %s (k, s) VALUES (1, {1})");
+ flush();
+
+ execute("INSERT INTO %s (k, s) VALUES (1, {2})");
+ flush();
+
+ assertRows(execute("SELECT * FROM %s"),
+ row(1, set(2)));
+ }
+
+ /**
+ * Test for 6276,
+ * migrated from cql_tests.py:TestCQL.drop_and_readd_collection_test()
+ */
+ @Test
+ public void testDropAndReaddCollection() throws Throwable
+ {
+ createTable("create table %s (k int primary key, v set<text>, x int)");
+ execute("insert into %s (k, v) VALUES (0, {'fffffffff'})");
+ flush();
+ execute("alter table %s drop v");
+ assertInvalid("alter table %s add v set<int>");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/f797bfa4/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java
new file mode 100644
index 0000000..c66a04d
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.validation.entities;
+
+import org.junit.Test;
+
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.exceptions.InvalidRequestException;
+
+public class CountersTest extends CQLTester
+{
+ /**
+ * Check for a table with counters,
+ * migrated from cql_tests.py:TestCQL.counters_test()
+ */
+ @Test
+ public void testCounters() throws Throwable
+ {
+ createTable("CREATE TABLE %s (userid int, url text, total counter, PRIMARY KEY (userid, url)) WITH COMPACT STORAGE");
+
+ execute("UPDATE %s SET total = total + 1 WHERE userid = 1 AND url = 'http://foo.com'");
+ assertRows(execute("SELECT total FROM %s WHERE userid = 1 AND url = 'http://foo.com'"),
+ row(1L));
+
+ execute("UPDATE %s SET total = total - 4 WHERE userid = 1 AND url = 'http://foo.com'");
+ assertRows(execute("SELECT total FROM %s WHERE userid = 1 AND url = 'http://foo.com'"),
+ row(-3L));
+
+ execute("UPDATE %s SET total = total+1 WHERE userid = 1 AND url = 'http://foo.com'");
+ assertRows(execute("SELECT total FROM %s WHERE userid = 1 AND url = 'http://foo.com'"),
+ row(-2L));
+
+ execute("UPDATE %s SET total = total -2 WHERE userid = 1 AND url = 'http://foo.com'");
+ assertRows(execute("SELECT total FROM %s WHERE userid = 1 AND url = 'http://foo.com'"),
+ row(-4L));
+ }
+
+ /**
+ * Test for the validation bug of #4706,
+ * migrated from cql_tests.py:TestCQL.validate_counter_regular_test()
+ */
+ @Test
+ public void testRegularCounters() throws Throwable
+ {
+ assertInvalidThrowMessage("Cannot add a non counter column",
+ ConfigurationException.class,
+ String.format("CREATE TABLE %s.%s (id bigint PRIMARY KEY, count counter, things set<text>)", KEYSPACE, createTableName()));
+ }
+
+ /**
+ * Migrated from cql_tests.py:TestCQL.collection_counter_test()
+ */
+ @Test
+ public void testCountersOnCollections() throws Throwable
+ {
+ String tableName = KEYSPACE + "." + createTableName();
+ assertInvalidThrow(InvalidRequestException.class,
+ String.format("CREATE TABLE %s (k int PRIMARY KEY, l list<counter>)", tableName));
+
+ tableName = KEYSPACE + "." + createTableName();
+ assertInvalidThrow(InvalidRequestException.class,
+ String.format("CREATE TABLE %s (k int PRIMARY KEY, s set<counter>)", tableName));
+
+ tableName = KEYSPACE + "." + createTableName();
+ assertInvalidThrow(InvalidRequestException.class,
+ String.format("CREATE TABLE %s (k int PRIMARY KEY, m map<text, counter>)", tableName));
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/f797bfa4/test/unit/org/apache/cassandra/cql3/validation/entities/DateTypeTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/DateTypeTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/DateTypeTest.java
new file mode 100644
index 0000000..7fa5e67
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/DateTypeTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.validation.entities;
+
+import org.junit.Test;
+
+import org.apache.cassandra.cql3.CQLTester;
+
+public class DateTypeTest extends CQLTester
+{
+ /**
+ * Check dates are correctly recognized and validated,
+ * migrated from cql_tests.py:TestCQL.date_test()
+ */
+ @Test
+ public void testDate() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, t timestamp)");
+
+ execute("INSERT INTO %s (k, t) VALUES (0, '2011-02-03')");
+ assertInvalid("INSERT INTO %s (k, t) VALUES (0, '2011-42-42')");
+ }
+}