Skip to content

Commit 7d01a5b

Browse files
committed
JAVA-3068: Use fully qualified table CQL in should_not_allow_unset_value_when_protocol_less_than_v4 to work around intermittent server error
1 parent 4af9f5a commit 7d01a5b

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

integration-tests/src/test/java/com/datastax/oss/driver/core/cql/BatchStatementIT.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.datastax.oss.driver.core.cql;
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1920

2021
import com.datastax.oss.driver.api.core.CqlSession;
2122
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
@@ -338,16 +339,20 @@ public void should_fail_counter_batch_with_non_counter_increment() {
338339
sessionRule.session().execute(batchStatement);
339340
}
340341

341-
@Test(expected = IllegalStateException.class)
342+
@Test
342343
public void should_not_allow_unset_value_when_protocol_less_than_v4() {
343344
// CREATE TABLE test (k0 text, k1 int, v int, PRIMARY KEY (k0, k1))
344345
DriverConfigLoader loader =
345346
SessionUtils.configLoaderBuilder()
346347
.withString(DefaultDriverOption.PROTOCOL_VERSION, "V3")
347348
.build();
348-
try (CqlSession v3Session = SessionUtils.newSession(ccmRule, sessionRule.keyspace(), loader)) {
349+
try (CqlSession v3Session = SessionUtils.newSession(ccmRule, loader)) {
350+
// Intentionally use fully qualified table here to avoid warnings as these are not supported
351+
// by v3 protocol version, see JAVA-3068
349352
PreparedStatement prepared =
350-
v3Session.prepare("INSERT INTO test (k0, k1, v) values (?, ?, ?)");
353+
v3Session.prepare(
354+
String.format(
355+
"INSERT INTO %s.test (k0, k1, v) values (?, ?, ?)", sessionRule.keyspace()));
351356

352357
BatchStatementBuilder builder = BatchStatement.builder(DefaultBatchType.LOGGED);
353358
builder.addStatements(
@@ -361,7 +366,9 @@ public void should_not_allow_unset_value_when_protocol_less_than_v4() {
361366
.unset(2)
362367
.build());
363368

364-
v3Session.execute(builder.build());
369+
assertThatThrownBy(() -> v3Session.execute(builder.build()))
370+
.isInstanceOf(IllegalStateException.class)
371+
.hasMessageContaining("Unset value at index");
365372
}
366373
}
367374

integration-tests/src/test/java/com/datastax/oss/driver/core/cql/BoundStatementCcmIT.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.datastax.oss.driver.core.cql;
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1920
import static org.assertj.core.api.Assumptions.assumeThat;
2021

2122
import com.datastax.oss.driver.api.core.ConsistencyLevel;
@@ -126,19 +127,25 @@ public void setupSchema() {
126127
.build());
127128
}
128129

129-
@Test(expected = IllegalStateException.class)
130+
@Test
130131
public void should_not_allow_unset_value_when_protocol_less_than_v4() {
131132
DriverConfigLoader loader =
132133
SessionUtils.configLoaderBuilder()
133134
.withString(DefaultDriverOption.PROTOCOL_VERSION, "V3")
134135
.build();
135-
try (CqlSession v3Session = SessionUtils.newSession(ccmRule, sessionRule.keyspace(), loader)) {
136-
PreparedStatement prepared = v3Session.prepare("INSERT INTO test2 (k, v0) values (?, ?)");
136+
try (CqlSession v3Session = SessionUtils.newSession(ccmRule, loader)) {
137+
// Intentionally use fully qualified table here to avoid warnings as these are not supported
138+
// by v3 protocol version, see JAVA-3068
139+
PreparedStatement prepared =
140+
v3Session.prepare(
141+
String.format("INSERT INTO %s.test2 (k, v0) values (?, ?)", sessionRule.keyspace()));
137142

138143
BoundStatement boundStatement =
139144
prepared.boundStatementBuilder().setString(0, name.getMethodName()).unset(1).build();
140145

141-
v3Session.execute(boundStatement);
146+
assertThatThrownBy(() -> v3Session.execute(boundStatement))
147+
.isInstanceOf(IllegalStateException.class)
148+
.hasMessageContaining("Unset value at index");
142149
}
143150
}
144151

0 commit comments

Comments
 (0)