This is an automated email from the ASF dual-hosted git repository.

djoshi pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 09f83fa  Add test cases for counter batch
09f83fa is described below

commit 09f83fa023cbe57e90287e7d93560f1cb0edb4c4
Author: Jon Meredith <jmeredit...@apple.com>
AuthorDate: Tue Apr 21 16:20:05 2020 -0600

    Add test cases for counter batch
    
    Patch by Jeff Jirsa, Jon Meredith; reviewed by David Capwell and Dinesh 
Joshi for CASSANDRA-15747
---
 .../cql3/validation/entities/CountersTest.java     | 67 ++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git 
a/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java 
b/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java
index 38bd4dd..adb824b 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java
@@ -163,4 +163,71 @@ public class CountersTest extends CQLTester
         assertInvalidThrowMessage("counter type is not supported for PRIMARY 
KEY column 'a'",
                                   InvalidRequestException.class, 
String.format("CREATE TABLE %s.%s (a counter, b int, PRIMARY KEY (b, a)) WITH 
CLUSTERING ORDER BY (a desc);", KEYSPACE, createTableName()));
     }
+
+    /**
+     * Check that a counter batch works as intended
+     */
+    @Test
+    public void testCounterBatch() throws Throwable
+    {
+        createTable("CREATE TABLE %s (userid int, url text, total counter, 
PRIMARY KEY (userid, url))");
+
+        // Ensure we handle updates to the same CQL row in the same partition 
properly
+        execute("BEGIN UNLOGGED BATCH " +
+                "UPDATE %1$s SET total = total + 1 WHERE userid = 1 AND url = 
'http://foo.com'; " +
+                "UPDATE %1$s SET total = total + 1 WHERE userid = 1 AND url = 
'http://foo.com'; " +
+                "UPDATE %1$s SET total = total + 1 WHERE userid = 1 AND url = 
'http://foo.com'; " +
+                "APPLY BATCH; ");
+        assertRows(execute("SELECT total FROM %s WHERE userid = 1 AND url = 
'http://foo.com'"),
+                row(3L));
+
+        // Ensure we handle different CQL rows in the same partition properly
+        execute("BEGIN UNLOGGED BATCH " +
+                "UPDATE %1$s SET total = total + 1 WHERE userid = 1 AND url = 
'http://bar.com'; " +
+                "UPDATE %1$s SET total = total + 1 WHERE userid = 1 AND url = 
'http://baz.com'; " +
+                "UPDATE %1$s SET total = total + 1 WHERE userid = 1 AND url = 
'http://bad.com'; " +
+                "APPLY BATCH; ");
+        assertRows(execute("SELECT url, total FROM %s WHERE userid = 1"),
+                row("http://bad.com";, 1L),
+                row("http://bar.com";, 1L),
+                row("http://baz.com";, 1L),
+                row("http://foo.com";, 3L)); // from previous batch
+
+        // Different counters in the same CQL Row
+        createTable("CREATE TABLE %s (userid int, url text, first counter, 
second counter, third counter, PRIMARY KEY (userid, url))");
+        execute("BEGIN UNLOGGED BATCH " +
+                "UPDATE %1$s SET first = first + 1 WHERE userid = 1 AND url = 
'http://foo.com'; " +
+                "UPDATE %1$s SET first = first + 1 WHERE userid = 1 AND url = 
'http://foo.com'; " +
+                "UPDATE %1$s SET second = second + 1 WHERE userid = 1 AND url 
= 'http://foo.com'; " +
+                "APPLY BATCH; ");
+        assertRows(execute("SELECT first, second, third FROM %s WHERE userid = 
1 AND url = 'http://foo.com'"),
+                row(2L, 1L, null));
+
+        // Different counters in different CQL Rows
+        execute("BEGIN UNLOGGED BATCH " +
+                "UPDATE %1$s SET first = first + 1 WHERE userid = 1 AND url = 
'http://bad.com'; " +
+                "UPDATE %1$s SET first = first + 1, second = second + 1 WHERE 
userid = 1 AND url = 'http://bar.com'; " +
+                "UPDATE %1$s SET first = first - 1, second = second - 1 WHERE 
userid = 1 AND url = 'http://bar.com'; " +
+                "UPDATE %1$s SET second = second + 1 WHERE userid = 1 AND url 
= 'http://baz.com'; " +
+                "APPLY BATCH; ");
+        assertRows(execute("SELECT url, first, second, third FROM %s WHERE 
userid = 1"),
+                row("http://bad.com";, 1L, null, null),
+                row("http://bar.com";, 0L, 0L, null),
+                row("http://baz.com";, null, 1L, null),
+                row("http://foo.com";, 2L, 1L, null)); // from previous batch
+
+
+        // Different counters in different partitions
+        execute("BEGIN UNLOGGED BATCH " +
+                "UPDATE %1$s SET first = first + 1 WHERE userid = 2 AND url = 
'http://bad.com'; " +
+                "UPDATE %1$s SET first = first + 1, second = second + 1 WHERE 
userid = 3 AND url = 'http://bar.com'; " +
+                "UPDATE %1$s SET first = first - 1, second = second - 1 WHERE 
userid = 4 AND url = 'http://bar.com'; " +
+                "UPDATE %1$s SET second = second + 1 WHERE userid = 5 AND url 
= 'http://baz.com'; " +
+                "APPLY BATCH; ");
+        assertRowsIgnoringOrder(execute("SELECT userid, url, first, second, 
third FROM %s WHERE userid IN (2, 3, 4, 5)"),
+                row(2, "http://bad.com";, 1L, null, null),
+                row(3, "http://bar.com";, 1L, 1L, null),
+                row(4, "http://bar.com";, -1L, -1L, null),
+                row(5, "http://baz.com";, null, 1L, null));
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to