From 292bf8ff4d1036f41a6b7f6a2aee3f0d928548e6 Mon Sep 17 00:00:00 2001 From: Andrew Tolbert Date: Thu, 12 Jul 2018 16:08:47 -0500 Subject: [PATCH] Fix unset and custom payload assumptions in BoundStatementIT * CassandraRequirement does not work at method level when using CcmRule with ClassRule annotation. * Don't add Custom Payload to Statement when V4 is not used. --- .../driver/api/core/cql/BoundStatementIT.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/integration-tests/src/test/java/com/datastax/oss/driver/api/core/cql/BoundStatementIT.java b/integration-tests/src/test/java/com/datastax/oss/driver/api/core/cql/BoundStatementIT.java index f843f4839a2..065e9bdb31b 100644 --- a/integration-tests/src/test/java/com/datastax/oss/driver/api/core/cql/BoundStatementIT.java +++ b/integration-tests/src/test/java/com/datastax/oss/driver/api/core/cql/BoundStatementIT.java @@ -19,6 +19,7 @@ import static com.datastax.oss.simulacron.common.stubbing.PrimeDsl.query; import static com.datastax.oss.simulacron.common.stubbing.PrimeDsl.when; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assumptions.assumeThat; import com.datastax.oss.driver.api.core.ConsistencyLevel; import com.datastax.oss.driver.api.core.CqlIdentifier; @@ -29,7 +30,6 @@ import com.datastax.oss.driver.api.core.config.DriverExecutionProfile; import com.datastax.oss.driver.api.core.metadata.token.Token; import com.datastax.oss.driver.api.core.type.codec.TypeCodecs; -import com.datastax.oss.driver.api.testinfra.CassandraRequirement; import com.datastax.oss.driver.api.testinfra.ccm.CcmRule; import com.datastax.oss.driver.api.testinfra.session.SessionRule; import com.datastax.oss.driver.api.testinfra.session.SessionUtils; @@ -71,6 +71,8 @@ public class BoundStatementIT { @ClassRule public static CcmRule ccm = CcmRule.getInstance(); + private static boolean atLeastV4 = ccm.getHighestProtocolVersion().getCode() >= 4; + @ClassRule public static SessionRule sessionRule = new SessionRule<>(ccm, "basic.request.page-size = 20"); @@ -131,8 +133,8 @@ public void should_not_allow_unset_value_when_protocol_less_than_v4() { } @Test - @CassandraRequirement(min = "2.2") public void should_not_write_tombstone_if_value_is_implicitly_unset() { + assumeThat(atLeastV4).as("unset values require protocol V4+").isTrue(); try (CqlSession session = SessionUtils.newSession(ccm, sessionRule.keyspace())) { PreparedStatement prepared = session.prepare("INSERT INTO test2 (k, v0) values (?, ?)"); @@ -146,8 +148,8 @@ public void should_not_write_tombstone_if_value_is_implicitly_unset() { } @Test - @CassandraRequirement(min = "2.2") public void should_write_tombstone_if_value_is_explicitly_unset() { + assumeThat(atLeastV4).as("unset values require protocol V4+").isTrue(); try (CqlSession session = SessionUtils.newSession(ccm, sessionRule.keyspace())) { PreparedStatement prepared = session.prepare("INSERT INTO test2 (k, v0) values (?, ?)"); @@ -165,8 +167,8 @@ public void should_write_tombstone_if_value_is_explicitly_unset() { } @Test - @CassandraRequirement(min = "2.2") public void should_write_tombstone_if_value_is_explicitly_unset_on_builder() { + assumeThat(atLeastV4).as("unset values require protocol V4+").isTrue(); try (CqlSession session = SessionUtils.newSession(ccm, sessionRule.keyspace())) { PreparedStatement prepared = session.prepare("INSERT INTO test2 (k, v0) values (?, ?)"); @@ -379,7 +381,6 @@ public void should_use_timeout() { } @Test - @CassandraRequirement(min = "2.2") public void should_propagate_attributes_when_preparing_a_simple_statement() { CqlSession session = sessionRule.session(); @@ -404,7 +405,7 @@ public void should_propagate_attributes_when_preparing_a_simple_statement() { ConsistencyLevel mockSerialCl = DefaultConsistencyLevel.LOCAL_SERIAL; int mockPageSize = 2000; - SimpleStatement simpleStatement = + SimpleStatementBuilder simpleStatementBuilder = SimpleStatement.builder("SELECT release_version FROM system.local") .withExecutionProfile(mockProfile) .withExecutionProfileName(mockConfigProfileName) @@ -413,16 +414,20 @@ public void should_propagate_attributes_when_preparing_a_simple_statement() { .withRoutingKeyspace(mockRoutingKeyspace) .withRoutingKey(mockRoutingKey) .withRoutingToken(mockRoutingToken) - .addCustomPayload("key1", mockCustomPayload.get("key1")) .withTimestamp(42) .withIdempotence(true) .withTracing() .withTimeout(mockTimeout) .withConsistencyLevel(mockCl) .withSerialConsistencyLevel(mockSerialCl) - .withPageSize(mockPageSize) - .build(); - PreparedStatement preparedStatement = session.prepare(simpleStatement); + .withPageSize(mockPageSize); + + if (atLeastV4) { + simpleStatementBuilder = + simpleStatementBuilder.addCustomPayload("key1", mockCustomPayload.get("key1")); + } + + PreparedStatement preparedStatement = session.prepare(simpleStatementBuilder.build()); // Cover all the ways to create bound statements: ImmutableList> createMethods = @@ -438,7 +443,9 @@ public void should_propagate_attributes_when_preparing_a_simple_statement() { .isEqualTo(mockKeyspace != null ? mockKeyspace : mockRoutingKeyspace); assertThat(boundStatement.getRoutingKey()).isEqualTo(mockRoutingKey); assertThat(boundStatement.getRoutingToken()).isEqualTo(mockRoutingToken); - assertThat(boundStatement.getCustomPayload()).isEqualTo(mockCustomPayload); + if (atLeastV4) { + assertThat(boundStatement.getCustomPayload()).isEqualTo(mockCustomPayload); + } assertThat(boundStatement.isIdempotent()).isTrue(); assertThat(boundStatement.isTracing()).isTrue(); assertThat(boundStatement.getTimeout()).isEqualTo(mockTimeout);