Elffuss BraidHub

kikocis/java-driver public

JAVA-1313: Copy SerialConsistencyLevel to PreparedStatement

Motivation:

A serial consistency level set on a statement that is going
to be prepared is not being propagated to the prepared statement.

Modifications:

Modify AbstractSession.prepareAsync(RegularStatement) and propagate
the serial consistency level to prepared statements, just as for
other inherited properties.

Result:

Serial consistency level is now being propagated to prepared
statements.
Changeset83e16610372dfea6e5f8feb5d15bcafa14e642ae2c9abce03cf7713e3cd26ef7
AuthorAlexandre Dutra <alexandre.dutra@datastax.com> · 2017-02-09 10:20 +01:00
CommitterAlexandre Dutra <alexandre.dutra@datastax.com> · 2017-02-09 15:51 +01:00
Parentsb30b02a7d32d

Browse the files at this changeset

3 files changed

modified changelog/README.md +1 −0
@@ -3,6 +3,7 @@
33 ### 3.0.7 (in progress)
44
55 - [bug] JAVA-1371: Reintroduce connection pool timeout.
6+- [bug] JAVA-1313: Copy SerialConsistencyLevel to PreparedStatement.
67
78
89 ### 3.0.6
modified driver-core/src/main/java/com/datastax/driver/core/AbstractSession.java +4 −1
@@ -144,7 +144,10 @@
144144 ByteBuffer routingKey = statement.getRoutingKey(protocolVersion, codecRegistry);
145145 if (routingKey != null)
146146 prepared.setRoutingKey(routingKey);
147- prepared.setConsistencyLevel(statement.getConsistencyLevel());
147+ if (statement.getConsistencyLevel() != null)
148+ prepared.setConsistencyLevel(statement.getConsistencyLevel());
149+ if (statement.getSerialConsistencyLevel() != null)
150+ prepared.setSerialConsistencyLevel(statement.getSerialConsistencyLevel());
148151 if (statement.isTracing())
149152 prepared.enableTracing();
150153 prepared.setRetryPolicy(statement.getRetryPolicy());
modified driver-core/src/test/java/com/datastax/driver/core/PreparedStatementTest.java +24 −3
@@ -17,7 +17,10 @@
1717
1818 import com.datastax.driver.core.exceptions.InvalidQueryException;
1919 import com.datastax.driver.core.exceptions.UnsupportedFeatureException;
20+import com.datastax.driver.core.policies.FallthroughRetryPolicy;
21+import com.datastax.driver.core.utils.Bytes;
2022 import com.datastax.driver.core.utils.CassandraVersion;
23+import com.google.common.collect.ImmutableMap;
2124 import com.google.common.util.concurrent.Uninterruptibles;
2225 import org.testng.annotations.Test;
2326
@@ -25,6 +28,7 @@
2528 import java.util.*;
2629 import java.util.concurrent.TimeUnit;
2730
31+import static com.datastax.driver.core.ProtocolVersion.V4;
2832 import static com.datastax.driver.core.TestUtils.*;
2933 import static org.assertj.core.api.Assertions.assertThat;
3034 import static org.testng.Assert.*;
@@ -334,13 +338,30 @@
334338
335339 RegularStatement toPrepare = new SimpleStatement("SELECT * FROM test WHERE k=?");
336340 toPrepare.setConsistencyLevel(ConsistencyLevel.QUORUM);
341+ toPrepare.setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL);
342+ toPrepare.setRetryPolicy(FallthroughRetryPolicy.INSTANCE);
343+ if (TestUtils.getDesiredProtocolVersion().compareTo(V4) >= 0)
344+ toPrepare.setOutgoingPayload(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe")));
345+ toPrepare.setIdempotent(true);
337346 toPrepare.enableTracing();
338347
339348 PreparedStatement prepared = session().prepare(toPrepare);
340- BoundStatement bs = prepared.bind("someValue");
349+ assertThat(prepared.getConsistencyLevel()).isEqualTo(ConsistencyLevel.QUORUM);
350+ assertThat(prepared.getSerialConsistencyLevel()).isEqualTo(ConsistencyLevel.LOCAL_SERIAL);
351+ assertThat(prepared.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE);
352+ if (TestUtils.getDesiredProtocolVersion().compareTo(V4) >= 0)
353+ assertThat(prepared.getOutgoingPayload()).isEqualTo(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe")));
354+ assertThat(prepared.isIdempotent()).isTrue();
355+ assertThat(prepared.isTracing()).isTrue();
341356
342- assertEquals(ConsistencyLevel.QUORUM, bs.getConsistencyLevel());
343- assertTrue(bs.isTracing());
357+ BoundStatement bs = prepared.bind("someValue");
358+ assertThat(bs.getConsistencyLevel()).isEqualTo(ConsistencyLevel.QUORUM);
359+ assertThat(bs.getSerialConsistencyLevel()).isEqualTo(ConsistencyLevel.LOCAL_SERIAL);
360+ assertThat(bs.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE);
361+ if (TestUtils.getDesiredProtocolVersion().compareTo(V4) >= 0)
362+ assertThat(bs.getOutgoingPayload()).isEqualTo(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe")));
363+ assertThat(bs.isIdempotent()).isTrue();
364+ assertThat(bs.isTracing()).isTrue();
344365 }
345366
346367 /**