use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class GraphSupportCheckerTest method should_use_correct_default_protocol_when_parsing.
@Test
@UseDataProvider("dseVersions6")
public void should_use_correct_default_protocol_when_parsing(Version dseVersion) {
GraphStatement graphStatement = mock(GraphStatement.class);
DriverExecutionProfile executionProfile = mock(DriverExecutionProfile.class);
DefaultDriverContext context = mockNodesInMetadataWithVersions(mock(DefaultDriverContext.class), true, dseVersion);
GraphProtocol inferredProtocol = new GraphSupportChecker().inferGraphProtocol(graphStatement, executionProfile, context);
// For DSE 6.8 and newer, the default should be GraphSON binary
// for DSE older than 6.8, the default should be GraphSON2
assertThat(inferredProtocol).isEqualTo((dseVersion.compareTo(Version.parse("6.8.0")) < 0) ? GraphProtocol.GRAPHSON_2_0 : GraphProtocol.GRAPH_BINARY_1_0);
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class GraphSupportCheckerTest method should_pickup_graph_protocol_from_statement.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_pickup_graph_protocol_from_statement(GraphProtocol graphProtocol) {
GraphStatement graphStatement = mock(GraphStatement.class);
DriverExecutionProfile executionProfile = mock(DriverExecutionProfile.class);
when(graphStatement.getSubProtocol()).thenReturn(graphProtocol.toInternalCode());
GraphProtocol inferredProtocol = new GraphSupportChecker().inferGraphProtocol(graphStatement, executionProfile, mock(InternalDriverContext.class));
assertThat(inferredProtocol).isEqualTo(graphProtocol);
verifyZeroInteractions(executionProfile);
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class GraphRequestHandlerTest method should_create_query_message_from_batch_statement.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_create_query_message_from_batch_statement(GraphProtocol graphProtocol) throws IOException {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
@SuppressWarnings("rawtypes") List<GraphTraversal> traversalsTest = ImmutableList.of(// GraphDataTypesTest
DseGraph.g.addV("person").property("p1", 2.3f).property("p2", LocalDateTime.now(ZoneOffset.UTC)), DseGraph.g.addV("software").property("p3", new BigInteger("123456789123456789123456789123456789")).property("p4", ImmutableList.of(Point.fromCoordinates(30.4, 25.63746284))));
GraphStatement<?> graphStatement = BatchGraphStatement.builder().addTraversals(traversalsTest).build();
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);
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class GraphRequestHandlerTest method should_create_payload_from_statement_options.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_create_payload_from_statement_options(GraphProtocol subProtocol) {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
GraphStatement<?> graphStatement = ScriptGraphStatement.builder("mockQuery").setGraphName("mockGraph").setTraversalSource("a").setTimeout(Duration.ofMillis(2)).setReadConsistencyLevel(DefaultConsistencyLevel.TWO).setWriteConsistencyLevel(DefaultConsistencyLevel.THREE).setSystemQuery(false).build();
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// when
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
Map<String, ByteBuffer> requestPayload = GraphConversions.createCustomPayload(graphStatement, subProtocol, executionProfile, harness.getContext(), module);
// checks
Mockito.verify(executionProfile, never()).getString(DseDriverOption.GRAPH_TRAVERSAL_SOURCE, null);
Mockito.verify(executionProfile, never()).getString(DseDriverOption.GRAPH_NAME, null);
Mockito.verify(executionProfile, never()).getBoolean(DseDriverOption.GRAPH_IS_SYSTEM_QUERY, false);
Mockito.verify(executionProfile, never()).getDuration(DseDriverOption.GRAPH_TIMEOUT, Duration.ZERO);
Mockito.verify(executionProfile, never()).getString(DseDriverOption.GRAPH_READ_CONSISTENCY_LEVEL, null);
Mockito.verify(executionProfile, never()).getString(DseDriverOption.GRAPH_WRITE_CONSISTENCY_LEVEL, null);
assertThat(requestPayload.get(GraphConversions.GRAPH_SOURCE_OPTION_KEY)).isEqualTo(TEXT.encode("a", harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_RESULTS_OPTION_KEY)).isEqualTo(TEXT.encode(subProtocol.toInternalCode(), harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_NAME_OPTION_KEY)).isEqualTo(TEXT.encode("mockGraph", harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_LANG_OPTION_KEY)).isEqualTo(TEXT.encode("gremlin-groovy", harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_TIMEOUT_OPTION_KEY)).isEqualTo(BIGINT.encode(2L, harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_READ_CONSISTENCY_LEVEL_OPTION_KEY)).isEqualTo(TEXT.encode("TWO", harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_WRITE_CONSISTENCY_LEVEL_OPTION_KEY)).isEqualTo(TEXT.encode("THREE", harness.getContext().getProtocolVersion()));
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile 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);
}
Aggregations