diff --git a/test/burn/org/apache/cassandra/transport/BurnTestUtil.java b/test/burn/org/apache/cassandra/transport/BurnTestUtil.java index e7bf6b85c4..961045514b 100644 --- a/test/burn/org/apache/cassandra/transport/BurnTestUtil.java +++ b/test/burn/org/apache/cassandra/transport/BurnTestUtil.java @@ -65,7 +65,7 @@ public class BurnTestUtil return new SimpleStatement(Integer.toString(idx), (Object[]) values); } - public static QueryMessage generateQueryMessage(int idx, SizeCaps sizeCaps) + public static QueryMessage generateQueryMessage(int idx, SizeCaps sizeCaps, ProtocolVersion version) { Random rnd = new Random(idx); List values = new ArrayList<>(); @@ -78,7 +78,7 @@ public class BurnTestUtil 10, null, null, - ProtocolVersion.V4, + version, "KEYSPACE"); return new QueryMessage(Integer.toString(idx), queryOptions); diff --git a/test/burn/org/apache/cassandra/transport/DriverBurnTest.java b/test/burn/org/apache/cassandra/transport/DriverBurnTest.java index a5e5261100..74f81559a7 100644 --- a/test/burn/org/apache/cassandra/transport/DriverBurnTest.java +++ b/test/burn/org/apache/cassandra/transport/DriverBurnTest.java @@ -33,7 +33,6 @@ import org.junit.Test; import com.datastax.driver.core.*; import io.netty.buffer.ByteBuf; -import org.apache.cassandra.config.EncryptionOptions; import org.apache.cassandra.cql3.CQLTester; import org.apache.cassandra.service.NativeTransportService; import org.apache.cassandra.service.QueryState; @@ -185,13 +184,25 @@ public class DriverBurnTest extends CQLTester } @Test - public void measureSmallV5() throws Throwable + public void measureSmallV6() throws Throwable { perfTest(new SizeCaps(10, 20, 5, 10), new SizeCaps(10, 20, 5, 10), Cluster.builder().addContactPoint(nativeAddr.getHostAddress()) .allowBetaProtocolVersion() - .withPort(nativePort)); + .withPort(nativePort), + ProtocolVersion.V6); + } + + @Test + public void measureSmallV5() throws Throwable + { + perfTest(new SizeCaps(10, 20, 5, 10), + new SizeCaps(10, 20, 5, 10), + Cluster.builder().addContactPoint(nativeAddr.getHostAddress()) + .withProtocolVersion(com.datastax.driver.core.ProtocolVersion.V5) + .withPort(nativePort), + ProtocolVersion.V5); } @Test @@ -201,7 +212,19 @@ public class DriverBurnTest extends CQLTester new SizeCaps(10, 20, 5, 10), Cluster.builder().addContactPoint(nativeAddr.getHostAddress()) .withProtocolVersion(com.datastax.driver.core.ProtocolVersion.V4) - .withPort(nativePort)); + .withPort(nativePort), + ProtocolVersion.V4); + } + + @Test + public void measureLargeV6() throws Throwable + { + perfTest(new SizeCaps(1000, 2000, 5, 150), + new SizeCaps(1000, 2000, 5, 150), + Cluster.builder().addContactPoint(nativeAddr.getHostAddress()) + .allowBetaProtocolVersion() + .withPort(nativePort), + ProtocolVersion.V6); } @Test @@ -210,8 +233,9 @@ public class DriverBurnTest extends CQLTester perfTest(new SizeCaps(1000, 2000, 5, 150), new SizeCaps(1000, 2000, 5, 150), Cluster.builder().addContactPoint(nativeAddr.getHostAddress()) - .allowBetaProtocolVersion() - .withPort(nativePort)); + .withProtocolVersion(com.datastax.driver.core.ProtocolVersion.V5) + .withPort(nativePort), + ProtocolVersion.V5); } @Test @@ -221,18 +245,32 @@ public class DriverBurnTest extends CQLTester new SizeCaps(1000, 2000, 5, 150), Cluster.builder().addContactPoint(nativeAddr.getHostAddress()) .withProtocolVersion(com.datastax.driver.core.ProtocolVersion.V4) - .withPort(nativePort)); + .withPort(nativePort), + ProtocolVersion.V4); } @Test - public void measureSmallV5ithCompression() throws Throwable + public void measureSmallV6WithCompression() throws Throwable { perfTest(new SizeCaps(10, 20, 5, 10), new SizeCaps(10, 20, 5, 10), Cluster.builder().addContactPoint(nativeAddr.getHostAddress()) .allowBetaProtocolVersion() .withCompression(ProtocolOptions.Compression.LZ4) - .withPort(nativePort)); + .withPort(nativePort), + ProtocolVersion.V6); + } + + @Test + public void measureSmallV5WithCompression() throws Throwable + { + perfTest(new SizeCaps(10, 20, 5, 10), + new SizeCaps(10, 20, 5, 10), + Cluster.builder().addContactPoint(nativeAddr.getHostAddress()) + .withProtocolVersion(com.datastax.driver.core.ProtocolVersion.V5) + .withCompression(ProtocolOptions.Compression.LZ4) + .withPort(nativePort), + ProtocolVersion.V5); } @Test @@ -243,7 +281,20 @@ public class DriverBurnTest extends CQLTester Cluster.builder().addContactPoint(nativeAddr.getHostAddress()) .withProtocolVersion(com.datastax.driver.core.ProtocolVersion.V4) .withCompression(ProtocolOptions.Compression.LZ4) - .withPort(nativePort)); + .withPort(nativePort), + ProtocolVersion.V4); + } + + @Test + public void measureLargeV6WithCompression() throws Throwable + { + perfTest(new SizeCaps(1000, 2000, 5, 150), + new SizeCaps(1000, 2000, 5, 150), + Cluster.builder().addContactPoint(nativeAddr.getHostAddress()) + .allowBetaProtocolVersion() + .withCompression(ProtocolOptions.Compression.LZ4) + .withPort(nativePort), + ProtocolVersion.V6); } @Test @@ -252,9 +303,10 @@ public class DriverBurnTest extends CQLTester perfTest(new SizeCaps(1000, 2000, 5, 150), new SizeCaps(1000, 2000, 5, 150), Cluster.builder().addContactPoint(nativeAddr.getHostAddress()) - .allowBetaProtocolVersion() + .withProtocolVersion(com.datastax.driver.core.ProtocolVersion.V5) .withCompression(ProtocolOptions.Compression.LZ4) - .withPort(nativePort)); + .withPort(nativePort), + ProtocolVersion.V5); } @Test @@ -265,18 +317,19 @@ public class DriverBurnTest extends CQLTester Cluster.builder().addContactPoint(nativeAddr.getHostAddress()) .withProtocolVersion(com.datastax.driver.core.ProtocolVersion.V4) .withCompression(ProtocolOptions.Compression.LZ4) - .withPort(nativePort)); + .withPort(nativePort), + ProtocolVersion.V4); } - public void perfTest(SizeCaps requestCaps, SizeCaps responseCaps, Cluster.Builder builder) throws Throwable + public void perfTest(SizeCaps requestCaps, SizeCaps responseCaps, Cluster.Builder builder, ProtocolVersion version) throws Throwable { SimpleStatement request = generateQueryStatement(0, requestCaps); ResultMessage.Rows response = generateRows(0, responseCaps); - QueryMessage requestMessage = generateQueryMessage(0, requestCaps); - Envelope message = requestMessage.encode(ProtocolVersion.V4); + QueryMessage requestMessage = generateQueryMessage(0, requestCaps, version); + Envelope message = requestMessage.encode(version); int requestSize = message.body.readableBytes(); message.release(); - message = response.encode(ProtocolVersion.V4); + message = response.encode(version); int responseSize = message.body.readableBytes(); message.release(); Message.Type.QUERY.unsafeSetCodec(new Message.Codec() { diff --git a/test/burn/org/apache/cassandra/transport/SimpleClientBurnTest.java b/test/burn/org/apache/cassandra/transport/SimpleClientBurnTest.java index 448e790b5a..7e57916eb1 100644 --- a/test/burn/org/apache/cassandra/transport/SimpleClientBurnTest.java +++ b/test/burn/org/apache/cassandra/transport/SimpleClientBurnTest.java @@ -167,7 +167,7 @@ public class SimpleClientBurnTest { int descriptor = counter + j * 100 + threadId * 10000; SizeCaps caps = descriptor % largeMessageFrequency == 0 ? largeMessageCap : smallMessageCap; - QueryMessage query = generateQueryMessage(descriptor, caps); + QueryMessage query = generateQueryMessage(descriptor, caps, client.connection.getVersion()); messages.add(query); } diff --git a/test/burn/org/apache/cassandra/transport/SimpleClientPerfTest.java b/test/burn/org/apache/cassandra/transport/SimpleClientPerfTest.java index f76d2eede3..47145356cd 100644 --- a/test/burn/org/apache/cassandra/transport/SimpleClientPerfTest.java +++ b/test/burn/org/apache/cassandra/transport/SimpleClientPerfTest.java @@ -20,20 +20,20 @@ package org.apache.cassandra.transport; import java.net.InetAddress; import java.net.ServerSocket; -import java.security.SecureRandom; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import java.util.stream.Collectors; import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import io.netty.buffer.ByteBuf; import org.apache.cassandra.auth.AllowAllAuthenticator; @@ -51,10 +51,19 @@ import static org.apache.cassandra.transport.BurnTestUtil.SizeCaps; import static org.apache.cassandra.transport.BurnTestUtil.generateQueryMessage; import static org.apache.cassandra.transport.BurnTestUtil.generateRows; +@RunWith(Parameterized.class) public class SimpleClientPerfTest { + @Parameterized.Parameter + public ProtocolVersion version; - private static final Logger logger = LoggerFactory.getLogger(CQLConnectionTest.class); + @Parameterized.Parameters() + public static Collection versions() + { + return ProtocolVersion.SUPPORTED.stream() + .map(v -> new Object[]{v}) + .collect(Collectors.toList()); + } private InetAddress address; private int port; @@ -82,102 +91,61 @@ public class SimpleClientPerfTest } @Test - public void measureSmallV5() throws Throwable + public void measureSmall() throws Throwable { perfTest(new SizeCaps(10, 20, 5, 10), new SizeCaps(10, 20, 5, 10), () -> new SimpleClient(address.getHostAddress(), - port, ProtocolVersion.V5, true, + port, version, true, new EncryptionOptions()) - .connect(false)); + .connect(false), + version); } - @Test - public void measureSmallV4() throws Throwable + public void measureSmallWithCompression() throws Throwable { perfTest(new SizeCaps(10, 20, 5, 10), new SizeCaps(10, 20, 5, 10), () -> new SimpleClient(address.getHostAddress(), - port, ProtocolVersion.V4, false, - new EncryptionOptions()) - .connect(false)); - } - - @Test - public void measureSmallV5WithCompression() throws Throwable - { - perfTest(new SizeCaps(10, 20, 5, 10), - new SizeCaps(10, 20, 5, 10), - () -> new SimpleClient(address.getHostAddress(), - port, ProtocolVersion.V5, true, + port, version, true, new EncryptionOptions()) - .connect(true)); + .connect(true), + version); } @Test - public void measureSmallV4WithCompression() throws Throwable - { - perfTest(new SizeCaps(10, 20, 5, 10), - new SizeCaps(10, 20, 5, 10), - () -> new SimpleClient(address.getHostAddress(), - port, ProtocolVersion.V4, false, - new EncryptionOptions()) - .connect(true)); - } - - @Test - public void measureLargeV5() throws Throwable + public void measureLarge() throws Throwable { perfTest(new SizeCaps(1000, 2000, 5, 150), new SizeCaps(1000, 2000, 5, 150), () -> new SimpleClient(address.getHostAddress(), - port, ProtocolVersion.V5, true, + port, version, true, new EncryptionOptions()) - .connect(false)); + .connect(false), + version); } @Test - public void measureLargeV4() throws Throwable + public void measureLargeWithCompression() throws Throwable { perfTest(new SizeCaps(1000, 2000, 5, 150), new SizeCaps(1000, 2000, 5, 150), () -> new SimpleClient(address.getHostAddress(), - port, ProtocolVersion.V4, false, + port, version, true, new EncryptionOptions()) - .connect(false)); + .connect(true), + version); } - @Test - public void measureLargeV5WithCompression() throws Throwable - { - perfTest(new SizeCaps(1000, 2000, 5, 150), - new SizeCaps(1000, 2000, 5, 150), - () -> new SimpleClient(address.getHostAddress(), - port, ProtocolVersion.V5, true, - new EncryptionOptions()) - .connect(true)); - } - - @Test - public void measureLargeV4WithCompression() throws Throwable - { - perfTest(new SizeCaps(1000, 2000, 5, 150), - new SizeCaps(1000, 2000, 5, 150), - () -> new SimpleClient(address.getHostAddress(), - port, ProtocolVersion.V4, false, - new EncryptionOptions()) - .connect(true)); - } - - public void perfTest(SizeCaps requestCaps, SizeCaps responseCaps, AssertUtil.ThrowingSupplier clientSupplier) throws Throwable + public void perfTest(SizeCaps requestCaps, SizeCaps responseCaps, AssertUtil.ThrowingSupplier clientSupplier, ProtocolVersion version) throws Throwable { ResultMessage.Rows response = generateRows(0, responseCaps); - QueryMessage requestMessage = generateQueryMessage(0, requestCaps); - Envelope message = requestMessage.encode(ProtocolVersion.V4); + QueryMessage requestMessage = generateQueryMessage(0, requestCaps, version); + Envelope message = requestMessage.encode(version); int requestSize = message.body.readableBytes(); message.release(); - message = response.encode(ProtocolVersion.V4); + message = response.encode(version); int responseSize = message.body.readableBytes(); message.release(); diff --git a/test/distributed/org/apache/cassandra/distributed/impl/Coordinator.java b/test/distributed/org/apache/cassandra/distributed/impl/Coordinator.java index ec3d313cca..e31ce2c635 100644 --- a/test/distributed/org/apache/cassandra/distributed/impl/Coordinator.java +++ b/test/distributed/org/apache/cassandra/distributed/impl/Coordinator.java @@ -107,7 +107,7 @@ public class Coordinator implements ICoordinator Integer.MAX_VALUE, null, null, - ProtocolVersion.V4, + ProtocolVersion.CURRENT, null), System.nanoTime()); diff --git a/test/unit/org/apache/cassandra/cql3/ViewComplexTest.java b/test/long/org/apache/cassandra/cql3/ViewComplexTest.java similarity index 96% rename from test/unit/org/apache/cassandra/cql3/ViewComplexTest.java rename to test/long/org/apache/cassandra/cql3/ViewComplexTest.java index e6a790a831..b5dc021599 100644 --- a/test/unit/org/apache/cassandra/cql3/ViewComplexTest.java +++ b/test/long/org/apache/cassandra/cql3/ViewComplexTest.java @@ -25,6 +25,7 @@ import static org.junit.Assert.fail; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; @@ -45,13 +46,28 @@ import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.Timeout; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import com.google.common.base.Objects; +@RunWith(Parameterized.class) public class ViewComplexTest extends CQLTester { - ProtocolVersion protocolVersion = ProtocolVersion.V4; + @Parameterized.Parameter + public ProtocolVersion version; + + @Parameterized.Parameters() + public static Collection versions() + { + return ProtocolVersion.SUPPORTED.stream() + .map(v -> new Object[]{v}) + .collect(Collectors.toList()); + } + private final List views = new ArrayList<>(); @BeforeClass @@ -70,14 +86,14 @@ public class ViewComplexTest extends CQLTester public void end() throws Throwable { for (String viewName : views) - executeNet(protocolVersion, "DROP MATERIALIZED VIEW " + viewName); + executeNet(version, "DROP MATERIALIZED VIEW " + viewName); } private void createView(String name, String query) throws Throwable { try { - executeNet(protocolVersion, String.format(query, name)); + executeNet(version, String.format(query, name)); // If exception is thrown, the view will not be added to the list; since it shouldn't have been created, this is // the desired behavior views.add(name); @@ -97,7 +113,7 @@ public class ViewComplexTest extends CQLTester private void updateViewWithFlush(String query, boolean flush, Object... params) throws Throwable { - executeNet(protocolVersion, query, params); + executeNet(version, query, params); while (!(((SEPExecutor) Stage.VIEW_MUTATION.executor()).getPendingTaskCount() == 0 && ((SEPExecutor) Stage.VIEW_MUTATION.executor()).getActiveTaskCount() == 0)) { @@ -114,7 +130,7 @@ public class ViewComplexTest extends CQLTester { boolean flush = true; execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); createTable("CREATE TABLE %s (k int, c int, a int, b int, PRIMARY KEY (k, c))"); createView("mv", "CREATE MATERIALIZED VIEW %s AS SELECT k,c FROM %%s WHERE k IS NOT NULL AND c IS NOT NULL PRIMARY KEY (k,c)"); @@ -168,7 +184,7 @@ public class ViewComplexTest extends CQLTester private void testPartialDeleteSelectedColumn(boolean flush) throws Throwable { execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); createTable("CREATE TABLE %s (k int, c int, a int, b int, e int, f int, PRIMARY KEY (k, c))"); createView("mv", "CREATE MATERIALIZED VIEW %s AS SELECT a, b, c, k FROM %%s WHERE k IS NOT NULL AND c IS NOT NULL PRIMARY KEY (k,c)"); @@ -261,7 +277,7 @@ public class ViewComplexTest extends CQLTester createTable("create table %s (k int primary key, a int, b int)"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); createView("mv", @@ -351,7 +367,7 @@ public class ViewComplexTest extends CQLTester String baseTable = createTable("create table %s (p int, c int, v1 int, v2 int, primary key(p, c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); createView("mv", @@ -452,7 +468,7 @@ public class ViewComplexTest extends CQLTester public void testPartialUpdateWithUnselectedCollections(boolean flush) throws Throwable { execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); String baseTable = createTable("CREATE TABLE %s (k int, c int, a int, b int, l list, s set, m map, PRIMARY KEY (k, c))"); createView("mv", "CREATE MATERIALIZED VIEW %s AS SELECT a, b, c, k FROM %%s WHERE k IS NOT NULL AND c IS NOT NULL PRIMARY KEY (c, k)"); @@ -490,7 +506,7 @@ public class ViewComplexTest extends CQLTester assertRowsIgnoringOrder(execute("SELECT * from mv"), row(1, 1, null, null)); assertInvalidMessage(String.format("Cannot drop column m on base table %s with materialized views", baseTable), "ALTER TABLE %s DROP m"); - // executeNet(protocolVersion, "ALTER TABLE %s DROP m"); + // executeNet(version, "ALTER TABLE %s DROP m"); // ks.getColumnFamilyStore("mv").forceMajorCompaction(); // assertRowsIgnoringOrder(execute("SELECT k,c,a,b from %s WHERE k = 1 AND c = 1")); // assertRowsIgnoringOrder(execute("SELECT * from mv WHERE k = 1 AND c = 1")); @@ -518,7 +534,7 @@ public class ViewComplexTest extends CQLTester createTable("create table %s (p int, c int, v int, primary key(p, c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); createView("mv", @@ -580,7 +596,7 @@ public class ViewComplexTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); createView("mv_test1", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE a IS NOT NULL AND b IS NOT NULL PRIMARY KEY (a, b)"); @@ -622,7 +638,7 @@ public class ViewComplexTest extends CQLTester createTable("create table %s (p int, c int, v int, primary key(p, c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); updateView("INSERT INTO %s (p, c, v) VALUES (0, 0, 0) using timestamp 1;"); @@ -674,7 +690,7 @@ public class ViewComplexTest extends CQLTester createTable("create table %s (p int primary key, v1 int, v2 int)"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); createView("mv", @@ -741,7 +757,7 @@ public class ViewComplexTest extends CQLTester createTable("create table %s (k int, c int, a int, b int, PRIMARY KEY(k, c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); createView("mv", @@ -803,7 +819,7 @@ public class ViewComplexTest extends CQLTester createTable("create table %s (p int primary key, v1 int, v2 int)"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); createView("mv", @@ -852,7 +868,7 @@ public class ViewComplexTest extends CQLTester createTable("CREATE TABLE %s (k int PRIMARY KEY, a int, b int);"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); createView("mv1", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE k IS NOT NULL AND a IS NOT NULL PRIMARY KEY (k, a);"); @@ -878,10 +894,10 @@ public class ViewComplexTest extends CQLTester for (String view : Arrays.asList("mv1", "mv2")) { // paging - assertEquals(1, executeNetWithPaging(protocolVersion, String.format("SELECT k,a,b FROM %s limit 1", view), 1).all().size()); - assertEquals(2, executeNetWithPaging(protocolVersion, String.format("SELECT k,a,b FROM %s limit 2", view), 1).all().size()); - assertEquals(2, executeNetWithPaging(protocolVersion, String.format("SELECT k,a,b FROM %s", view), 1).all().size()); - assertRowsNet(protocolVersion, executeNetWithPaging(protocolVersion, String.format("SELECT k,a,b FROM %s ", view), 1), + assertEquals(1, executeNetWithPaging(version, String.format("SELECT k,a,b FROM %s limit 1", view), 1).all().size()); + assertEquals(2, executeNetWithPaging(version, String.format("SELECT k,a,b FROM %s limit 2", view), 1).all().size()); + assertEquals(2, executeNetWithPaging(version, String.format("SELECT k,a,b FROM %s", view), 1).all().size()); + assertRowsNet(version, executeNetWithPaging(version, String.format("SELECT k,a,b FROM %s ", view), 1), row(50, 50, 50), row(100, 100, 100)); // limit @@ -912,7 +928,7 @@ public class ViewComplexTest extends CQLTester String baseTable = createTable("CREATE TABLE %s (k int PRIMARY KEY, a int, b int);"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); createView("mv", @@ -978,7 +994,7 @@ public class ViewComplexTest extends CQLTester createTable("create table %s (p1 int, p2 int, v1 int, v2 int, primary key (p1,p2))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); createView("mv", @@ -1030,7 +1046,7 @@ public class ViewComplexTest extends CQLTester createTable("create table %s (p int primary key, v1 int, v2 int)"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); createView("mv", @@ -1092,7 +1108,7 @@ public class ViewComplexTest extends CQLTester createTable("create table %s (p int primary key, v1 int, v2 int)"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); createView("mv", @@ -1165,7 +1181,7 @@ public class ViewComplexTest extends CQLTester createTable("create table %s (p1 int, p2 int, v1 int, v2 int, primary key(p1, p2))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); createView("mv2", @@ -1226,7 +1242,7 @@ public class ViewComplexTest extends CQLTester createTable("create table %s (p int primary key, v1 int, v2 int)"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); createView("mv", @@ -1265,7 +1281,7 @@ public class ViewComplexTest extends CQLTester assertRowsIgnoringOrder(execute("SELECT * from mv limit 1"), row(1, 3, null)); // insert values TS=2, it should be considered dead due to previous tombstone - executeNet(protocolVersion, "UPDATE %s USING TIMESTAMP 3 SET v2 = ? WHERE p = ?", 4, 3); + executeNet(version, "UPDATE %s USING TIMESTAMP 3 SET v2 = ? WHERE p = ?", 4, 3); if (flush) FBUtilities.waitOnFutures(ks.flush()); @@ -1294,7 +1310,7 @@ public class ViewComplexTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, f int, PRIMARY KEY(a, b))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); List viewNames = new ArrayList<>(); List mvStatements = Arrays.asList( // all selected diff --git a/test/unit/org/apache/cassandra/cql3/ViewFilteringTest.java b/test/long/org/apache/cassandra/cql3/ViewFilteringTest.java similarity index 96% rename from test/unit/org/apache/cassandra/cql3/ViewFilteringTest.java rename to test/long/org/apache/cassandra/cql3/ViewFilteringTest.java index bc52321142..c8b130db7e 100644 --- a/test/unit/org/apache/cassandra/cql3/ViewFilteringTest.java +++ b/test/long/org/apache/cassandra/cql3/ViewFilteringTest.java @@ -19,6 +19,7 @@ package org.apache.cassandra.cql3; import java.util.*; +import java.util.stream.Collectors; import org.junit.After; import org.junit.AfterClass; @@ -29,6 +30,8 @@ import org.junit.Test; import com.datastax.driver.core.exceptions.InvalidQueryException; import org.junit.Assert; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import com.datastax.driver.core.exceptions.OperationTimedOutException; import org.apache.cassandra.concurrent.SEPExecutor; @@ -38,9 +41,20 @@ import org.apache.cassandra.db.SystemKeyspace; import org.apache.cassandra.transport.ProtocolVersion; import org.apache.cassandra.utils.FBUtilities; +@RunWith(Parameterized.class) public class ViewFilteringTest extends CQLTester { - ProtocolVersion protocolVersion = ProtocolVersion.V4; + @Parameterized.Parameter + public ProtocolVersion version; + + @Parameterized.Parameters() + public static Collection versions() + { + return ProtocolVersion.SUPPORTED.stream() + .map(v -> new Object[]{v}) + .collect(Collectors.toList()); + } + private final List views = new ArrayList<>(); @BeforeClass @@ -66,14 +80,14 @@ public class ViewFilteringTest extends CQLTester public void end() throws Throwable { for (String viewName : views) - executeNet(protocolVersion, "DROP MATERIALIZED VIEW " + viewName); + executeNet(version, "DROP MATERIALIZED VIEW " + viewName); } private void createView(String name, String query) throws Throwable { try { - executeNet(protocolVersion, String.format(query, name)); + executeNet(version, String.format(query, name)); // If exception is thrown, the view will not be added to the list; since it shouldn't have been created, this is // the desired behavior views.add(name); @@ -88,7 +102,7 @@ public class ViewFilteringTest extends CQLTester private void updateView(String query, Object... params) throws Throwable { - executeNet(protocolVersion, query, params); + executeNet(version, query, params); while (!(((SEPExecutor) Stage.VIEW_MUTATION.executor()).getPendingTaskCount() == 0 && ((SEPExecutor) Stage.VIEW_MUTATION.executor()).getActiveTaskCount() == 0)) { @@ -98,7 +112,7 @@ public class ViewFilteringTest extends CQLTester private void dropView(String name) throws Throwable { - executeNet(protocolVersion, "DROP MATERIALIZED VIEW " + name); + executeNet(version, "DROP MATERIALIZED VIEW " + name); views.remove(name); } @@ -124,7 +138,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); createView("mv_test1", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE a IS NOT NULL AND b IS NOT NULL and c = 1 PRIMARY KEY (a, b)"); @@ -334,7 +348,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, l list, s set, m map, PRIMARY KEY (a, b))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); createView("mv_test1", "CREATE MATERIALIZED VIEW %s AS SELECT a,b,c FROM %%s WHERE a IS NOT NULL AND b IS NOT NULL AND c IS NOT NULL " @@ -420,7 +434,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, PRIMARY KEY((a, b), c, d))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); // IS NOT NULL is required on all PK statements that are not otherwise restricted List badStatements = Arrays.asList( @@ -470,7 +484,7 @@ public class ViewFilteringTest extends CQLTester try { - executeNet(protocolVersion, "ALTER MATERIALIZED VIEW mv" + i + "_test WITH compaction = { 'class' : 'LeveledCompactionStrategy' }"); + executeNet(version, "ALTER MATERIALIZED VIEW mv" + i + "_test WITH compaction = { 'class' : 'LeveledCompactionStrategy' }"); } catch (Exception e) { @@ -485,7 +499,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (\"theKey\" int, \"theClustering\" int, \"the\"\"Value\" int, PRIMARY KEY (\"theKey\", \"theClustering\"))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (\"theKey\", \"theClustering\", \"the\"\"Value\") VALUES (?, ?, ?)", 0, 0, 0); execute("INSERT INTO %s (\"theKey\", \"theClustering\", \"the\"\"Value\") VALUES (?, ?, ?)", 0, 1, 0); @@ -511,7 +525,7 @@ public class ViewFilteringTest extends CQLTester ); } - executeNet(protocolVersion, "ALTER TABLE %s RENAME \"theClustering\" TO \"Col\""); + executeNet(version, "ALTER TABLE %s RENAME \"theClustering\" TO \"Col\""); for (String mvname : Arrays.asList("mv_test", "mv_test2")) { @@ -527,7 +541,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY (a, b))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 0, 0); execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 1, 1); @@ -546,7 +560,7 @@ public class ViewFilteringTest extends CQLTester row(1, 1, 3) ); - executeNet(protocolVersion, "ALTER TABLE %s RENAME a TO foo"); + executeNet(version, "ALTER TABLE %s RENAME a TO foo"); assertRows(execute("SELECT foo, b, c FROM mv_test"), row(1, 0, 2), @@ -560,7 +574,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY (a, b))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 0, 0); execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 1, 1); @@ -579,7 +593,7 @@ public class ViewFilteringTest extends CQLTester row(1, 1, 3) ); - executeNet(protocolVersion, "ALTER TABLE %s RENAME a TO foo"); + executeNet(version, "ALTER TABLE %s RENAME a TO foo"); assertRows(execute("SELECT foo, b, c FROM mv_test"), row(1, 0, 2), @@ -596,7 +610,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY ((a, b), c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 0, 0); @@ -701,7 +715,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY ((a, b), c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 1); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 10, 1, 2); @@ -800,7 +814,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 0, 0); @@ -901,7 +915,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY ((a, b), c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 0); @@ -989,7 +1003,7 @@ public class ViewFilteringTest extends CQLTester { createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY ((a, b), c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 0); @@ -1078,7 +1092,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 0); @@ -1187,7 +1201,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 0); @@ -1295,7 +1309,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 0); @@ -1412,7 +1426,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 0); @@ -1525,7 +1539,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 0); @@ -1650,7 +1664,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 0); @@ -1788,7 +1802,7 @@ public class ViewFilteringTest extends CQLTester "PRIMARY KEY (" + columnNames + "))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); createView( @@ -1844,7 +1858,7 @@ public class ViewFilteringTest extends CQLTester assert !execute("SELECT * FROM mv_test").isEmpty(); - executeNet(protocolVersion, "ALTER TABLE %s RENAME inetval TO foo"); + executeNet(version, "ALTER TABLE %s RENAME inetval TO foo"); assert !execute("SELECT * FROM mv_test").isEmpty(); } @@ -1854,7 +1868,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); try { createView("mv_test", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE a IS NOT NULL AND b IS NOT NULL AND c IS NOT NULL AND d = 1 PRIMARY KEY (a, b, c)"); @@ -1872,7 +1886,7 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0); execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 0); @@ -1984,28 +1998,28 @@ public class ViewFilteringTest extends CQLTester createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, PRIMARY KEY (a, b))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); Keyspace ks = Keyspace.open(keyspace()); createView("mv", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE a IS NOT NULL AND b IS NOT NULL AND c IS NOT NULL AND c = 1 PRIMARY KEY (c, a, b)"); ks.getColumnFamilyStore("mv").disableAutoCompaction(); //Set initial values TS=0, matching the restriction and verify view - executeNet(protocolVersion, "INSERT INTO %s (a, b, c, d) VALUES (0, 0, 1, 0) USING TIMESTAMP 0"); + executeNet(version, "INSERT INTO %s (a, b, c, d) VALUES (0, 0, 1, 0) USING TIMESTAMP 0"); assertRows(execute("SELECT d from mv WHERE c = ? and a = ? and b = ?", 1, 0, 0), row(0)); if (flush) FBUtilities.waitOnFutures(ks.flush()); //update c's timestamp TS=2 - executeNet(protocolVersion, "UPDATE %s USING TIMESTAMP 2 SET c = ? WHERE a = ? and b = ? ", 1, 0, 0); + executeNet(version, "UPDATE %s USING TIMESTAMP 2 SET c = ? WHERE a = ? and b = ? ", 1, 0, 0); assertRows(execute("SELECT d from mv WHERE c = ? and a = ? and b = ?", 1, 0, 0), row(0)); if (flush) FBUtilities.waitOnFutures(ks.flush()); //change c's value and TS=3, tombstones c=1 and adds c=0 record - executeNet(protocolVersion, "UPDATE %s USING TIMESTAMP 3 SET c = ? WHERE a = ? and b = ? ", 0, 0, 0); + executeNet(version, "UPDATE %s USING TIMESTAMP 3 SET c = ? WHERE a = ? and b = ? ", 0, 0, 0); assertRows(execute("SELECT d from mv WHERE c = ? and a = ? and b = ?", 0, 0, 0)); if(flush) @@ -2015,7 +2029,7 @@ public class ViewFilteringTest extends CQLTester } //change c's value back to 1 with TS=4, check we can see d - executeNet(protocolVersion, "UPDATE %s USING TIMESTAMP 4 SET c = ? WHERE a = ? and b = ? ", 1, 0, 0); + executeNet(version, "UPDATE %s USING TIMESTAMP 4 SET c = ? WHERE a = ? and b = ? ", 1, 0, 0); if (flush) { ks.getColumnFamilyStore("mv").forceMajorCompaction(); @@ -2026,7 +2040,7 @@ public class ViewFilteringTest extends CQLTester //Add e value @ TS=1 - executeNet(protocolVersion, "UPDATE %s USING TIMESTAMP 1 SET e = ? WHERE a = ? and b = ? ", 1, 0, 0); + executeNet(version, "UPDATE %s USING TIMESTAMP 1 SET e = ? WHERE a = ? and b = ? ", 1, 0, 0); assertRows(execute("SELECT d, e from mv WHERE c = ? and a = ? and b = ?", 1, 0, 0), row(0, 1)); if (flush) @@ -2034,7 +2048,7 @@ public class ViewFilteringTest extends CQLTester //Change d value @ TS=2 - executeNet(protocolVersion, "UPDATE %s USING TIMESTAMP 2 SET d = ? WHERE a = ? and b = ? ", 2, 0, 0); + executeNet(version, "UPDATE %s USING TIMESTAMP 2 SET d = ? WHERE a = ? and b = ? ", 2, 0, 0); assertRows(execute("SELECT d from mv WHERE c = ? and a = ? and b = ?", 1, 0, 0), row(2)); if (flush) @@ -2042,17 +2056,17 @@ public class ViewFilteringTest extends CQLTester //Change d value @ TS=3 - executeNet(protocolVersion, "UPDATE %s USING TIMESTAMP 3 SET d = ? WHERE a = ? and b = ? ", 1, 0, 0); + executeNet(version, "UPDATE %s USING TIMESTAMP 3 SET d = ? WHERE a = ? and b = ? ", 1, 0, 0); assertRows(execute("SELECT d from mv WHERE c = ? and a = ? and b = ?", 1, 0, 0), row(1)); //Tombstone c - executeNet(protocolVersion, "DELETE FROM %s WHERE a = ? and b = ?", 0, 0); + executeNet(version, "DELETE FROM %s WHERE a = ? and b = ?", 0, 0); assertRowsIgnoringOrder(execute("SELECT d from mv")); assertRows(execute("SELECT d from mv")); //Add back without D - executeNet(protocolVersion, "INSERT INTO %s (a, b, c) VALUES (0, 0, 1)"); + executeNet(version, "INSERT INTO %s (a, b, c) VALUES (0, 0, 1)"); //Make sure D doesn't pop back in. assertRows(execute("SELECT d from mv WHERE c = ? and a = ? and b = ?", 1, 0, 0), row((Object) null)); @@ -2060,24 +2074,24 @@ public class ViewFilteringTest extends CQLTester //New partition // insert a row with timestamp 0 - executeNet(protocolVersion, "INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?) USING TIMESTAMP 0", 1, 0, 1, 0, 0); + executeNet(version, "INSERT INTO %s (a, b, c, d, e) VALUES (?, ?, ?, ?, ?) USING TIMESTAMP 0", 1, 0, 1, 0, 0); // overwrite pk and e with timestamp 1, but don't overwrite d - executeNet(protocolVersion, "INSERT INTO %s (a, b, c, e) VALUES (?, ?, ?, ?) USING TIMESTAMP 1", 1, 0, 1, 0); + executeNet(version, "INSERT INTO %s (a, b, c, e) VALUES (?, ?, ?, ?) USING TIMESTAMP 1", 1, 0, 1, 0); // delete with timestamp 0 (which should only delete d) - executeNet(protocolVersion, "DELETE FROM %s USING TIMESTAMP 0 WHERE a = ? AND b = ?", 1, 0); + executeNet(version, "DELETE FROM %s USING TIMESTAMP 0 WHERE a = ? AND b = ?", 1, 0); assertRows(execute("SELECT a, b, c, d, e from mv WHERE c = ? and a = ? and b = ?", 1, 1, 0), row(1, 0, 1, null, 0) ); - executeNet(protocolVersion, "UPDATE %s USING TIMESTAMP 2 SET c = ? WHERE a = ? AND b = ?", 1, 1, 1); - executeNet(protocolVersion, "UPDATE %s USING TIMESTAMP 3 SET c = ? WHERE a = ? AND b = ?", 1, 1, 0); + executeNet(version, "UPDATE %s USING TIMESTAMP 2 SET c = ? WHERE a = ? AND b = ?", 1, 1, 1); + executeNet(version, "UPDATE %s USING TIMESTAMP 3 SET c = ? WHERE a = ? AND b = ?", 1, 1, 0); assertRows(execute("SELECT a, b, c, d, e from mv WHERE c = ? and a = ? and b = ?", 1, 1, 0), row(1, 0, 1, null, 0) ); - executeNet(protocolVersion, "UPDATE %s USING TIMESTAMP 3 SET d = ? WHERE a = ? AND b = ?", 0, 1, 0); + executeNet(version, "UPDATE %s USING TIMESTAMP 3 SET d = ? WHERE a = ? AND b = ?", 0, 1, 0); assertRows(execute("SELECT a, b, c, d, e from mv WHERE c = ? and a = ? and b = ?", 1, 1, 0), row(1, 0, 1, 0, 0) ); @@ -2094,7 +2108,7 @@ public class ViewFilteringTest extends CQLTester "val int)"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); createView("mv_rctstest", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE k IS NOT NULL AND c IS NOT NULL AND c = 1 PRIMARY KEY (k,c)"); @@ -2123,7 +2137,7 @@ public class ViewFilteringTest extends CQLTester "PRIMARY KEY(k, c))"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); createView("mv_tstest", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE val IS NOT NULL AND k IS NOT NULL AND c IS NOT NULL AND val = 'baz' PRIMARY KEY (val,k,c)"); diff --git a/test/long/org/apache/cassandra/cql3/ViewLongTest.java b/test/long/org/apache/cassandra/cql3/ViewLongTest.java index 3a69e11eef..de888d4df6 100644 --- a/test/long/org/apache/cassandra/cql3/ViewLongTest.java +++ b/test/long/org/apache/cassandra/cql3/ViewLongTest.java @@ -20,15 +20,19 @@ package org.apache.cassandra.cql3; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CyclicBarrier; +import java.util.stream.Collectors; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import com.datastax.driver.core.Row; import com.datastax.driver.core.exceptions.NoHostAvailableException; @@ -43,9 +47,20 @@ import org.apache.cassandra.db.Keyspace; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.WrappedRunnable; +@RunWith(Parameterized.class) public class ViewLongTest extends CQLTester { - ProtocolVersion protocolVersion = ProtocolVersion.V4; + @Parameterized.Parameter + public ProtocolVersion version; + + @Parameterized.Parameters() + public static Collection versions() + { + return ProtocolVersion.SUPPORTED.stream() + .map(v -> new Object[]{v}) + .collect(Collectors.toList()); + } + private final List views = new ArrayList<>(); @BeforeClass @@ -63,14 +78,14 @@ public class ViewLongTest extends CQLTester public void end() throws Throwable { for (String viewName : views) - executeNet(protocolVersion, "DROP MATERIALIZED VIEW " + viewName); + executeNet(version, "DROP MATERIALIZED VIEW " + viewName); } private void createView(String name, String query) throws Throwable { try { - executeNet(protocolVersion, String.format(query, name)); + executeNet(version, String.format(query, name)); // If exception is thrown, the view will not be added to the list; since it shouldn't have been created, this is // the desired behavior views.add(name); @@ -96,7 +111,7 @@ public class ViewLongTest extends CQLTester "c int," + "PRIMARY KEY (a, b))"); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); createView("mv", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE c IS NOT NULL AND a IS NOT NULL AND b IS NOT NULL PRIMARY KEY (c, a, b)"); @@ -118,7 +133,7 @@ public class ViewLongTest extends CQLTester { try { - executeNet(protocolVersion, "INSERT INTO %s (a, b, c) VALUES (?, ?, ?) USING TIMESTAMP 1", + executeNet(version, "INSERT INTO %s (a, b, c) VALUES (?, ?, ?) USING TIMESTAMP 1", 1, 1, i + writerOffset); @@ -144,7 +159,7 @@ public class ViewLongTest extends CQLTester for (int i = 0; i < writers * insertsPerWriter; i++) { - if (executeNet(protocolVersion, "SELECT COUNT(*) FROM system.batches").one().getLong(0) == 0) + if (executeNet(version, "SELECT COUNT(*) FROM system.batches").one().getLong(0) == 0) break; try { @@ -158,9 +173,9 @@ public class ViewLongTest extends CQLTester } } - int value = executeNet(protocolVersion, "SELECT c FROM %s WHERE a = 1 AND b = 1").one().getInt("c"); + int value = executeNet(version, "SELECT c FROM %s WHERE a = 1 AND b = 1").one().getInt("c"); - List rows = executeNet(protocolVersion, "SELECT c FROM " + keyspace() + ".mv").all(); + List rows = executeNet(version, "SELECT c FROM " + keyspace() + ".mv").all(); boolean containsC = false; StringBuilder others = new StringBuilder(); @@ -217,7 +232,7 @@ public class ViewLongTest extends CQLTester createTable("CREATE TABLE %s (field1 int,field2 int,date int,PRIMARY KEY ((field1), field2)) WITH default_time_to_live = 5;"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); createView("mv", "CREATE MATERIALIZED VIEW mv AS SELECT * FROM %%s WHERE field1 IS NOT NULL AND field2 IS NOT NULL AND date IS NOT NULL PRIMARY KEY ((field1), date, field2) WITH CLUSTERING ORDER BY (date desc, field2 asc);"); @@ -334,7 +349,7 @@ public class ViewLongTest extends CQLTester createTable("CREATE TABLE %s (k int,c int,a int, b int, PRIMARY KEY ((k), c)) WITH default_time_to_live = 1000;"); execute("USE " + keyspace()); - executeNet(protocolVersion, "USE " + keyspace()); + executeNet(version, "USE " + keyspace()); createView("mv", "CREATE MATERIALIZED VIEW mv AS SELECT k,c,a FROM %%s WHERE k IS NOT NULL AND c IS NOT NULL " @@ -415,7 +430,7 @@ public class ViewLongTest extends CQLTester private void updateViewWithFlush(String query, boolean flush, Object... params) throws Throwable { - executeNet(protocolVersion, query, params); + executeNet(version, query, params); while (!(((SEPExecutor) Stage.VIEW_MUTATION.executor()).getPendingTaskCount() == 0 && ((SEPExecutor) Stage.VIEW_MUTATION.executor()).getActiveTaskCount() == 0)) { diff --git a/test/unit/org/apache/cassandra/service/ClientWarningsTest.java b/test/unit/org/apache/cassandra/service/ClientWarningsTest.java index e939df0f23..ee652e2b91 100644 --- a/test/unit/org/apache/cassandra/service/ClientWarningsTest.java +++ b/test/unit/org/apache/cassandra/service/ClientWarningsTest.java @@ -17,12 +17,18 @@ */ package org.apache.cassandra.service; +import java.util.Collection; +import java.util.stream.Collectors; + import org.apache.commons.lang3.StringUtils; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.config.EncryptionOptions; import org.apache.cassandra.cql3.CQLTester; import org.apache.cassandra.cql3.QueryOptions; import org.apache.cassandra.db.ColumnFamilyStore; @@ -35,8 +41,21 @@ import org.apache.cassandra.transport.messages.QueryMessage; import static junit.framework.Assert.assertEquals; import static org.junit.Assert.assertNull; +@RunWith(Parameterized.class) public class ClientWarningsTest extends CQLTester { + @Parameterized.Parameter + public ProtocolVersion version; + + @Parameterized.Parameters() + public static Collection versions() + { + return ProtocolVersion.SUPPORTED.stream() + .skip(1) + .map(v -> new Object[]{v}) + .collect(Collectors.toList()); + } + @BeforeClass public static void setUp() { @@ -45,11 +64,12 @@ public class ClientWarningsTest extends CQLTester } @Test - public void testUnloggedBatchWithProtoV4() throws Exception + public void testUnloggedBatch() throws Exception { createTable("CREATE TABLE %s (pk int PRIMARY KEY, v text)"); - try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, ProtocolVersion.V4)) + // v4 and higher + try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, version, true, new EncryptionOptions())) { client.connect(false); @@ -64,11 +84,12 @@ public class ClientWarningsTest extends CQLTester } @Test - public void testLargeBatchWithProtoV4() throws Exception + public void testLargeBatch() throws Exception { createTable("CREATE TABLE %s (pk int PRIMARY KEY, v text)"); - try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, ProtocolVersion.V4)) + // v4 and higher + try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, version, true, new EncryptionOptions())) { client.connect(false); @@ -88,7 +109,7 @@ public class ClientWarningsTest extends CQLTester final int iterations = 10000; createTable("CREATE TABLE %s (pk int, ck int, v int, PRIMARY KEY (pk, ck))"); - try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, ProtocolVersion.V4)) + try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, version, true, new EncryptionOptions())) { client.connect(false); diff --git a/test/unit/org/apache/cassandra/service/QueryPagerTest.java b/test/unit/org/apache/cassandra/service/QueryPagerTest.java index 87478abeb8..11d1cb0969 100644 --- a/test/unit/org/apache/cassandra/service/QueryPagerTest.java +++ b/test/unit/org/apache/cassandra/service/QueryPagerTest.java @@ -25,6 +25,7 @@ import java.util.*; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.apache.cassandra.*; import org.apache.cassandra.cql3.statements.schema.CreateTableStatement; @@ -231,9 +232,15 @@ public class QueryPagerTest } @Test - public void namesQueryTest() throws Exception + public void namesQueryTest() { - QueryPager pager = namesQuery("k0", "c1", "c5", "c7", "c8").getPager(null, ProtocolVersion.CURRENT); + for(ProtocolVersion protocolVersion : ProtocolVersion.SUPPORTED) + namesQueryTest(protocolVersion); + } + + public void namesQueryTest(ProtocolVersion protocolVersion) + { + QueryPager pager = namesQuery("k0", "c1", "c5", "c7", "c8").getPager(null, protocolVersion); assertFalse(pager.isExhausted()); List partition = query(pager, 5, 4); @@ -243,16 +250,16 @@ public class QueryPagerTest } @Test - public void sliceQueryTest() throws Exception + public void sliceQueryTest() { - sliceQueryTest(false, ProtocolVersion.V3); - sliceQueryTest(true, ProtocolVersion.V3); - - sliceQueryTest(false, ProtocolVersion.V4); - sliceQueryTest(true, ProtocolVersion.V4); + for(ProtocolVersion protocolVersion : ProtocolVersion.SUPPORTED) + { + sliceQueryTest(false, protocolVersion); + sliceQueryTest(true, protocolVersion); + } } - public void sliceQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) throws Exception + public void sliceQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) { ReadCommand command = sliceQuery("k0", "c1", "c8", 10); QueryPager pager = command.getPager(null, protocolVersion); @@ -277,16 +284,16 @@ public class QueryPagerTest } @Test - public void reversedSliceQueryTest() throws Exception + public void reversedSliceQueryTest() { - reversedSliceQueryTest(false, ProtocolVersion.V3); - reversedSliceQueryTest(true, ProtocolVersion.V3); - - reversedSliceQueryTest(false, ProtocolVersion.V4); - reversedSliceQueryTest(true, ProtocolVersion.V4); + for(ProtocolVersion protocolVersion : ProtocolVersion.SUPPORTED) + { + reversedSliceQueryTest(false, protocolVersion); + reversedSliceQueryTest(true, protocolVersion); + } } - public void reversedSliceQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) throws Exception + public void reversedSliceQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) { ReadCommand command = sliceQuery("k0", "c1", "c8", true, 10); QueryPager pager = command.getPager(null, protocolVersion); @@ -311,16 +318,16 @@ public class QueryPagerTest } @Test - public void multiQueryTest() throws Exception + public void multiQueryTest() { - multiQueryTest(false, ProtocolVersion.V3); - multiQueryTest(true, ProtocolVersion.V3); - - multiQueryTest(false, ProtocolVersion.V4); - multiQueryTest(true, ProtocolVersion.V4); + for(ProtocolVersion protocolVersion : ProtocolVersion.SUPPORTED) + { + multiQueryTest(false, protocolVersion); + multiQueryTest(true, protocolVersion); + } } - public void multiQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) throws Exception + public void multiQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) { ReadQuery command = new SinglePartitionReadCommand.Group(new ArrayList() {{ @@ -350,16 +357,16 @@ public class QueryPagerTest } @Test - public void rangeNamesQueryTest() throws Exception + public void rangeNamesQueryTest() { - rangeNamesQueryTest(false, ProtocolVersion.V3); - rangeNamesQueryTest(true, ProtocolVersion.V3); - - rangeNamesQueryTest(false, ProtocolVersion.V4); - rangeNamesQueryTest(true, ProtocolVersion.V4); + for(ProtocolVersion protocolVersion : ProtocolVersion.SUPPORTED) + { + rangeNamesQueryTest(false, protocolVersion); + rangeNamesQueryTest(true, protocolVersion); + } } - public void rangeNamesQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) throws Exception + public void rangeNamesQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) { ReadCommand command = rangeNamesQuery("k0", "k5", 100, "c1", "c4", "c8"); QueryPager pager = command.getPager(null, protocolVersion); @@ -380,16 +387,16 @@ public class QueryPagerTest } @Test - public void rangeSliceQueryTest() throws Exception + public void rangeSliceQueryTest() { - rangeSliceQueryTest(false, ProtocolVersion.V3); - rangeSliceQueryTest(true, ProtocolVersion.V3); - - rangeSliceQueryTest(false, ProtocolVersion.V4); - rangeSliceQueryTest(true, ProtocolVersion.V4); + for(ProtocolVersion protocolVersion : ProtocolVersion.SUPPORTED) + { + rangeSliceQueryTest(false, protocolVersion); + rangeSliceQueryTest(true, protocolVersion); + } } - public void rangeSliceQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) throws Exception + public void rangeSliceQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) { ReadCommand command = rangeSliceQuery("k1", "k5", 100, "c1", "c7"); QueryPager pager = command.getPager(null, protocolVersion); @@ -435,7 +442,13 @@ public class QueryPagerTest } @Test - public void SliceQueryWithTombstoneTest() throws Exception + public void SliceQueryWithTombstoneTest() + { + for(ProtocolVersion version : ProtocolVersion.SUPPORTED) + SliceQueryWithTombstoneTest(version); + } + + public void SliceQueryWithTombstoneTest(ProtocolVersion protocolVersion) { // Testing for the bug of #6748 String keyspace = "cql_keyspace"; @@ -448,7 +461,7 @@ public class QueryPagerTest ReadCommand command = SinglePartitionReadCommand.create(cfs.metadata(), nowInSec, Util.dk("k0"), Slice.ALL); - QueryPager pager = command.getPager(null, ProtocolVersion.CURRENT); + QueryPager pager = command.getPager(null, protocolVersion); for (int i = 0; i < 5; i++) { @@ -459,7 +472,7 @@ public class QueryPagerTest } @Test - public void pagingReversedQueriesWithStaticColumnsTest() throws Exception + public void pagingReversedQueriesWithStaticColumnsTest() { // There was a bug in paging for reverse queries when the schema includes static columns in // 2.1 & 2.2. This was never a problem in 3.0, so this test just guards against regressions @@ -475,7 +488,7 @@ public class QueryPagerTest queryAndVerifyCells(table, true, "k0"); } - private void queryAndVerifyCells(TableMetadata table, boolean reversed, String key) throws Exception + private void queryAndVerifyCells(TableMetadata table, boolean reversed, String key) { ClusteringIndexFilter rowfilter = new ClusteringIndexSliceFilter(Slices.ALL, reversed); ReadCommand command = SinglePartitionReadCommand.create(table, nowInSec, Util.dk(key), ColumnFilter.all(table), rowfilter); diff --git a/test/unit/org/apache/cassandra/service/pager/PagingStateTest.java b/test/unit/org/apache/cassandra/service/pager/PagingStateTest.java index 58e8635225..05160521d4 100644 --- a/test/unit/org/apache/cassandra/service/pager/PagingStateTest.java +++ b/test/unit/org/apache/cassandra/service/pager/PagingStateTest.java @@ -82,6 +82,15 @@ public class PagingStateTest assertEquals(state, PagingState.deserialize(serialized, ProtocolVersion.V4)); } + @Test + public void testSerializeV5DeserializeV5() + { + PagingState state = Util.makeSomePagingState(ProtocolVersion.V5); + ByteBuffer serialized = state.serialize(ProtocolVersion.V5); + assertEquals(serialized.remaining(), state.serializedSize(ProtocolVersion.V5)); + assertEquals(state, PagingState.deserialize(serialized, ProtocolVersion.V5)); + } + @Test public void testSerializeV3DeserializeV4() {