Skip to content

Commit c6b6b73

Browse files
committed
JAVA-2942: GraphStatement.setConsistencyLevel() is not effective
1 parent e2f46f4 commit c6b6b73

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 4.11.2 (in progress)
66

7+
- [bug] JAVA-2942: GraphStatement.setConsistencyLevel() is not effective
78
- [bug] JAVA-2941: Cannot add a single static column with the alter table API
89
- [bug] JAVA-2943: Prevent session leak with wrong keyspace name
910
- [bug] JAVA-2938: OverloadedException message is misleading

core/src/main/java/com/datastax/dse/driver/internal/core/graph/GraphConversions.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,13 @@ static Message createMessageFromGraphStatement(
179179
}
180180
}
181181

182+
ConsistencyLevel consistency = statement.getConsistencyLevel();
182183
int consistencyLevel =
183-
DefaultConsistencyLevel.valueOf(config.getString(DefaultDriverOption.REQUEST_CONSISTENCY))
184-
.getProtocolCode();
184+
(consistency == null)
185+
? context
186+
.getConsistencyLevelRegistry()
187+
.nameToCode(config.getString(DefaultDriverOption.REQUEST_CONSISTENCY))
188+
: consistency.getProtocolCode();
185189

186190
long timestamp = statement.getTimestamp();
187191
if (timestamp == Statement.NO_DEFAULT_TIMESTAMP) {

core/src/test/java/com/datastax/dse/driver/internal/core/graph/GraphRequestHandlerTest.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void should_create_query_message_from_fluent_statement(GraphProtocol grap
137137
throws IOException {
138138
// initialization
139139
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
140-
GraphTraversal traversalTest =
140+
GraphTraversal<?, ?> traversalTest =
141141
DseGraph.g.V().has("person", "name", "marko").has("p1", 1L).has("p2", Uuids.random());
142142
GraphStatement<?> graphStatement = FluentGraphStatement.newInstance(traversalTest);
143143

@@ -171,6 +171,7 @@ public void should_create_query_message_from_batch_statement(GraphProtocol graph
171171
throws IOException {
172172
// initialization
173173
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
174+
@SuppressWarnings("rawtypes")
174175
List<GraphTraversal> traversalsTest =
175176
ImmutableList.of(
176177
// randomly testing some complex data types. Complete suite of data types test is in
@@ -424,7 +425,7 @@ public void should_return_results_for_statements(GraphProtocol graphProtocol, Ve
424425
Mockito.spy(new GraphRequestAsyncProcessor(harness.getContext(), graphSupportChecker));
425426
when(p.getGraphBinaryModule()).thenReturn(module);
426427

427-
GraphStatement graphStatement =
428+
GraphStatement<?> graphStatement =
428429
ScriptGraphStatement.newInstance("mockQuery").setExecutionProfileName("test-graph");
429430
GraphResultSet grs =
430431
new GraphRequestSyncProcessor(p)
@@ -487,7 +488,7 @@ public void should_invoke_request_tracker_and_update_metrics(
487488
RequestTracker requestTracker = mock(RequestTracker.class);
488489
when(harness.getContext().getRequestTracker()).thenReturn(requestTracker);
489490

490-
GraphStatement graphStatement = ScriptGraphStatement.newInstance("mockQuery");
491+
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery");
491492

492493
node1Behavior.setResponseSuccess(defaultDseFrameOf(singleGraphRow(graphProtocol, module)));
493494

@@ -549,6 +550,31 @@ public void should_invoke_request_tracker_and_update_metrics(
549550
verifyNoMoreInteractions(harness.getSession().getMetricUpdater());
550551
}
551552

553+
@Test
554+
public void should_honor_statement_consistency_level() {
555+
// initialization
556+
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
557+
ScriptGraphStatement graphStatement =
558+
ScriptGraphStatement.builder("mockScript")
559+
.setConsistencyLevel(DefaultConsistencyLevel.THREE)
560+
.build();
561+
562+
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
563+
564+
// when
565+
DriverExecutionProfile executionProfile =
566+
Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
567+
568+
Message m =
569+
GraphConversions.createMessageFromGraphStatement(
570+
graphStatement, GRAPH_BINARY_1_0, executionProfile, harness.getContext(), module);
571+
572+
// checks
573+
assertThat(m).isInstanceOf(Query.class);
574+
Query q = ((Query) m);
575+
assertThat(q.options.consistency).isEqualTo(DefaultConsistencyLevel.THREE.getProtocolCode());
576+
}
577+
552578
@DataProvider
553579
public static Object[][] dseVersionsWithDefaultGraphProtocol() {
554580
// Default GraphSON sub protocol version differs based on DSE version, so test with a version

0 commit comments

Comments
 (0)