adelapena commented on a change in pull request #890:
URL: https://github.com/apache/cassandra/pull/890#discussion_r578407159
##########
File path: test/unit/org/apache/cassandra/db/filter/ColumnFilterTest.java
##########
@@ -33,20 +38,24 @@
public class ColumnFilterTest
{
+ private final static Logger logger =
LoggerFactory.getLogger(ColumnFilterTest.class);
+
final static ColumnFilter.Serializer serializer = new
ColumnFilter.Serializer();
+ private final Supplier<CFMetaData> metadataSupplier = Suppliers.memoize(()
-> CFMetaData.Builder
Review comment:
Do we need memoization here, instead of just plainly initializing the
`CFMetadata`?
##########
File path: test/unit/org/apache/cassandra/db/filter/ColumnFilterTest.java
##########
@@ -33,20 +38,24 @@
public class ColumnFilterTest
{
+ private final static Logger logger =
LoggerFactory.getLogger(ColumnFilterTest.class);
Review comment:
It seems this logger is not used
##########
File path:
test/distributed/org/apache/cassandra/distributed/test/ReadDigestConsistencyTest.java
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.distributed.test;
+
+import java.util.Arrays;
+import java.util.UUID;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+import org.apache.cassandra.distributed.shared.DistributedTestBase;
+
+public class ReadDigestConsistencyTest extends TestBaseImpl
+{
+ public static final String TABLE_NAME = "tbl";
+ public static final String CREATE_TABLE = String.format("CREATE TABLE
%s.%s (key int, s1 text static, c1 text, c2 text, c3 text, PRIMARY KEY (key,
c1))", DistributedTestBase.KEYSPACE, TABLE_NAME);
+ public static final String INSERT = String.format("INSERT INTO %s.%s (key,
s1, c1, c2, c3) VALUES (?, ?, ?, ?, ?)", DistributedTestBase.KEYSPACE,
TABLE_NAME);
+
+ public static final String SELECT_C1 = String.format("SELECT key, c1 FROM
%s.%s WHERE key = ?", DistributedTestBase.KEYSPACE, TABLE_NAME);
+ public static final String SELECT_C1_S1_ROW = String.format("SELECT key,
c1, s1 FROM %s.%s WHERE key = ? and c1 = ? ", DistributedTestBase.KEYSPACE,
TABLE_NAME);
+ public static final String SELECT_TRACE = "SELECT activity FROM
system_traces.events where session_id = ? and source = ? ALLOW FILTERING;";
+
+ @Test
+ public void testDigestConsistency() throws Exception
+ {
+ try (Cluster cluster = init(builder().withNodes(2).start()))
+ {
+ cluster.schemaChange(CREATE_TABLE);
+ cluster.coordinator(1).execute(INSERT, ConsistencyLevel.ALL, 1,
"static", "foo", "bar", "baz");
+ cluster.coordinator(1).execute(INSERT, ConsistencyLevel.ALL, 1,
"static", "fi", "biz", "baz");
+ cluster.coordinator(1).execute(INSERT, ConsistencyLevel.ALL, 1,
"static", "fo", "boz", "baz");
+
+ checkTraceForDigestMismatch(cluster, 1, SELECT_C1, 1);
+ checkTraceForDigestMismatch(cluster, 2, SELECT_C1, 1);
+ checkTraceForDigestMismatch(cluster, 1, SELECT_C1_S1_ROW, 1,
"foo");
+ checkTraceForDigestMismatch(cluster, 2, SELECT_C1_S1_ROW, 1, "fi");
+ }
+ }
+
+ public static void checkTraceForDigestMismatch(Cluster cluster, int
coordinatorNode, String query, Object... boundValues)
Review comment:
Nit: the method could be private.
##########
File path: test/unit/org/apache/cassandra/db/filter/ColumnFilterTest.java
##########
@@ -59,6 +68,17 @@ public void columnFilterSerialisationRoundTrip() throws
Exception
testRoundTrip(ColumnFilter.selection(metadata,
metadata.partitionColumns().without(v1)), metadata,
MessagingService.VERSION_3014);
}
+ @Test
+ public void testToString()
+ {
+ CFMetaData metadata = metadataSupplier.get();
+ ColumnDefinition v1 =
metadata.getColumnDefinition(ByteBufferUtil.bytes("v1"));
+
+ Assert.assertEquals("*/*", ColumnFilter.all(metadata).toString());
+ Assert.assertEquals("[v2, v3]",
ColumnFilter.selection(metadata.partitionColumns().without(v1)).toString());
+ Assert.assertEquals("*/[v2, v3]", ColumnFilter.selection(metadata,
metadata.partitionColumns().without(v1)).toString());
Review comment:
I think we could easily extend the test coverage of
`ColumnFilter#toString` to subselections if, for example, we declare one of the
columns in the table metadata as a not-frozen collection:
```java
.addRegularColumn("v3", SetType.getInstance(Int32Type.instance, true))
```
and then we test:
```java
Assert.assertEquals("[]",
ColumnFilter.selectionBuilder().build().toString());
Assert.assertEquals("[v3[1], v3[2]]",
ColumnFilter.selectionBuilder().select(v3, c2).select(v3,
c1).build().toString());
Assert.assertEquals("[v3[1:2]]", ColumnFilter.selectionBuilder().slice(v3,
c1, c2).build().toString());
Assert.assertEquals("*/[v3[1], v3[2]]",
ColumnFilter.allColumnsBuilder(metadata).select(v3, c2).select(v3,
c1).build().toString());
Assert.assertEquals("*/[v3[1:2]]",
ColumnFilter.allColumnsBuilder(metadata).slice(v3, c1, c2).build().toString());
```
##########
File path:
test/distributed/org/apache/cassandra/distributed/test/ReadDigestConsistencyTest.java
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.distributed.test;
+
+import java.util.Arrays;
+import java.util.UUID;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+import org.apache.cassandra.distributed.shared.DistributedTestBase;
+
+public class ReadDigestConsistencyTest extends TestBaseImpl
+{
+ public static final String TABLE_NAME = "tbl";
+ public static final String CREATE_TABLE = String.format("CREATE TABLE
%s.%s (key int, s1 text static, c1 text, c2 text, c3 text, PRIMARY KEY (key,
c1))", DistributedTestBase.KEYSPACE, TABLE_NAME);
+ public static final String INSERT = String.format("INSERT INTO %s.%s (key,
s1, c1, c2, c3) VALUES (?, ?, ?, ?, ?)", DistributedTestBase.KEYSPACE,
TABLE_NAME);
+
+ public static final String SELECT_C1 = String.format("SELECT key, c1 FROM
%s.%s WHERE key = ?", DistributedTestBase.KEYSPACE, TABLE_NAME);
+ public static final String SELECT_C1_S1_ROW = String.format("SELECT key,
c1, s1 FROM %s.%s WHERE key = ? and c1 = ? ", DistributedTestBase.KEYSPACE,
TABLE_NAME);
Review comment:
Nit: we don't need the `DistributedTestBase .` prefix, nor the import of
`DistributedTestBase` above.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]