http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/GoodClass.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/GoodClass.java b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/GoodClass.java index 54821b9..7275ef5 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/GoodClass.java +++ b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/GoodClass.java @@ -24,6 +24,7 @@ import java.util.List; import com.datastax.driver.core.TypeCodec; import org.apache.cassandra.cql3.functions.JavaUDF; import org.apache.cassandra.cql3.functions.UDFContext; +import org.apache.cassandra.transport.ProtocolVersion; /** * Used by {@link org.apache.cassandra.cql3.validation.entities.UFVerifierTest}. @@ -35,12 +36,12 @@ public final class GoodClass extends JavaUDF super(returnDataType, argDataTypes, udfContext); } - protected Object executeAggregateImpl(int protocolVersion, Object firstParam, List<ByteBuffer> params) + protected Object executeAggregateImpl(ProtocolVersion protocolVersion, Object firstParam, List<ByteBuffer> params) { throw new UnsupportedOperationException(); } - protected ByteBuffer executeImpl(int protocolVersion, List<ByteBuffer> params) + protected ByteBuffer executeImpl(ProtocolVersion protocolVersion, List<ByteBuffer> params) { return null; }
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronized.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronized.java b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronized.java index dba846d..c036f63 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronized.java +++ b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronized.java @@ -24,6 +24,7 @@ import java.util.List; import com.datastax.driver.core.TypeCodec; import org.apache.cassandra.cql3.functions.JavaUDF; import org.apache.cassandra.cql3.functions.UDFContext; +import org.apache.cassandra.transport.ProtocolVersion; /** * Used by {@link org.apache.cassandra.cql3.validation.entities.UFVerifierTest}. @@ -35,12 +36,12 @@ public final class UseOfSynchronized extends JavaUDF super(returnDataType, argDataTypes, udfContext); } - protected Object executeAggregateImpl(int protocolVersion, Object firstParam, List<ByteBuffer> params) + protected Object executeAggregateImpl(ProtocolVersion protocolVersion, Object firstParam, List<ByteBuffer> params) { throw new UnsupportedOperationException(); } - protected ByteBuffer executeImpl(int protocolVersion, List<ByteBuffer> params) + protected ByteBuffer executeImpl(ProtocolVersion protocolVersion, List<ByteBuffer> params) { synchronized (this) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithNotify.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithNotify.java b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithNotify.java index 63c319c..3eb673a 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithNotify.java +++ b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithNotify.java @@ -24,6 +24,7 @@ import java.util.List; import com.datastax.driver.core.TypeCodec; import org.apache.cassandra.cql3.functions.JavaUDF; import org.apache.cassandra.cql3.functions.UDFContext; +import org.apache.cassandra.transport.ProtocolVersion; /** * Used by {@link org.apache.cassandra.cql3.validation.entities.UFVerifierTest}. @@ -35,12 +36,12 @@ public final class UseOfSynchronizedWithNotify extends JavaUDF super(returnDataType, argDataTypes, udfContext); } - protected Object executeAggregateImpl(int protocolVersion, Object firstParam, List<ByteBuffer> params) + protected Object executeAggregateImpl(ProtocolVersion protocolVersion, Object firstParam, List<ByteBuffer> params) { throw new UnsupportedOperationException(); } - protected ByteBuffer executeImpl(int protocolVersion, List<ByteBuffer> params) + protected ByteBuffer executeImpl(ProtocolVersion protocolVersion, List<ByteBuffer> params) { synchronized (this) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithNotifyAll.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithNotifyAll.java b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithNotifyAll.java index 4d0c2a0..d9841f7 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithNotifyAll.java +++ b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithNotifyAll.java @@ -24,6 +24,7 @@ import java.util.List; import com.datastax.driver.core.TypeCodec; import org.apache.cassandra.cql3.functions.JavaUDF; import org.apache.cassandra.cql3.functions.UDFContext; +import org.apache.cassandra.transport.ProtocolVersion; /** * Used by {@link org.apache.cassandra.cql3.validation.entities.UFVerifierTest}. @@ -35,12 +36,12 @@ public final class UseOfSynchronizedWithNotifyAll extends JavaUDF super(returnDataType, argDataTypes, udfContext); } - protected Object executeAggregateImpl(int protocolVersion, Object firstParam, List<ByteBuffer> params) + protected Object executeAggregateImpl(ProtocolVersion protocolVersion, Object firstParam, List<ByteBuffer> params) { throw new UnsupportedOperationException(); } - protected ByteBuffer executeImpl(int protocolVersion, List<ByteBuffer> params) + protected ByteBuffer executeImpl(ProtocolVersion protocolVersion, List<ByteBuffer> params) { synchronized (this) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWait.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWait.java b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWait.java index b002086..b4e4af3 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWait.java +++ b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWait.java @@ -24,6 +24,7 @@ import java.util.List; import com.datastax.driver.core.TypeCodec; import org.apache.cassandra.cql3.functions.JavaUDF; import org.apache.cassandra.cql3.functions.UDFContext; +import org.apache.cassandra.transport.ProtocolVersion; /** * Used by {@link org.apache.cassandra.cql3.validation.entities.UFVerifierTest}. @@ -35,12 +36,12 @@ public final class UseOfSynchronizedWithWait extends JavaUDF super(returnDataType, argDataTypes, udfContext); } - protected Object executeAggregateImpl(int protocolVersion, Object firstParam, List<ByteBuffer> params) + protected Object executeAggregateImpl(ProtocolVersion protocolVersion, Object firstParam, List<ByteBuffer> params) { throw new UnsupportedOperationException(); } - protected ByteBuffer executeImpl(int protocolVersion, List<ByteBuffer> params) + protected ByteBuffer executeImpl(ProtocolVersion protocolVersion, List<ByteBuffer> params) { synchronized (this) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWaitL.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWaitL.java b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWaitL.java index f128fac..24d4a21 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWaitL.java +++ b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWaitL.java @@ -24,6 +24,7 @@ import java.util.List; import com.datastax.driver.core.TypeCodec; import org.apache.cassandra.cql3.functions.JavaUDF; import org.apache.cassandra.cql3.functions.UDFContext; +import org.apache.cassandra.transport.ProtocolVersion; /** * Used by {@link org.apache.cassandra.cql3.validation.entities.UFVerifierTest}. @@ -35,12 +36,12 @@ public final class UseOfSynchronizedWithWaitL extends JavaUDF super(returnDataType, argDataTypes, udfContext); } - protected Object executeAggregateImpl(int protocolVersion, Object firstParam, List<ByteBuffer> params) + protected Object executeAggregateImpl(ProtocolVersion protocolVersion, Object firstParam, List<ByteBuffer> params) { throw new UnsupportedOperationException(); } - protected ByteBuffer executeImpl(int protocolVersion, List<ByteBuffer> params) + protected ByteBuffer executeImpl(ProtocolVersion protocolVersion, List<ByteBuffer> params) { synchronized (this) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWaitLI.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWaitLI.java b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWaitLI.java index d439518..5f61bf6 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWaitLI.java +++ b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UseOfSynchronizedWithWaitLI.java @@ -24,6 +24,7 @@ import java.util.List; import com.datastax.driver.core.TypeCodec; import org.apache.cassandra.cql3.functions.JavaUDF; import org.apache.cassandra.cql3.functions.UDFContext; +import org.apache.cassandra.transport.ProtocolVersion; /** * Used by {@link org.apache.cassandra.cql3.validation.entities.UFVerifierTest}. @@ -35,12 +36,12 @@ public final class UseOfSynchronizedWithWaitLI extends JavaUDF super(returnDataType, argDataTypes, udfContext); } - protected Object executeAggregateImpl(int protocolVersion, Object firstParam, List<ByteBuffer> params) + protected Object executeAggregateImpl(ProtocolVersion protocolVersion, Object firstParam, List<ByteBuffer> params) { throw new UnsupportedOperationException(); } - protected ByteBuffer executeImpl(int protocolVersion, List<ByteBuffer> params) + protected ByteBuffer executeImpl(ProtocolVersion protocolVersion, List<ByteBuffer> params) { synchronized (this) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UsingMapEntry.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UsingMapEntry.java b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UsingMapEntry.java index b99dbfd..0b95b90 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UsingMapEntry.java +++ b/test/unit/org/apache/cassandra/cql3/validation/entities/udfverify/UsingMapEntry.java @@ -26,6 +26,7 @@ import java.util.Map; import com.datastax.driver.core.TypeCodec; import org.apache.cassandra.cql3.functions.JavaUDF; import org.apache.cassandra.cql3.functions.UDFContext; +import org.apache.cassandra.transport.ProtocolVersion; /** * Used by {@link org.apache.cassandra.cql3.validation.entities.UFVerifierTest}. @@ -37,12 +38,12 @@ public final class UsingMapEntry extends JavaUDF super(returnDataType, argDataTypes, udfContext); } - protected Object executeAggregateImpl(int protocolVersion, Object firstParam, List<ByteBuffer> params) + protected Object executeAggregateImpl(ProtocolVersion protocolVersion, Object firstParam, List<ByteBuffer> params) { throw new UnsupportedOperationException(); } - protected ByteBuffer executeImpl(int protocolVersion, List<ByteBuffer> params) + protected ByteBuffer executeImpl(ProtocolVersion protocolVersion, List<ByteBuffer> params) { Map<String, String> map = new HashMap<>(); // Map.Entry is passed in as an "inner class usage" http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java index 8f03635..c2094f4 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java +++ b/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java @@ -54,7 +54,7 @@ import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.schema.KeyspaceMetadata; import org.apache.cassandra.service.ClientState; import org.apache.cassandra.transport.Event; -import org.apache.cassandra.transport.Server; +import org.apache.cassandra.transport.ProtocolVersion; import org.apache.cassandra.transport.messages.ResultMessage; import static org.junit.Assert.assertEquals; @@ -1889,7 +1889,7 @@ public class AggregationTest extends CQLTester { String type = "DynamicCompositeType(s => UTF8Type, i => Int32Type)"; - executeNet(Server.CURRENT_VERSION, + executeNet(ProtocolVersion.CURRENT, "CREATE FUNCTION " + KEYSPACE + ".f11064(i 'DynamicCompositeType(s => UTF8Type, i => Int32Type)')\n" + "RETURNS NULL ON NULL INPUT\n" + "RETURNS '" + type + "'\n" + @@ -1897,7 +1897,7 @@ public class AggregationTest extends CQLTester "AS 'return i;'"); // create aggregate using the 'composite syntax' for composite types - executeNet(Server.CURRENT_VERSION, + executeNet(ProtocolVersion.CURRENT, "CREATE AGGREGATE " + KEYSPACE + ".a11064()\n" + "SFUNC f11064 " + "STYPE '" + type + "'\n" + @@ -1905,7 +1905,7 @@ public class AggregationTest extends CQLTester AbstractType<?> compositeType = TypeParser.parse(type); ByteBuffer compositeTypeValue = compositeType.fromString("s@foo:i@32"); - String compositeTypeString = compositeType.asCQL3Type().toCQLLiteral(compositeTypeValue, Server.CURRENT_VERSION); + String compositeTypeString = compositeType.asCQL3Type().toCQLLiteral(compositeTypeValue, ProtocolVersion.CURRENT); // ensure that the composite type is serialized using the 'blob syntax' assertTrue(compositeTypeString.startsWith("0x")); @@ -1914,7 +1914,7 @@ public class AggregationTest extends CQLTester row(compositeTypeString)); // create aggregate using the 'blob syntax' for composite types - executeNet(Server.CURRENT_VERSION, + executeNet(ProtocolVersion.CURRENT, "CREATE AGGREGATE " + KEYSPACE + ".a11064_2()\n" + "SFUNC f11064 " + "STYPE '" + type + "'\n" + http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java index c9be678..51ffab2 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java +++ b/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java @@ -25,7 +25,7 @@ import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.exceptions.SyntaxException; import org.apache.cassandra.schema.SchemaKeyspace; -import org.apache.cassandra.transport.Server; +import org.apache.cassandra.transport.ProtocolVersion; import org.apache.cassandra.utils.ByteBufferUtil; import org.junit.Assert; @@ -484,9 +484,9 @@ public class AlterTest extends CQLTester execute("INSERT INTO %s (a, b) VALUES (1, 1)"); - executeNet(Server.CURRENT_VERSION, "ALTER TABLE %s ALTER b TYPE BLOB"); + executeNet(ProtocolVersion.CURRENT, "ALTER TABLE %s ALTER b TYPE BLOB"); - assertRowsNet(Server.CURRENT_VERSION, executeNet(Server.CURRENT_VERSION, "SELECT * FROM %s WHERE a = 1"), + assertRowsNet(ProtocolVersion.CURRENT, executeNet(ProtocolVersion.CURRENT, "SELECT * FROM %s WHERE a = 1"), row(1, ByteBufferUtil.bytes(1)) ); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/index/CustomIndexTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/index/CustomIndexTest.java b/test/unit/org/apache/cassandra/index/CustomIndexTest.java index 882de2d..8e1385e 100644 --- a/test/unit/org/apache/cassandra/index/CustomIndexTest.java +++ b/test/unit/org/apache/cassandra/index/CustomIndexTest.java @@ -49,7 +49,7 @@ import org.apache.cassandra.db.partitions.UnfilteredPartitionIterator; import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.schema.IndexMetadata; import org.apache.cassandra.schema.Indexes; -import org.apache.cassandra.transport.Server; +import org.apache.cassandra.transport.ProtocolVersion; import org.apache.cassandra.utils.FBUtilities; import static org.apache.cassandra.Util.throwAssert; @@ -357,7 +357,7 @@ public class CustomIndexTest extends CQLTester createIndex(String.format("CREATE CUSTOM INDEX %s ON %%s(c) USING '%s'", indexName, StubIndex.class.getName())); - assertInvalidThrowMessage(Server.CURRENT_VERSION, + assertInvalidThrowMessage(Optional.of(ProtocolVersion.CURRENT), String.format(IndexRestrictions.INDEX_NOT_FOUND, "no_such_index", keyspace(), currentTable()), QueryValidationException.class, "SELECT * FROM %s WHERE expr(no_such_index, 'foo bar baz ')"); @@ -368,7 +368,7 @@ public class CustomIndexTest extends CQLTester assertRows(execute(String.format("SELECT * FROM %%s WHERE expr(%s, $$foo \" ~~~ bar Baz$$)", indexName)), row); // multiple expressions on the same index - assertInvalidThrowMessage(Server.CURRENT_VERSION, + assertInvalidThrowMessage(Optional.of(ProtocolVersion.CURRENT), IndexRestrictions.MULTIPLE_EXPRESSIONS, QueryValidationException.class, String.format("SELECT * FROM %%s WHERE expr(%1$s, 'foo') AND expr(%1$s, 'bar')", @@ -376,13 +376,13 @@ public class CustomIndexTest extends CQLTester // multiple expressions on different indexes createIndex(String.format("CREATE CUSTOM INDEX other_custom_index ON %%s(d) USING '%s'", StubIndex.class.getName())); - assertInvalidThrowMessage(Server.CURRENT_VERSION, + assertInvalidThrowMessage(Optional.of(ProtocolVersion.CURRENT), IndexRestrictions.MULTIPLE_EXPRESSIONS, QueryValidationException.class, String.format("SELECT * FROM %%s WHERE expr(%s, 'foo') AND expr(other_custom_index, 'bar')", indexName)); - assertInvalidThrowMessage(Server.CURRENT_VERSION, + assertInvalidThrowMessage(Optional.of(ProtocolVersion.CURRENT), StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE, QueryValidationException.class, String.format("SELECT * FROM %%s WHERE expr(%s, 'foo') AND d=0", indexName)); @@ -397,7 +397,7 @@ public class CustomIndexTest extends CQLTester createIndex(String.format("CREATE CUSTOM INDEX %s ON %%s(c) USING '%s'", indexName, NoCustomExpressionsIndex.class.getName())); - assertInvalidThrowMessage(Server.CURRENT_VERSION, + assertInvalidThrowMessage(Optional.of(ProtocolVersion.CURRENT), String.format( IndexRestrictions.CUSTOM_EXPRESSION_NOT_SUPPORTED, indexName), QueryValidationException.class, String.format("SELECT * FROM %%s WHERE expr(%s, 'foo bar baz')", indexName)); @@ -411,7 +411,7 @@ public class CustomIndexTest extends CQLTester createIndex(String.format("CREATE CUSTOM INDEX %s ON %%s(c) USING '%s'", indexName, AlwaysRejectIndex.class.getName())); - assertInvalidThrowMessage(Server.CURRENT_VERSION, + assertInvalidThrowMessage(Optional.of(ProtocolVersion.CURRENT), "None shall pass", QueryValidationException.class, String.format("SELECT * FROM %%s WHERE expr(%s, 'foo bar baz')", indexName)); @@ -422,7 +422,7 @@ public class CustomIndexTest extends CQLTester { createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b))"); createIndex("CREATE INDEX non_custom_index ON %s(c)"); - assertInvalidThrowMessage(Server.CURRENT_VERSION, + assertInvalidThrowMessage(Optional.of(ProtocolVersion.CURRENT), String.format(IndexRestrictions.NON_CUSTOM_INDEX_IN_EXPRESSION, "non_custom_index"), QueryValidationException.class, "SELECT * FROM %s WHERE expr(non_custom_index, 'c=0')"); @@ -436,11 +436,11 @@ public class CustomIndexTest extends CQLTester createIndex(String.format("CREATE CUSTOM INDEX %s ON %%s(c) USING '%s'", indexName, StubIndex.class.getName())); - assertInvalidThrowMessage(Server.CURRENT_VERSION, + assertInvalidThrowMessage(Optional.of(ProtocolVersion.CURRENT), ModificationStatement.CUSTOM_EXPRESSIONS_NOT_ALLOWED, QueryValidationException.class, String.format("DELETE FROM %%s WHERE expr(%s, 'foo bar baz ')", indexName)); - assertInvalidThrowMessage(Server.CURRENT_VERSION, + assertInvalidThrowMessage(Optional.of(ProtocolVersion.CURRENT), ModificationStatement.CUSTOM_EXPRESSIONS_NOT_ALLOWED, QueryValidationException.class, String.format("UPDATE %%s SET d=0 WHERE expr(%s, 'foo bar baz ')", indexName)); @@ -518,13 +518,13 @@ public class CustomIndexTest extends CQLTester UTF8ExpressionIndex.class.getName())); execute("SELECT * FROM %s WHERE expr(text_index, 'foo')"); - assertInvalidThrowMessage(Server.CURRENT_VERSION, + assertInvalidThrowMessage(Optional.of(ProtocolVersion.CURRENT), "Invalid INTEGER constant (99) for \"custom index expression\" of type text", QueryValidationException.class, "SELECT * FROM %s WHERE expr(text_index, 99)"); execute("SELECT * FROM %s WHERE expr(int_index, 99)"); - assertInvalidThrowMessage(Server.CURRENT_VERSION, + assertInvalidThrowMessage(Optional.of(ProtocolVersion.CURRENT), "Invalid STRING constant (foo) for \"custom index expression\" of type int", QueryValidationException.class, "SELECT * FROM %s WHERE expr(int_index, 'foo')"); http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/service/ClientWarningsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/service/ClientWarningsTest.java b/test/unit/org/apache/cassandra/service/ClientWarningsTest.java index 78b1c88..e939df0 100644 --- a/test/unit/org/apache/cassandra/service/ClientWarningsTest.java +++ b/test/unit/org/apache/cassandra/service/ClientWarningsTest.java @@ -28,7 +28,7 @@ import org.apache.cassandra.cql3.QueryOptions; import org.apache.cassandra.db.ColumnFamilyStore; import org.apache.cassandra.db.Keyspace; import org.apache.cassandra.transport.Message; -import org.apache.cassandra.transport.Server; +import org.apache.cassandra.transport.ProtocolVersion; import org.apache.cassandra.transport.SimpleClient; import org.apache.cassandra.transport.messages.QueryMessage; @@ -49,7 +49,7 @@ public class ClientWarningsTest extends CQLTester { createTable("CREATE TABLE %s (pk int PRIMARY KEY, v text)"); - try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, Server.VERSION_4)) + try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, ProtocolVersion.V4)) { client.connect(false); @@ -68,7 +68,7 @@ public class ClientWarningsTest extends CQLTester { createTable("CREATE TABLE %s (pk int PRIMARY KEY, v text)"); - try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, Server.VERSION_4)) + try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, ProtocolVersion.V4)) { client.connect(false); @@ -88,7 +88,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, Server.VERSION_4)) + try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, ProtocolVersion.V4)) { client.connect(false); @@ -128,7 +128,7 @@ public class ClientWarningsTest extends CQLTester { createTable("CREATE TABLE %s (pk int PRIMARY KEY, v text)"); - try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, Server.VERSION_3)) + try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, ProtocolVersion.V3)) { client.connect(false); http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/service/ProtocolBetaVersionTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/service/ProtocolBetaVersionTest.java b/test/unit/org/apache/cassandra/service/ProtocolBetaVersionTest.java index 238c2f9..0c51eb7 100644 --- a/test/unit/org/apache/cassandra/service/ProtocolBetaVersionTest.java +++ b/test/unit/org/apache/cassandra/service/ProtocolBetaVersionTest.java @@ -26,6 +26,7 @@ import org.apache.cassandra.transport.*; import org.apache.cassandra.transport.messages.*; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.fail; public class ProtocolBetaVersionTest extends CQLTester @@ -37,12 +38,37 @@ public class ProtocolBetaVersionTest extends CQLTester DatabaseDescriptor.setBatchSizeWarnThresholdInKB(1); } + private ProtocolVersion getBetaVersion() + { + ProtocolVersion betaVersion = ProtocolVersion.BETA.orElse(null); + if (betaVersion == null) + { + for (ProtocolVersion version : ProtocolVersion.SUPPORTED) + { + if (version.isBeta()) + { + betaVersion = version; + break; + } + } + } + return betaVersion; + } + @Test public void testProtocolBetaVersion() throws Exception { + ProtocolVersion betaVersion = getBetaVersion(); + if (betaVersion == null) + { + logger.info("No beta version found for testing"); + return; + } + createTable("CREATE TABLE %s (pk int PRIMARY KEY, v int)"); + assertTrue(betaVersion.isBeta()); // change to another beta version or remove test if no beta version - try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, Server.BETA_VERSION, true, new EncryptionOptions.ClientEncryptionOptions())) + try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, betaVersion, true, new EncryptionOptions.ClientEncryptionOptions())) { client.connect(false); for (int i = 0; i < 10; i++) @@ -69,14 +95,22 @@ public class ProtocolBetaVersionTest extends CQLTester @Test public void unforcedProtocolVersionTest() throws Exception { - try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, Server.BETA_VERSION, false, new EncryptionOptions.ClientEncryptionOptions())) + ProtocolVersion betaVersion = getBetaVersion(); + if (betaVersion == null) + { + logger.info("No beta version found for testing"); + return; + } + + assertTrue(betaVersion.isBeta()); // change to another beta version or remove test if no beta version + try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, betaVersion, false, new EncryptionOptions.ClientEncryptionOptions())) { client.connect(false); fail("Exception should have been thrown"); } catch (Exception e) { - assertEquals("Beta version of server used (5), but USE_BETA flag is not set", + assertEquals("Beta version of server used (5/v5-beta), but USE_BETA flag is not set", e.getMessage()); } } http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/service/QueryPagerTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/service/QueryPagerTest.java b/test/unit/org/apache/cassandra/service/QueryPagerTest.java index 2f2a236..2104d14 100644 --- a/test/unit/org/apache/cassandra/service/QueryPagerTest.java +++ b/test/unit/org/apache/cassandra/service/QueryPagerTest.java @@ -38,9 +38,9 @@ import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.schema.KeyspaceParams; import org.apache.cassandra.service.pager.QueryPager; import org.apache.cassandra.service.pager.PagingState; +import org.apache.cassandra.transport.ProtocolVersion; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; -import org.apache.cassandra.transport.Server; import static org.apache.cassandra.cql3.QueryProcessor.executeInternal; import static org.apache.cassandra.utils.ByteBufferUtil.bytes; @@ -207,7 +207,7 @@ public class QueryPagerTest } } - private QueryPager maybeRecreate(QueryPager pager, ReadQuery command, boolean testPagingState, int protocolVersion) + private QueryPager maybeRecreate(QueryPager pager, ReadQuery command, boolean testPagingState, ProtocolVersion protocolVersion) { if (!testPagingState) return pager; @@ -219,7 +219,7 @@ public class QueryPagerTest @Test public void namesQueryTest() throws Exception { - QueryPager pager = namesQuery("k0", "c1", "c5", "c7", "c8").getPager(null, Server.CURRENT_VERSION); + QueryPager pager = namesQuery("k0", "c1", "c5", "c7", "c8").getPager(null, ProtocolVersion.CURRENT); assertFalse(pager.isExhausted()); List<FilteredPartition> partition = query(pager, 5, 4); @@ -231,13 +231,13 @@ public class QueryPagerTest @Test public void sliceQueryTest() throws Exception { - sliceQueryTest(false, Server.VERSION_3); - sliceQueryTest(true, Server.VERSION_4); - sliceQueryTest(false, Server.VERSION_3); - sliceQueryTest(true, Server.VERSION_4); + sliceQueryTest(false, ProtocolVersion.V3); + sliceQueryTest(true, ProtocolVersion.V4); + sliceQueryTest(false, ProtocolVersion.V3); + sliceQueryTest(true, ProtocolVersion.V4); } - public void sliceQueryTest(boolean testPagingState, int protocolVersion) throws Exception + public void sliceQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) throws Exception { ReadCommand command = sliceQuery("k0", "c1", "c8", 10); QueryPager pager = command.getPager(null, protocolVersion); @@ -264,13 +264,13 @@ public class QueryPagerTest @Test public void reversedSliceQueryTest() throws Exception { - reversedSliceQueryTest(false, Server.VERSION_3); - reversedSliceQueryTest(true, Server.VERSION_4); - reversedSliceQueryTest(false, Server.VERSION_3); - reversedSliceQueryTest(true, Server.VERSION_4); + reversedSliceQueryTest(false, ProtocolVersion.V3); + reversedSliceQueryTest(true, ProtocolVersion.V4); + reversedSliceQueryTest(false, ProtocolVersion.V3); + reversedSliceQueryTest(true, ProtocolVersion.V4); } - public void reversedSliceQueryTest(boolean testPagingState, int protocolVersion) throws Exception + public void reversedSliceQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) throws Exception { ReadCommand command = sliceQuery("k0", "c1", "c8", true, 10); QueryPager pager = command.getPager(null, protocolVersion); @@ -297,13 +297,13 @@ public class QueryPagerTest @Test public void multiQueryTest() throws Exception { - multiQueryTest(false, Server.VERSION_3); - multiQueryTest(true, Server.VERSION_4); - multiQueryTest(false, Server.VERSION_3); - multiQueryTest(true, Server.VERSION_4); + multiQueryTest(false, ProtocolVersion.V3); + multiQueryTest(true, ProtocolVersion.V4); + multiQueryTest(false, ProtocolVersion.V3); + multiQueryTest(true, ProtocolVersion.V4); } - public void multiQueryTest(boolean testPagingState, int protocolVersion) throws Exception + public void multiQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) throws Exception { ReadQuery command = new SinglePartitionReadCommand.Group(new ArrayList<SinglePartitionReadCommand>() {{ @@ -335,13 +335,13 @@ public class QueryPagerTest @Test public void rangeNamesQueryTest() throws Exception { - rangeNamesQueryTest(false, Server.VERSION_3); - rangeNamesQueryTest(true, Server.VERSION_4); - rangeNamesQueryTest(false, Server.VERSION_3); - rangeNamesQueryTest(true, Server.VERSION_4); + rangeNamesQueryTest(false, ProtocolVersion.V3); + rangeNamesQueryTest(true, ProtocolVersion.V4); + rangeNamesQueryTest(false, ProtocolVersion.V3); + rangeNamesQueryTest(true, ProtocolVersion.V4); } - public void rangeNamesQueryTest(boolean testPagingState, int protocolVersion) throws Exception + public void rangeNamesQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) throws Exception { ReadCommand command = rangeNamesQuery("k0", "k5", 100, "c1", "c4", "c8"); QueryPager pager = command.getPager(null, protocolVersion); @@ -364,13 +364,13 @@ public class QueryPagerTest @Test public void rangeSliceQueryTest() throws Exception { - rangeSliceQueryTest(false, Server.VERSION_3); - rangeSliceQueryTest(true, Server.VERSION_4); - rangeSliceQueryTest(false, Server.VERSION_3); - rangeSliceQueryTest(true, Server.VERSION_4); + rangeSliceQueryTest(false, ProtocolVersion.V3); + rangeSliceQueryTest(true, ProtocolVersion.V4); + rangeSliceQueryTest(false, ProtocolVersion.V3); + rangeSliceQueryTest(true, ProtocolVersion.V4); } - public void rangeSliceQueryTest(boolean testPagingState, int protocolVersion) throws Exception + public void rangeSliceQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) throws Exception { ReadCommand command = rangeSliceQuery("k1", "k5", 100, "c1", "c7"); QueryPager pager = command.getPager(null, protocolVersion); @@ -429,7 +429,7 @@ public class QueryPagerTest ReadCommand command = SinglePartitionReadCommand.create(cfs.metadata, nowInSec, Util.dk("k0"), Slice.ALL); - QueryPager pager = command.getPager(null, Server.CURRENT_VERSION); + QueryPager pager = command.getPager(null, ProtocolVersion.CURRENT); for (int i = 0; i < 5; i++) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/service/pager/PagingStateTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/service/pager/PagingStateTest.java b/test/unit/org/apache/cassandra/service/pager/PagingStateTest.java index 0ae6d9a..778088d 100644 --- a/test/unit/org/apache/cassandra/service/pager/PagingStateTest.java +++ b/test/unit/org/apache/cassandra/service/pager/PagingStateTest.java @@ -24,14 +24,9 @@ import java.nio.ByteBuffer; import org.junit.BeforeClass; import org.junit.Test; -import org.apache.cassandra.config.CFMetaData; -import org.apache.cassandra.config.ColumnDefinition; +import org.apache.cassandra.Util; import org.apache.cassandra.config.DatabaseDescriptor; -import org.apache.cassandra.cql3.ColumnIdentifier; -import org.apache.cassandra.db.*; -import org.apache.cassandra.db.rows.*; -import org.apache.cassandra.db.marshal.*; -import org.apache.cassandra.transport.Server; +import org.apache.cassandra.transport.ProtocolVersion; import org.apache.cassandra.utils.ByteBufferUtil; import static org.junit.Assert.assertEquals; @@ -45,24 +40,6 @@ public class PagingStateTest DatabaseDescriptor.daemonInitialization(); } - private PagingState makeSomePagingState(int protocolVersion) - { - CFMetaData metadata = CFMetaData.Builder.create("ks", "tbl") - .addPartitionKey("k", AsciiType.instance) - .addClusteringColumn("c1", AsciiType.instance) - .addClusteringColumn("c1", Int32Type.instance) - .addRegularColumn("myCol", AsciiType.instance) - .build(); - - ByteBuffer pk = ByteBufferUtil.bytes("someKey"); - - ColumnDefinition def = metadata.getColumnDefinition(new ColumnIdentifier("myCol", false)); - Clustering c = Clustering.make(ByteBufferUtil.bytes("c1"), ByteBufferUtil.bytes(42)); - Row row = BTreeRow.singleCellRow(c, BufferCell.live(def, 0, ByteBufferUtil.EMPTY_BYTE_BUFFER)); - PagingState.RowMark mark = PagingState.RowMark.create(metadata, row, protocolVersion); - return new PagingState(pk, mark, 10, 0); - } - @Test public void testSerializationBackwardCompatibility() { @@ -78,9 +55,9 @@ public class PagingStateTest * PagingState state = new PagingState(pk, cn.toByteBuffer(), 10); * System.out.println("PagingState = " + ByteBufferUtil.bytesToHex(state.serialize())); */ - PagingState state = makeSomePagingState(Server.VERSION_3); + PagingState state = Util.makeSomePagingState(ProtocolVersion.V3); - String serializedState = ByteBufferUtil.bytesToHex(state.serialize(Server.VERSION_3)); + String serializedState = ByteBufferUtil.bytesToHex(state.serialize(ProtocolVersion.V3)); // Note that we don't assert exact equality because we know 3.0 nodes include the "remainingInPartition" number // that is not present on 2.1/2.2 nodes. We know this is ok however because we know that 2.1/2.2 nodes will ignore // anything remaining once they have properly deserialized a paging state. @@ -90,18 +67,18 @@ public class PagingStateTest @Test public void testSerializeDeserializeV3() { - PagingState state = makeSomePagingState(Server.VERSION_3); - ByteBuffer serialized = state.serialize(Server.VERSION_3); - assertEquals(serialized.remaining(), state.serializedSize(Server.VERSION_3)); - assertEquals(state, PagingState.deserialize(serialized, Server.VERSION_3)); + PagingState state = Util.makeSomePagingState(ProtocolVersion.V3); + ByteBuffer serialized = state.serialize(ProtocolVersion.V3); + assertEquals(serialized.remaining(), state.serializedSize(ProtocolVersion.V3)); + assertEquals(state, PagingState.deserialize(serialized, ProtocolVersion.V3)); } @Test public void testSerializeDeserializeV4() { - PagingState state = makeSomePagingState(Server.VERSION_4); - ByteBuffer serialized = state.serialize(Server.VERSION_4); - assertEquals(serialized.remaining(), state.serializedSize(Server.VERSION_4)); - assertEquals(state, PagingState.deserialize(serialized, Server.VERSION_4)); + PagingState state = Util.makeSomePagingState(ProtocolVersion.V4); + ByteBuffer serialized = state.serialize(ProtocolVersion.V4); + assertEquals(serialized.remaining(), state.serializedSize(ProtocolVersion.V4)); + assertEquals(state, PagingState.deserialize(serialized, ProtocolVersion.V4)); } } http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/transport/DataTypeTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/transport/DataTypeTest.java b/test/unit/org/apache/cassandra/transport/DataTypeTest.java index dc2c4e2..c25730c 100644 --- a/test/unit/org/apache/cassandra/transport/DataTypeTest.java +++ b/test/unit/org/apache/cassandra/transport/DataTypeTest.java @@ -44,7 +44,7 @@ public class DataTypeTest continue; Map<DataType, Object> options = Collections.singletonMap(type, (Object)type.toString()); - for (int version = 1; version < 5; version++) + for (ProtocolVersion version : ProtocolVersion.SUPPORTED) testEncodeDecode(type, options, version); } } @@ -54,7 +54,7 @@ public class DataTypeTest { DataType type = DataType.LIST; Map<DataType, Object> options = Collections.singletonMap(type, (Object)LongType.instance); - for (int version = 1; version < 5; version++) + for (ProtocolVersion version : ProtocolVersion.SUPPORTED) testEncodeDecode(type, options, version); } @@ -66,11 +66,11 @@ public class DataTypeTest value.add(LongType.instance); value.add(AsciiType.instance); Map<DataType, Object> options = Collections.singletonMap(type, (Object)value); - for (int version = 1; version < 5; version++) + for (ProtocolVersion version : ProtocolVersion.SUPPORTED) testEncodeDecode(type, options, version); } - private void testEncodeDecode(DataType type, Map<DataType, Object> options, int version) + private void testEncodeDecode(DataType type, Map<DataType, Object> options, ProtocolVersion version) { ByteBuf dest = type.codec.encode(options, version); Map<DataType, Object> results = type.codec.decode(dest, version); @@ -78,7 +78,7 @@ public class DataTypeTest for (DataType key : results.keySet()) { int ssize = type.serializedValueSize(results.get(key), version); - int esize = version < type.getProtocolVersion() ? 2 + TypeSizes.encodedUTF8Length(results.get(key).toString()) : 0; + int esize = version.isSmallerThan(type.getProtocolVersion()) ? 2 + TypeSizes.encodedUTF8Length(results.get(key).toString()) : 0; switch (type) { case LIST: @@ -94,7 +94,7 @@ public class DataTypeTest } assertEquals(esize, ssize); - DataType expected = version < type.getProtocolVersion() + DataType expected = version.isSmallerThan(type.getProtocolVersion()) ? DataType.CUSTOM : type; assertEquals(expected, key); @@ -103,6 +103,6 @@ public class DataTypeTest private boolean isComplexType(DataType type) { - return type.getId(Server.CURRENT_VERSION) >= 32; + return type.getId(ProtocolVersion.CURRENT) >= 32; } } http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/transport/ErrorMessageTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/transport/ErrorMessageTest.java b/test/unit/org/apache/cassandra/transport/ErrorMessageTest.java index a145d18..2dcd2ac 100644 --- a/test/unit/org/apache/cassandra/transport/ErrorMessageTest.java +++ b/test/unit/org/apache/cassandra/transport/ErrorMessageTest.java @@ -63,7 +63,7 @@ public class ErrorMessageTest boolean dataPresent = false; ReadFailureException rfe = new ReadFailureException(consistencyLevel, receivedBlockFor, receivedBlockFor, dataPresent, failureReasonMap1); - ErrorMessage deserialized = serializeAndGetDeserializedErrorMessage(ErrorMessage.fromException(rfe), 5); + ErrorMessage deserialized = serializeAndGetDeserializedErrorMessage(ErrorMessage.fromException(rfe), ProtocolVersion.V5); ReadFailureException deserializedRfe = (ReadFailureException) deserialized.error; assertEquals(failureReasonMap1, deserializedRfe.failureReasonByEndpoint); @@ -81,7 +81,7 @@ public class ErrorMessageTest WriteType writeType = WriteType.SIMPLE; WriteFailureException wfe = new WriteFailureException(consistencyLevel, receivedBlockFor, receivedBlockFor, writeType, failureReasonMap2); - ErrorMessage deserialized = serializeAndGetDeserializedErrorMessage(ErrorMessage.fromException(wfe), 5); + ErrorMessage deserialized = serializeAndGetDeserializedErrorMessage(ErrorMessage.fromException(wfe), ProtocolVersion.V5); WriteFailureException deserializedWfe = (WriteFailureException) deserialized.error; assertEquals(failureReasonMap2, deserializedWfe.failureReasonByEndpoint); @@ -112,7 +112,7 @@ public class ErrorMessageTest assertEquals(failureReasonMap1, wfe.failureReasonByEndpoint); } - private ErrorMessage serializeAndGetDeserializedErrorMessage(ErrorMessage message, int version) + private ErrorMessage serializeAndGetDeserializedErrorMessage(ErrorMessage message, ProtocolVersion version) { ByteBuf buffer = Unpooled.buffer(ErrorMessage.codec.encodedSize(message, version)); ErrorMessage.codec.encode(message, buffer, version); http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/transport/MessagePayloadTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/transport/MessagePayloadTest.java b/test/unit/org/apache/cassandra/transport/MessagePayloadTest.java index f8a77e1..2bd1883 100644 --- a/test/unit/org/apache/cassandra/transport/MessagePayloadTest.java +++ b/test/unit/org/apache/cassandra/transport/MessagePayloadTest.java @@ -191,7 +191,7 @@ public class MessagePayloadTest extends CQLTester Assert.assertSame(TestQueryHandler.class, ClientState.getCQLQueryHandler().getClass()); - SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, Server.VERSION_3); + SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, ProtocolVersion.V3); try { client.connect(false); http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java b/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java index 44c434d..5e9731a 100644 --- a/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java +++ b/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java @@ -43,9 +43,10 @@ public class ProtocolErrorTest { public void testInvalidProtocolVersion() throws Exception { // test using a protocol 2 version higher than the current version (1 version higher is current beta) - testInvalidProtocolVersion(Server.CURRENT_VERSION + 2); // + testInvalidProtocolVersion(ProtocolVersion.CURRENT.asInt() + 2); // // test using a protocol version lower than the lowest version - testInvalidProtocolVersion(Server.MIN_SUPPORTED_VERSION - 1); + for (ProtocolVersion version : ProtocolVersion.UNSUPPORTED) + testInvalidProtocolVersion(version.asInt()); } @@ -107,7 +108,7 @@ public class ProtocolErrorTest { // should generate a protocol exception for using a response frame with // a prepare op, ensure that it comes back with stream ID 1 byte[] frame = new byte[] { - (byte) RESPONSE.addToVersion(Server.CURRENT_VERSION), // direction & version + (byte) RESPONSE.addToVersion(ProtocolVersion.CURRENT.asInt()), // direction & version 0x00, // flags 0x00, 0x01, // stream ID 0x09, // opcode @@ -136,7 +137,7 @@ public class ProtocolErrorTest { List<Object> results = new ArrayList<>(); byte[] frame = new byte[] { - (byte) REQUEST.addToVersion(Server.CURRENT_VERSION), // direction & version + (byte) REQUEST.addToVersion(ProtocolVersion.CURRENT.asInt()), // direction & version 0x00, // flags 0x00, 0x01, // stream ID 0x09, // opcode @@ -160,9 +161,9 @@ public class ProtocolErrorTest { // test for CASSANDRA-11167 ErrorMessage msg = ErrorMessage.fromException(new ServerError((String) null)); assert msg.toString().endsWith("null") : msg.toString(); - int size = ErrorMessage.codec.encodedSize(msg, Server.CURRENT_VERSION); + int size = ErrorMessage.codec.encodedSize(msg, ProtocolVersion.CURRENT); ByteBuf buf = Unpooled.buffer(size); - ErrorMessage.codec.encode(msg, buf, Server.CURRENT_VERSION); + ErrorMessage.codec.encode(msg, buf, ProtocolVersion.CURRENT); ByteBuf expected = Unpooled.wrappedBuffer(new byte[]{ 0x00, 0x00, 0x00, 0x00, // int error code http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/transport/ProtocolVersionTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/transport/ProtocolVersionTest.java b/test/unit/org/apache/cassandra/transport/ProtocolVersionTest.java new file mode 100644 index 0000000..e287c08 --- /dev/null +++ b/test/unit/org/apache/cassandra/transport/ProtocolVersionTest.java @@ -0,0 +1,97 @@ +/* + * 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.transport; + +import org.junit.Assert; +import org.junit.Test; + +public class ProtocolVersionTest +{ + @Test + public void testDecode() + { + for (ProtocolVersion version : ProtocolVersion.SUPPORTED) + Assert.assertEquals(version, ProtocolVersion.decode(version.asInt())); + + for (ProtocolVersion version : ProtocolVersion.UNSUPPORTED) + { // unsupported old versions + try + { + Assert.assertEquals(version, ProtocolVersion.decode(version.asInt())); + Assert.fail("Expected invalid protocol exception"); + } + catch (ProtocolException ex) + { + Assert.assertNotNull(ex.getForcedProtocolVersion()); + Assert.assertEquals(version, ex.getForcedProtocolVersion()); + } + } + + try + { // unsupported newer version + Assert.assertEquals(null, ProtocolVersion.decode(63)); + Assert.fail("Expected invalid protocol exception"); + } + catch (ProtocolException ex) + { + Assert.assertNotNull(ex.getForcedProtocolVersion()); + Assert.assertEquals(ProtocolVersion.MAX_SUPPORTED_VERSION, ex.getForcedProtocolVersion()); + } + } + + @Test + public void testSupportedVersions() + { + Assert.assertTrue(ProtocolVersion.supportedVersions().size() >= 2); // at least one OS and one DSE + Assert.assertNotNull(ProtocolVersion.CURRENT); + + Assert.assertFalse(ProtocolVersion.V4.isBeta()); + Assert.assertTrue(ProtocolVersion.V5.isBeta()); + } + + @Test + public void testComparisons() + { + Assert.assertTrue(ProtocolVersion.V1.isSmallerOrEqualTo(ProtocolVersion.V1)); + Assert.assertTrue(ProtocolVersion.V2.isSmallerOrEqualTo(ProtocolVersion.V2)); + Assert.assertTrue(ProtocolVersion.V3.isSmallerOrEqualTo(ProtocolVersion.V3)); + Assert.assertTrue(ProtocolVersion.V4.isSmallerOrEqualTo(ProtocolVersion.V4)); + + Assert.assertTrue(ProtocolVersion.V1.isGreaterOrEqualTo(ProtocolVersion.V1)); + Assert.assertTrue(ProtocolVersion.V2.isGreaterOrEqualTo(ProtocolVersion.V2)); + Assert.assertTrue(ProtocolVersion.V3.isGreaterOrEqualTo(ProtocolVersion.V3)); + Assert.assertTrue(ProtocolVersion.V4.isGreaterOrEqualTo(ProtocolVersion.V4)); + + Assert.assertTrue(ProtocolVersion.V1.isSmallerThan(ProtocolVersion.V2)); + Assert.assertTrue(ProtocolVersion.V2.isSmallerThan(ProtocolVersion.V3)); + Assert.assertTrue(ProtocolVersion.V3.isSmallerThan(ProtocolVersion.V4)); + + Assert.assertFalse(ProtocolVersion.V1.isGreaterThan(ProtocolVersion.V2)); + Assert.assertFalse(ProtocolVersion.V2.isGreaterThan(ProtocolVersion.V3)); + Assert.assertFalse(ProtocolVersion.V3.isGreaterThan(ProtocolVersion.V4)); + + Assert.assertTrue(ProtocolVersion.V4.isGreaterThan(ProtocolVersion.V3)); + Assert.assertTrue(ProtocolVersion.V3.isGreaterThan(ProtocolVersion.V2)); + Assert.assertTrue(ProtocolVersion.V2.isGreaterThan(ProtocolVersion.V1)); + + Assert.assertFalse(ProtocolVersion.V4.isSmallerThan(ProtocolVersion.V3)); + Assert.assertFalse(ProtocolVersion.V3.isSmallerThan(ProtocolVersion.V2)); + Assert.assertFalse(ProtocolVersion.V2.isSmallerThan(ProtocolVersion.V1)); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/transport/SerDeserTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/transport/SerDeserTest.java b/test/unit/org/apache/cassandra/transport/SerDeserTest.java index 44d72a1..1eaa5ac 100644 --- a/test/unit/org/apache/cassandra/transport/SerDeserTest.java +++ b/test/unit/org/apache/cassandra/transport/SerDeserTest.java @@ -23,10 +23,16 @@ import java.util.*; import io.netty.buffer.Unpooled; import io.netty.buffer.ByteBuf; +import org.junit.BeforeClass; import org.junit.Test; + +import org.apache.cassandra.Util; +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.cql3.*; +import org.apache.cassandra.db.ConsistencyLevel; import org.apache.cassandra.db.marshal.*; import org.apache.cassandra.serializers.CollectionSerializer; +import org.apache.cassandra.service.pager.PagingState; import org.apache.cassandra.transport.Event.TopologyChange; import org.apache.cassandra.transport.Event.SchemaChange; import org.apache.cassandra.transport.Event.StatusChange; @@ -35,6 +41,7 @@ import org.apache.cassandra.utils.Pair; import static org.junit.Assert.assertEquals; import static org.apache.cassandra.utils.ByteBufferUtil.bytes; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; /** @@ -42,14 +49,21 @@ import static org.junit.Assert.assertNotSame; */ public class SerDeserTest { + @BeforeClass + public static void setupDD() + { + // required for making the paging state + DatabaseDescriptor.daemonInitialization(); + } + @Test public void collectionSerDeserTest() throws Exception { - collectionSerDeserTest(3); - collectionSerDeserTest(4); + for (ProtocolVersion version : ProtocolVersion.SUPPORTED) + collectionSerDeserTest(version); } - public void collectionSerDeserTest(int version) throws Exception + public void collectionSerDeserTest(ProtocolVersion version) throws Exception { // Lists ListType<?> lt = ListType.getInstance(Int32Type.instance, true); @@ -92,11 +106,11 @@ public class SerDeserTest @Test public void eventSerDeserTest() throws Exception { - eventSerDeserTest(3); - eventSerDeserTest(4); + for (ProtocolVersion version : ProtocolVersion.SUPPORTED) + eventSerDeserTest(version); } - public void eventSerDeserTest(int version) throws Exception + public void eventSerDeserTest(ProtocolVersion version) throws Exception { List<Event> events = new ArrayList<>(); @@ -115,14 +129,14 @@ public class SerDeserTest events.add(new SchemaChange(SchemaChange.Change.UPDATED, SchemaChange.Target.TABLE, "ks", "table")); events.add(new SchemaChange(SchemaChange.Change.DROPPED, SchemaChange.Target.TABLE, "ks", "table")); - if (version >= 3) + if (version.isGreaterOrEqualTo(ProtocolVersion.V3)) { events.add(new SchemaChange(SchemaChange.Change.CREATED, SchemaChange.Target.TYPE, "ks", "type")); events.add(new SchemaChange(SchemaChange.Change.UPDATED, SchemaChange.Target.TYPE, "ks", "type")); events.add(new SchemaChange(SchemaChange.Change.DROPPED, SchemaChange.Target.TYPE, "ks", "type")); } - if (version >= 4) + if (version.isGreaterOrEqualTo(ProtocolVersion.V4)) { List<String> moreTypes = Arrays.asList("text", "bigint"); @@ -176,12 +190,12 @@ public class SerDeserTest @Test public void udtSerDeserTest() throws Exception { - udtSerDeserTest(3); - udtSerDeserTest(4); + for (ProtocolVersion version : ProtocolVersion.SUPPORTED) + udtSerDeserTest(version); } - public void udtSerDeserTest(int version) throws Exception + public void udtSerDeserTest(ProtocolVersion version) throws Exception { ListType<?> lt = ListType.getInstance(Int32Type.instance, true); SetType<?> st = SetType.getInstance(UTF8Type.instance, true); @@ -218,45 +232,109 @@ public class SerDeserTest // a UDT should alway be serialized with version 3 of the protocol. Which is why we don't use 'version' // on purpose below. - assertEquals(Arrays.asList(3, 1), lt.getSerializer().deserializeForNativeProtocol(fields[1], 3)); + assertEquals(Arrays.asList(3, 1), lt.getSerializer().deserializeForNativeProtocol(fields[1], ProtocolVersion.V3)); LinkedHashSet<String> s = new LinkedHashSet<>(); s.addAll(Arrays.asList("bar", "foo")); - assertEquals(s, st.getSerializer().deserializeForNativeProtocol(fields[2], 3)); + assertEquals(s, st.getSerializer().deserializeForNativeProtocol(fields[2], ProtocolVersion.V3)); LinkedHashMap<String, Long> m = new LinkedHashMap<>(); m.put("bar", 12L); m.put("foo", 24L); - assertEquals(m, mt.getSerializer().deserializeForNativeProtocol(fields[3], 3)); + assertEquals(m, mt.getSerializer().deserializeForNativeProtocol(fields[3], ProtocolVersion.V3)); } @Test public void preparedMetadataSerializationTest() { + for (ProtocolVersion version : ProtocolVersion.SUPPORTED) + preparedMetadataSerializationTest(version); + } + + private void preparedMetadataSerializationTest(ProtocolVersion version) + { List<ColumnSpecification> columnNames = new ArrayList<>(); for (int i = 0; i < 3; i++) columnNames.add(new ColumnSpecification("ks", "cf", new ColumnIdentifier("col" + i, false), Int32Type.instance)); - ResultSet.PreparedMetadata meta = new ResultSet.PreparedMetadata(columnNames, new short[]{2, 1}); - ByteBuf buf = Unpooled.buffer(meta.codec.encodedSize(meta, Server.VERSION_4)); - meta.codec.encode(meta, buf, Server.VERSION_4); - ResultSet.PreparedMetadata decodedMeta = meta.codec.decode(buf, Server.VERSION_4); + if (version == ProtocolVersion.V3) + { + // v3 encoding doesn't include partition key bind indexes + ResultSet.PreparedMetadata meta = new ResultSet.PreparedMetadata(columnNames, new short[]{ 2, 1 }); + ByteBuf buf = Unpooled.buffer(ResultSet.PreparedMetadata.codec.encodedSize(meta, version)); + ResultSet.PreparedMetadata.codec.encode(meta, buf, version); + ResultSet.PreparedMetadata decodedMeta = ResultSet.PreparedMetadata.codec.decode(buf, version); - assertEquals(meta, decodedMeta); + assertNotSame(meta, decodedMeta); + + // however, if there are no partition key indexes, they should be the same + ResultSet.PreparedMetadata metaWithoutIndexes = new ResultSet.PreparedMetadata(columnNames, null); + buf = Unpooled.buffer(metaWithoutIndexes.codec.encodedSize(metaWithoutIndexes, version)); + metaWithoutIndexes.codec.encode(metaWithoutIndexes, buf, version); + ResultSet.PreparedMetadata decodedMetaWithoutIndexes = metaWithoutIndexes.codec.decode(buf, version); + + assertEquals(decodedMeta, decodedMetaWithoutIndexes); + } + else + { + ResultSet.PreparedMetadata meta = new ResultSet.PreparedMetadata(columnNames, new short[]{ 2, 1 }); + ByteBuf buf = Unpooled.buffer(ResultSet.PreparedMetadata.codec.encodedSize(meta, version)); + ResultSet.PreparedMetadata.codec.encode(meta, buf, version); + ResultSet.PreparedMetadata decodedMeta = ResultSet.PreparedMetadata.codec.decode(buf, version); + assertEquals(meta, decodedMeta); + } + } - // v3 encoding doesn't include partition key bind indexes - buf = Unpooled.buffer(meta.codec.encodedSize(meta, Server.VERSION_3)); - meta.codec.encode(meta, buf, Server.VERSION_3); - decodedMeta = meta.codec.decode(buf, Server.VERSION_3); + @Test + public void metadataSerializationTest() + { + for (ProtocolVersion version : ProtocolVersion.SUPPORTED) + metadataSerializationTest(version); + } - assertNotSame(meta, decodedMeta); + private void metadataSerializationTest(ProtocolVersion version) + { + List<ColumnSpecification> columnNames = new ArrayList<>(); + for (int i = 0; i < 3; i++) + columnNames.add(new ColumnSpecification("ks", "cf", new ColumnIdentifier("col" + i, false), Int32Type.instance)); - // however, if there are no partition key indexes, they should be the same - ResultSet.PreparedMetadata metaWithoutIndexes = new ResultSet.PreparedMetadata(columnNames, null); - buf = Unpooled.buffer(metaWithoutIndexes.codec.encodedSize(metaWithoutIndexes, Server.VERSION_4)); - metaWithoutIndexes.codec.encode(metaWithoutIndexes, buf, Server.VERSION_4); - ResultSet.PreparedMetadata decodedMetaWithoutIndexes = metaWithoutIndexes.codec.decode(buf, Server.VERSION_4); + ResultSet.ResultMetadata meta = new ResultSet.ResultMetadata(columnNames); + ByteBuf buf = Unpooled.buffer(meta.codec.encodedSize(meta, version)); + meta.codec.encode(meta, buf, version); + ResultSet.ResultMetadata decodedMeta = meta.codec.decode(buf, version); - assertEquals(decodedMeta, decodedMetaWithoutIndexes); + assertEquals(meta, decodedMeta); + } + + @Test + public void queryOptionsSerDeserTest() throws Exception + { + for (ProtocolVersion version : ProtocolVersion.SUPPORTED) + queryOptionsSerDeserTest(version); + } + + private void queryOptionsSerDeserTest(ProtocolVersion version) throws Exception + { + QueryOptions options = QueryOptions.create(ConsistencyLevel.ALL, + Collections.singletonList(ByteBuffer.wrap(new byte[] { 0x00, 0x01, 0x02 })), + false, + 5000, + Util.makeSomePagingState(version), + ConsistencyLevel.SERIAL, + version + ); + + ByteBuf buf = Unpooled.buffer(QueryOptions.codec.encodedSize(options, version)); + QueryOptions.codec.encode(options, buf, version); + QueryOptions decodedOptions = QueryOptions.codec.decode(buf, version); + + assertNotNull(decodedOptions); + assertEquals(options.getConsistency(), decodedOptions.getConsistency()); + assertEquals(options.getSerialConsistency(), decodedOptions.getSerialConsistency()); + assertEquals(options.getPageSize(), decodedOptions.getPageSize()); + assertEquals(options.getProtocolVersion(), decodedOptions.getProtocolVersion()); + assertEquals(options.getValues(), decodedOptions.getValues()); + assertEquals(options.getPagingState(), decodedOptions.getPagingState()); + assertEquals(options.skipMetadata(), decodedOptions.skipMetadata()); } } http://git-wip-us.apache.org/repos/asf/cassandra/blob/e0adc166/test/unit/org/apache/cassandra/utils/CassandraVersionTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/utils/CassandraVersionTest.java b/test/unit/org/apache/cassandra/utils/CassandraVersionTest.java index d8d0a8a..da7e266 100644 --- a/test/unit/org/apache/cassandra/utils/CassandraVersionTest.java +++ b/test/unit/org/apache/cassandra/utils/CassandraVersionTest.java @@ -176,7 +176,7 @@ public class CassandraVersionTest next = new CassandraVersion("3.2"); assertTrue(prev.compareTo(next) < 0); } - + private static void assertThrows(String str) { try @@ -186,7 +186,7 @@ public class CassandraVersionTest } catch (IllegalArgumentException e) {} } - + @Test public void testParseIdentifiersPositive() throws Throwable { @@ -194,7 +194,7 @@ public class CassandraVersionTest String[] expected = {"a", "b", "cde", "f_g"}; assertArrayEquals(expected, result); } - + @Test public void testParseIdentifiersNegative() throws Throwable { @@ -202,7 +202,7 @@ public class CassandraVersionTest try { parseIdentifiers(version, "+a. .b"); - + } catch (IllegalArgumentException e) { @@ -215,13 +215,13 @@ public class CassandraVersionTest Class[] args = {String.class, String.class}; for (Method m: CassandraVersion.class.getDeclaredMethods()) { - if (name.equals(m.getName()) && + if (name.equals(m.getName()) && Arrays.equals(args, m.getParameterTypes())) { m.setAccessible(true); - try + try { - return (String[]) m.invoke(null, version, str); + return (String[]) m.invoke(null, version, str); } catch (InvocationTargetException e){ throw e.getTargetException(); }