Skip to content

Commit

Permalink
Fix unset and custom payload assumptions in BoundStatementIT
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
tolbertam committed Jul 12, 2018
1 parent 6b04c21 commit 292bf8f
Showing 1 changed file with 18 additions and 11 deletions.
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<CqlSession> sessionRule =
new SessionRule<>(ccm, "basic.request.page-size = 20");
Expand Down Expand Up @@ -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 (?, ?)");

Expand All @@ -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 (?, ?)");

Expand All @@ -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 (?, ?)");

Expand Down Expand Up @@ -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();

Expand All @@ -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)
Expand All @@ -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<Function<PreparedStatement, BoundStatement>> createMethods =
Expand All @@ -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);
Expand Down

0 comments on commit 292bf8f

Please sign in to comment.