Search in sources :

Example 6 with Message

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);
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Query(com.datastax.oss.protocol.internal.request.Query) RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DseQueryOptions(com.datastax.dse.protocol.internal.request.query.DseQueryOptions) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 7 with Message

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());
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Query(com.datastax.oss.protocol.internal.request.Query) RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) ScriptGraphStatement(com.datastax.dse.driver.api.core.graph.ScriptGraphStatement) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) Test(org.junit.Test)

Example 8 with Message

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);
    }
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Execute(com.datastax.oss.protocol.internal.request.Execute)

Example 9 with Message

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();
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Query(com.datastax.oss.protocol.internal.request.Query) RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) ScriptGraphStatement(com.datastax.dse.driver.api.core.graph.ScriptGraphStatement) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 10 with Message

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);
}
Also used : RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) Message(com.datastax.oss.protocol.internal.Message) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

Message (com.datastax.oss.protocol.internal.Message)14 Test (org.junit.Test)8 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)7 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)5 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)5 RawBytesQuery (com.datastax.dse.protocol.internal.request.RawBytesQuery)5 Execute (com.datastax.oss.protocol.internal.request.Execute)4 Query (com.datastax.oss.protocol.internal.request.Query)4 QueryLog (com.datastax.oss.simulacron.common.cluster.QueryLog)4 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)4 ByteBuffer (java.nio.ByteBuffer)4 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)3 ScriptGraphStatement (com.datastax.dse.driver.api.core.graph.ScriptGraphStatement)2 CqlSession (com.datastax.oss.driver.api.core.CqlSession)2 NodeUnavailableException (com.datastax.oss.driver.api.core.NodeUnavailableException)2 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)2 Node (com.datastax.oss.driver.api.core.metadata.Node)2 DriverChannel (com.datastax.oss.driver.internal.core.channel.DriverChannel)2 DefaultNode (com.datastax.oss.driver.internal.core.metadata.DefaultNode)2 GraphNode (com.datastax.dse.driver.api.core.graph.GraphNode)1