1919import static com .datastax .oss .simulacron .common .stubbing .PrimeDsl .query ;
2020import static com .datastax .oss .simulacron .common .stubbing .PrimeDsl .when ;
2121import static org .assertj .core .api .Assertions .assertThat ;
22+ import static org .assertj .core .api .Assumptions .assumeThat ;
2223
2324import com .datastax .oss .driver .api .core .ConsistencyLevel ;
2425import com .datastax .oss .driver .api .core .CqlIdentifier ;
2930import com .datastax .oss .driver .api .core .config .DriverExecutionProfile ;
3031import com .datastax .oss .driver .api .core .metadata .token .Token ;
3132import com .datastax .oss .driver .api .core .type .codec .TypeCodecs ;
32- import com .datastax .oss .driver .api .testinfra .CassandraRequirement ;
3333import com .datastax .oss .driver .api .testinfra .ccm .CcmRule ;
3434import com .datastax .oss .driver .api .testinfra .session .SessionRule ;
3535import com .datastax .oss .driver .api .testinfra .session .SessionUtils ;
@@ -71,6 +71,8 @@ public class BoundStatementIT {
7171
7272 @ ClassRule public static CcmRule ccm = CcmRule .getInstance ();
7373
74+ private static boolean atLeastV4 = ccm .getHighestProtocolVersion ().getCode () >= 4 ;
75+
7476 @ ClassRule
7577 public static SessionRule <CqlSession > sessionRule =
7678 new SessionRule <>(ccm , "basic.request.page-size = 20" );
@@ -131,8 +133,8 @@ public void should_not_allow_unset_value_when_protocol_less_than_v4() {
131133 }
132134
133135 @ Test
134- @ CassandraRequirement (min = "2.2" )
135136 public void should_not_write_tombstone_if_value_is_implicitly_unset () {
137+ assumeThat (atLeastV4 ).as ("unset values require protocol V4+" ).isTrue ();
136138 try (CqlSession session = SessionUtils .newSession (ccm , sessionRule .keyspace ())) {
137139 PreparedStatement prepared = session .prepare ("INSERT INTO test2 (k, v0) values (?, ?)" );
138140
@@ -146,8 +148,8 @@ public void should_not_write_tombstone_if_value_is_implicitly_unset() {
146148 }
147149
148150 @ Test
149- @ CassandraRequirement (min = "2.2" )
150151 public void should_write_tombstone_if_value_is_explicitly_unset () {
152+ assumeThat (atLeastV4 ).as ("unset values require protocol V4+" ).isTrue ();
151153 try (CqlSession session = SessionUtils .newSession (ccm , sessionRule .keyspace ())) {
152154 PreparedStatement prepared = session .prepare ("INSERT INTO test2 (k, v0) values (?, ?)" );
153155
@@ -165,8 +167,8 @@ public void should_write_tombstone_if_value_is_explicitly_unset() {
165167 }
166168
167169 @ Test
168- @ CassandraRequirement (min = "2.2" )
169170 public void should_write_tombstone_if_value_is_explicitly_unset_on_builder () {
171+ assumeThat (atLeastV4 ).as ("unset values require protocol V4+" ).isTrue ();
170172 try (CqlSession session = SessionUtils .newSession (ccm , sessionRule .keyspace ())) {
171173 PreparedStatement prepared = session .prepare ("INSERT INTO test2 (k, v0) values (?, ?)" );
172174
@@ -379,7 +381,6 @@ public void should_use_timeout() {
379381 }
380382
381383 @ Test
382- @ CassandraRequirement (min = "2.2" )
383384 public void should_propagate_attributes_when_preparing_a_simple_statement () {
384385 CqlSession session = sessionRule .session ();
385386
@@ -404,7 +405,7 @@ public void should_propagate_attributes_when_preparing_a_simple_statement() {
404405 ConsistencyLevel mockSerialCl = DefaultConsistencyLevel .LOCAL_SERIAL ;
405406 int mockPageSize = 2000 ;
406407
407- SimpleStatement simpleStatement =
408+ SimpleStatementBuilder simpleStatementBuilder =
408409 SimpleStatement .builder ("SELECT release_version FROM system.local" )
409410 .withExecutionProfile (mockProfile )
410411 .withExecutionProfileName (mockConfigProfileName )
@@ -413,16 +414,20 @@ public void should_propagate_attributes_when_preparing_a_simple_statement() {
413414 .withRoutingKeyspace (mockRoutingKeyspace )
414415 .withRoutingKey (mockRoutingKey )
415416 .withRoutingToken (mockRoutingToken )
416- .addCustomPayload ("key1" , mockCustomPayload .get ("key1" ))
417417 .withTimestamp (42 )
418418 .withIdempotence (true )
419419 .withTracing ()
420420 .withTimeout (mockTimeout )
421421 .withConsistencyLevel (mockCl )
422422 .withSerialConsistencyLevel (mockSerialCl )
423- .withPageSize (mockPageSize )
424- .build ();
425- PreparedStatement preparedStatement = session .prepare (simpleStatement );
423+ .withPageSize (mockPageSize );
424+
425+ if (atLeastV4 ) {
426+ simpleStatementBuilder =
427+ simpleStatementBuilder .addCustomPayload ("key1" , mockCustomPayload .get ("key1" ));
428+ }
429+
430+ PreparedStatement preparedStatement = session .prepare (simpleStatementBuilder .build ());
426431
427432 // Cover all the ways to create bound statements:
428433 ImmutableList <Function <PreparedStatement , BoundStatement >> createMethods =
@@ -438,7 +443,9 @@ public void should_propagate_attributes_when_preparing_a_simple_statement() {
438443 .isEqualTo (mockKeyspace != null ? mockKeyspace : mockRoutingKeyspace );
439444 assertThat (boundStatement .getRoutingKey ()).isEqualTo (mockRoutingKey );
440445 assertThat (boundStatement .getRoutingToken ()).isEqualTo (mockRoutingToken );
441- assertThat (boundStatement .getCustomPayload ()).isEqualTo (mockCustomPayload );
446+ if (atLeastV4 ) {
447+ assertThat (boundStatement .getCustomPayload ()).isEqualTo (mockCustomPayload );
448+ }
442449 assertThat (boundStatement .isIdempotent ()).isTrue ();
443450 assertThat (boundStatement .isTracing ()).isTrue ();
444451 assertThat (boundStatement .getTimeout ()).isEqualTo (mockTimeout );
0 commit comments