use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile 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.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class GraphRequestHandlerTest method should_create_payload_from_config_options.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_create_payload_from_config_options(GraphProtocol subProtocol) {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery").setExecutionProfileName("test-graph");
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).getString(DseDriverOption.GRAPH_TRAVERSAL_SOURCE, null);
Mockito.verify(executionProfile).getString(DseDriverOption.GRAPH_NAME, null);
Mockito.verify(executionProfile).getBoolean(DseDriverOption.GRAPH_IS_SYSTEM_QUERY, false);
Mockito.verify(executionProfile).getDuration(DseDriverOption.GRAPH_TIMEOUT, Duration.ZERO);
Mockito.verify(executionProfile).getString(DseDriverOption.GRAPH_READ_CONSISTENCY_LEVEL, null);
Mockito.verify(executionProfile).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("LOCAL_TWO", harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_WRITE_CONSISTENCY_LEVEL_OPTION_KEY)).isEqualTo(TEXT.encode("LOCAL_THREE", harness.getContext().getProtocolVersion()));
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class ContinuousGraphRequestHandlerTest method should_honor_default_timeout.
@Test
public void should_honor_default_timeout() throws Exception {
// given
GraphBinaryModule binaryModule = createGraphBinaryModule(mockContext);
Duration defaultTimeout = Duration.ofSeconds(1);
RequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withGraphTimeout(defaultTimeout);
PoolBehavior node1Behavior = builder.customBehavior(node);
try (RequestHandlerTestHarness harness = builder.build()) {
DriverExecutionProfile profile = harness.getContext().getConfig().getDefaultProfile();
when(profile.isDefined(DseDriverOption.GRAPH_SUB_PROTOCOL)).thenReturn(true);
when(profile.getString(DseDriverOption.GRAPH_SUB_PROTOCOL)).thenReturn(GraphProtocol.GRAPH_BINARY_1_0.toInternalCode());
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery");
// when
ContinuousGraphRequestHandler handler = new ContinuousGraphRequestHandler(graphStatement, harness.getSession(), harness.getContext(), "test", binaryModule, new GraphSupportChecker());
// send the initial request
CompletionStage<AsyncGraphResultSet> page1Future = handler.handle();
// acknowledge the write, will set the global timeout
node1Behavior.verifyWrite();
node1Behavior.setWriteSuccess();
CapturedTimeout globalTimeout = harness.nextScheduledTimeout();
assertThat(globalTimeout.getDelay(TimeUnit.NANOSECONDS)).isEqualTo(defaultTimeout.toNanos());
// will trigger the global timeout and complete it exceptionally
globalTimeout.task().run(globalTimeout);
assertThat(page1Future.toCompletableFuture()).isCompletedExceptionally();
assertThatThrownBy(() -> page1Future.toCompletableFuture().get()).hasRootCauseExactlyInstanceOf(DriverTimeoutException.class).hasMessageContaining("Query timed out after " + defaultTimeout);
}
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class MicroProfileNodeMetricsUpdaterTest method should_not_log_warning_when_provided_eviction_time_setting_is_acceptable.
@Test
@UseDataProvider(value = "acceptableEvictionTimes")
public void should_not_log_warning_when_provided_eviction_time_setting_is_acceptable(Duration expireAfter) {
// given
LoggerTest.LoggerSetup logger = LoggerTest.setupTestLogger(AbstractMetricUpdater.class, Level.WARN);
Node node = mock(Node.class);
InternalDriverContext context = mock(InternalDriverContext.class);
DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
DriverConfig config = mock(DriverConfig.class);
Set<NodeMetric> enabledMetrics = Collections.singleton(DefaultNodeMetric.CQL_MESSAGES);
// when
when(context.getSessionName()).thenReturn("prefix");
when(context.getConfig()).thenReturn(config);
when(config.getDefaultProfile()).thenReturn(profile);
when(profile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(expireAfter);
MicroProfileNodeMetricUpdater updater = new MicroProfileNodeMetricUpdater(node, context, enabledMetrics, new MetricsRegistryImpl()) {
@Override
protected void initializeGauge(NodeMetric metric, DriverExecutionProfile profile, Gauge<Number> supplier) {
// do nothing
}
@Override
protected void initializeCounter(NodeMetric metric, DriverExecutionProfile profile) {
// do nothing
}
@Override
protected void initializeTimer(NodeMetric metric, DriverExecutionProfile profile) {
// do nothing
}
};
// then
assertThat(updater.getExpireAfter()).isEqualTo(expireAfter);
verify(logger.appender, timeout(500).times(0)).doAppend(logger.loggingEventCaptor.capture());
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class MicroProfileNodeMetricsUpdaterTest method should_log_warning_when_provided_eviction_time_setting_is_too_low.
@Test
public void should_log_warning_when_provided_eviction_time_setting_is_too_low() {
// given
LoggerTest.LoggerSetup logger = LoggerTest.setupTestLogger(AbstractMetricUpdater.class, Level.WARN);
Node node = mock(Node.class);
InternalDriverContext context = mock(InternalDriverContext.class);
DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
DriverConfig config = mock(DriverConfig.class);
Set<NodeMetric> enabledMetrics = Collections.singleton(DefaultNodeMetric.CQL_MESSAGES);
Duration expireAfter = AbstractMetricUpdater.MIN_EXPIRE_AFTER.minusMinutes(1);
// when
when(context.getSessionName()).thenReturn("prefix");
when(context.getConfig()).thenReturn(config);
when(config.getDefaultProfile()).thenReturn(profile);
when(profile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(expireAfter);
MicroProfileNodeMetricUpdater updater = new MicroProfileNodeMetricUpdater(node, context, enabledMetrics, new MetricsRegistryImpl()) {
@Override
protected void initializeGauge(NodeMetric metric, DriverExecutionProfile profile, Gauge<Number> supplier) {
// do nothing
}
@Override
protected void initializeCounter(NodeMetric metric, DriverExecutionProfile profile) {
// do nothing
}
@Override
protected void initializeTimer(NodeMetric metric, DriverExecutionProfile profile) {
// do nothing
}
};
// then
assertThat(updater.getExpireAfter()).isEqualTo(AbstractMetricUpdater.MIN_EXPIRE_AFTER);
verify(logger.appender, timeout(500).times(1)).doAppend(logger.loggingEventCaptor.capture());
assertThat(logger.loggingEventCaptor.getValue().getMessage()).isNotNull();
assertThat(logger.loggingEventCaptor.getValue().getFormattedMessage()).contains(String.format("[prefix] Value too low for %s: %s. Forcing to %s instead.", DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER.getPath(), expireAfter, AbstractMetricUpdater.MIN_EXPIRE_AFTER));
}
Aggregations