blob: cb49e579b50d6f123b534182cc5546519a74d2f1 [file] [log] [blame]
/*
* 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.operations;
import org.junit.Test;
import org.apache.cassandra.cql3.CQLTester;
public class BatchTest extends CQLTester
{
/**
* Test batch statements
* migrated from cql_tests.py:TestCQL.batch_test()
*/
@Test
public void testBatch() throws Throwable
{
createTable("CREATE TABLE %s (userid text PRIMARY KEY, name text, password text)");
String query = "BEGIN BATCH\n"
+ "INSERT INTO %1$s (userid, password, name) VALUES ('user2', 'ch@ngem3b', 'second user');\n"
+ "UPDATE %1$s SET password = 'ps22dhds' WHERE userid = 'user3';\n"
+ "INSERT INTO %1$s (userid, password) VALUES ('user4', 'ch@ngem3c');\n"
+ "DELETE name FROM %1$s WHERE userid = 'user1';\n"
+ "APPLY BATCH;";
execute(query);
}
/**
* Migrated from cql_tests.py:TestCQL.batch_and_list_test()
*/
@Test
public void testBatchAndList() throws Throwable
{
createTable("CREATE TABLE %s (k int PRIMARY KEY, l list<int>)");
execute("BEGIN BATCH " +
"UPDATE %1$s SET l = l +[ 1 ] WHERE k = 0; " +
"UPDATE %1$s SET l = l + [ 2 ] WHERE k = 0; " +
"UPDATE %1$s SET l = l + [ 3 ] WHERE k = 0; " +
"APPLY BATCH");
assertRows(execute("SELECT l FROM %s WHERE k = 0"),
row(list(1, 2, 3)));
execute("BEGIN BATCH " +
"UPDATE %1$s SET l =[ 1 ] + l WHERE k = 1; " +
"UPDATE %1$s SET l = [ 2 ] + l WHERE k = 1; " +
"UPDATE %1$s SET l = [ 3 ] + l WHERE k = 1; " +
"APPLY BATCH ");
assertRows(execute("SELECT l FROM %s WHERE k = 1"),
row(list(3, 2, 1)));
}
/**
* Migrated from cql_tests.py:TestCQL.bug_6115_test()
*/
@Test
public void testBatchDeleteInsert() throws Throwable
{
createTable("CREATE TABLE %s (k int, v int, PRIMARY KEY (k, v))");
execute("INSERT INTO %s (k, v) VALUES (0, 1)");
execute("BEGIN BATCH DELETE FROM %1$s WHERE k=0 AND v=1; INSERT INTO %1$s (k, v) VALUES (0, 2); APPLY BATCH");
assertRows(execute("SELECT * FROM %s"),
row(0, 2));
}
}