use of com.datastax.oss.protocol.internal.Message in project java-driver by datastax.
the class GraphRequestHandlerTest method should_set_correct_query_options_from_graph_statement.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_set_correct_query_options_from_graph_statement(GraphProtocol subProtocol) throws IOException {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery").setQueryParam("name", "value");
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// when
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
Message m = GraphConversions.createMessageFromGraphStatement(graphStatement, subProtocol, executionProfile, harness.getContext(), module);
// checks
Query query = ((Query) m);
DseQueryOptions options = ((DseQueryOptions) query.options);
assertThat(options.consistency).isEqualTo(DefaultConsistencyLevel.valueOf(executionProfile.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).getProtocolCode());
// set by the mock timestamp generator
assertThat(options.defaultTimestamp).isEqualTo(-9223372036854775808L);
assertThat(options.positionalValues).isEqualTo(ImmutableList.of(serialize(ImmutableMap.of("name", "value"), subProtocol, module)));
m = GraphConversions.createMessageFromGraphStatement(graphStatement.setTimestamp(2L), subProtocol, executionProfile, harness.getContext(), module);
query = ((Query) m);
options = ((DseQueryOptions) query.options);
assertThat(options.defaultTimestamp).isEqualTo(2L);
}
use of com.datastax.oss.protocol.internal.Message in project java-driver by datastax.
the class GraphRequestHandlerTest method should_honor_statement_consistency_level.
@Test
public void should_honor_statement_consistency_level() {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
ScriptGraphStatement graphStatement = ScriptGraphStatement.builder("mockScript").setConsistencyLevel(DefaultConsistencyLevel.THREE).build();
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// when
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
Message m = GraphConversions.createMessageFromGraphStatement(graphStatement, GRAPH_BINARY_1_0, executionProfile, harness.getContext(), module);
// checks
assertThat(m).isInstanceOf(Query.class);
Query q = ((Query) m);
assertThat(q.options.consistency).isEqualTo(DefaultConsistencyLevel.THREE.getProtocolCode());
}
use of com.datastax.oss.protocol.internal.Message in project java-driver by datastax.
the class StatementAttributesIT method validateQueryOptions.
private void validateQueryOptions(QueryLog log, boolean validatePageState) {
Message message = log.getFrame().message;
assertThat(message).isInstanceOf(Execute.class);
Execute queryExecute = (Execute) message;
assertThat(queryExecute.options.consistency).isEqualTo(DefaultConsistencyLevel.ANY.getProtocolCode());
assertThat(queryExecute.options.serialConsistency).isEqualTo(DefaultConsistencyLevel.QUORUM.getProtocolCode());
assertThat(queryExecute.options.pageSize).isEqualTo(PAGE_SIZE);
if (validatePageState) {
String pagingState = UTF_8.decode(queryExecute.options.pagingState).toString();
assertThat(pagingState).isEqualTo(PAGING_STATE);
}
}
use of com.datastax.oss.protocol.internal.Message in project java-driver by datastax.
the class GraphRequestHandlerTest method should_create_query_message_from_script_statement.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_create_query_message_from_script_statement(GraphProtocol graphProtocol) throws IOException {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
ScriptGraphStatement graphStatement = ScriptGraphStatement.newInstance("mockQuery").setQueryParam("p1", 1L).setQueryParam("p2", Uuids.random());
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// when
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
Message m = GraphConversions.createMessageFromGraphStatement(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
// checks
assertThat(m).isInstanceOf(Query.class);
Query q = ((Query) m);
assertThat(q.query).isEqualTo("mockQuery");
assertThat(q.options.positionalValues).containsExactly(serialize(graphStatement.getQueryParams(), graphProtocol, module));
assertThat(q.options.namedValues).isEmpty();
}
use of com.datastax.oss.protocol.internal.Message in project java-driver by datastax.
the class GraphRequestHandlerTest method should_create_query_message_from_fluent_statement.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_create_query_message_from_fluent_statement(GraphProtocol graphProtocol) throws IOException {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
GraphTraversal<?, ?> traversalTest = DseGraph.g.V().has("person", "name", "marko").has("p1", 1L).has("p2", Uuids.random());
GraphStatement<?> graphStatement = FluentGraphStatement.newInstance(traversalTest);
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// when
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
Message m = GraphConversions.createMessageFromGraphStatement(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
Map<String, ByteBuffer> createdCustomPayload = GraphConversions.createCustomPayload(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
// checks
assertThat(m).isInstanceOf(RawBytesQuery.class);
testQueryRequestAndPayloadContents(((RawBytesQuery) m), createdCustomPayload, GraphConversions.bytecodeToSerialize(graphStatement), graphProtocol, module);
}
Aggregations