Repository: cassandra Updated Branches: refs/heads/trunk 27fdf4211 -> a19c91280
Fix handling of EXECUTE with skip_metadata=false patch by Aleksey Yeschenko and Jake Luciani; reviewed by Sylvain Lebresne Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/63cb95e0 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/63cb95e0 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/63cb95e0 Branch: refs/heads/trunk Commit: 63cb95e012ae3cc197b42b9aa881f905449437b1 Parents: dee15a8 Author: Aleksey Yeschenko <alek...@apache.org> Authored: Tue Oct 14 00:23:54 2014 +0300 Committer: Aleksey Yeschenko <alek...@apache.org> Committed: Tue Oct 14 00:24:04 2014 +0300 ---------------------------------------------------------------------- .../org/apache/cassandra/cql3/ResultSet.java | 2 +- .../cql3/PreparedStatementCleanupTest.java | 86 ------------- .../cassandra/cql3/PreparedStatementsTest.java | 122 +++++++++++++++++++ 3 files changed, 123 insertions(+), 87 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/63cb95e0/src/java/org/apache/cassandra/cql3/ResultSet.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/ResultSet.java b/src/java/org/apache/cassandra/cql3/ResultSet.java index 3928060..e463b29 100644 --- a/src/java/org/apache/cassandra/cql3/ResultSet.java +++ b/src/java/org/apache/cassandra/cql3/ResultSet.java @@ -266,7 +266,7 @@ public class ResultSet public Metadata copy() { - return new Metadata(flags, names, columnCount, pagingState); + return new Metadata(EnumSet.copyOf(flags), names, columnCount, pagingState); } // The maximum number of values that the ResultSet can hold. This can be bigger than columnCount due to CASSANDRA-4911 http://git-wip-us.apache.org/repos/asf/cassandra/blob/63cb95e0/test/unit/org/apache/cassandra/cql3/PreparedStatementCleanupTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/PreparedStatementCleanupTest.java b/test/unit/org/apache/cassandra/cql3/PreparedStatementCleanupTest.java deleted file mode 100644 index 3e725e9..0000000 --- a/test/unit/org/apache/cassandra/cql3/PreparedStatementCleanupTest.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 com.datastax.driver.core.Cluster; -import com.datastax.driver.core.PreparedStatement; -import com.datastax.driver.core.Session; -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.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -public class PreparedStatementCleanupTest extends SchemaLoader -{ - private static Cluster cluster; - private static Session session; - - private static final String KEYSPACE = "prepared_stmt_cleanup"; - private static final String createKsStatement = "CREATE KEYSPACE " + KEYSPACE + - " WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"; - private static final String dropKsStatement = "DROP KEYSPACE IF EXISTS " + KEYSPACE; - - @BeforeClass - public static void setup() throws Exception - { - Schema.instance.clear(); - - EmbeddedCassandraService cassandra = new EmbeddedCassandraService(); - cassandra.start(); - - // Currently the native server start method return before the server is fully binded to the socket, so we need - // to wait slightly before trying to connect to it. We should fix this but in the meantime using a sleep. - Thread.sleep(500); - - cluster = Cluster.builder().addContactPoint("127.0.0.1") - .withPort(DatabaseDescriptor.getNativeTransportPort()) - .build(); - session = cluster.connect(); - - session.execute(dropKsStatement); - session.execute(createKsStatement); - } - - @AfterClass - public static void tearDown() throws Exception - { - cluster.close(); - } - - @Test - public void testInvalidatePreparedStatementsOnDrop() - { - String createTableStatement = "CREATE TABLE IF NOT EXISTS " + KEYSPACE + ".qp_cleanup (id int PRIMARY KEY, cid int, val text);"; - String dropTableStatement = "DROP TABLE IF EXISTS " + KEYSPACE + ".qp_cleanup;"; - - session.execute(createTableStatement); - PreparedStatement prepared = session.prepare("INSERT INTO " + KEYSPACE + ".qp_cleanup (id, cid, val) VALUES (?, ?, ?)"); - session.execute(dropTableStatement); - session.execute(createTableStatement); - session.execute(prepared.bind(1, 1, "value")); - - session.execute(dropKsStatement); - session.execute(createKsStatement); - session.execute(createTableStatement); - session.execute(prepared.bind(1, 1, "value")); - session.execute(dropKsStatement); - } -} http://git-wip-us.apache.org/repos/asf/cassandra/blob/63cb95e0/test/unit/org/apache/cassandra/cql3/PreparedStatementsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/PreparedStatementsTest.java b/test/unit/org/apache/cassandra/cql3/PreparedStatementsTest.java new file mode 100644 index 0000000..f65ec18 --- /dev/null +++ b/test/unit/org/apache/cassandra/cql3/PreparedStatementsTest.java @@ -0,0 +1,122 @@ +/* + * 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.AfterClass; +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.Session; +import org.apache.cassandra.SchemaLoader; +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.config.Schema; +import org.apache.cassandra.service.EmbeddedCassandraService; + +import static junit.framework.Assert.assertEquals; + +public class PreparedStatementsTest extends SchemaLoader +{ + private static Cluster cluster; + private static Session session; + + private static final String KEYSPACE = "prepared_stmt_cleanup"; + private static final String createKsStatement = "CREATE KEYSPACE " + KEYSPACE + + " WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"; + private static final String dropKsStatement = "DROP KEYSPACE IF EXISTS " + KEYSPACE; + + @BeforeClass + public static void setup() throws Exception + { + Schema.instance.clear(); + + EmbeddedCassandraService cassandra = new EmbeddedCassandraService(); + cassandra.start(); + + // Currently the native server start method return before the server is fully binded to the socket, so we need + // to wait slightly before trying to connect to it. We should fix this but in the meantime using a sleep. + Thread.sleep(500); + + cluster = Cluster.builder().addContactPoint("127.0.0.1") + .withPort(DatabaseDescriptor.getNativeTransportPort()) + .build(); + session = cluster.connect(); + + session.execute(dropKsStatement); + session.execute(createKsStatement); + } + + @AfterClass + public static void tearDown() throws Exception + { + cluster.close(); + } + + @Test + public void testInvalidatePreparedStatementsOnDrop() + { + String createTableStatement = "CREATE TABLE IF NOT EXISTS " + KEYSPACE + ".qp_cleanup (id int PRIMARY KEY, cid int, val text);"; + String dropTableStatement = "DROP TABLE IF EXISTS " + KEYSPACE + ".qp_cleanup;"; + + session.execute(createTableStatement); + PreparedStatement prepared = session.prepare("INSERT INTO " + KEYSPACE + ".qp_cleanup (id, cid, val) VALUES (?, ?, ?)"); + session.execute(dropTableStatement); + session.execute(createTableStatement); + session.execute(prepared.bind(1, 1, "value")); + + session.execute(dropKsStatement); + session.execute(createKsStatement); + session.execute(createTableStatement); + session.execute(prepared.bind(1, 1, "value")); + session.execute(dropKsStatement); + + // FIXME: where is invalidation actually tested? + } + + @Test + public void testStatementRePreparationOnReconnect() + { + session.execute(dropKsStatement); + session.execute(createKsStatement); + + session.execute("CREATE TABLE IF NOT EXISTS " + KEYSPACE + ".qp_test (id int PRIMARY KEY, cid int, val text);"); + + String insertCQL = "INSERT INTO " + KEYSPACE + ".qp_test (id, cid, val) VALUES (?, ?, ?)"; + String selectCQL = "Select * from " + KEYSPACE + ".qp_test where id = ?"; + + PreparedStatement preparedInsert = session.prepare(insertCQL); + PreparedStatement preparedSelect = session.prepare(selectCQL); + + session.execute(preparedInsert.bind(1, 1, "value")); + assertEquals(1, session.execute(preparedSelect.bind(1)).all().size()); + + cluster.close(); + + cluster = Cluster.builder().addContactPoint("127.0.0.1") + .withPort(DatabaseDescriptor.getNativeTransportPort()) + .build(); + session = cluster.connect(); + + preparedInsert = session.prepare(insertCQL); + preparedSelect = session.prepare(selectCQL); + session.execute(preparedInsert.bind(1, 1, "value")); + + assertEquals(1, session.execute(preparedSelect.bind(1)).all().size()); + } +}