use of com.datastax.oss.driver.api.core.servererrors.ServerError in project java-driver by datastax.
the class RequestLoggerIT method should_log_failed_request_with_stack_trace_with_defaults.
@Test
public void should_log_failed_request_with_stack_trace_with_defaults() {
// Given
simulacronRule.cluster().prime(when(QUERY).then(serverError("test")));
// When
try {
sessionRuleDefaults.session().execute(QUERY);
fail("Expected a ServerError");
} catch (ServerError error) {
// expected
}
// Then
verify(appender, timeout(5000)).doAppend(loggingEventCaptor.capture());
ILoggingEvent log = loggingEventCaptor.getValue();
assertThat(log.getFormattedMessage()).contains("Error", "[0 values]", QUERY, ServerError.class.getName()).matches(WITH_PER_REQUEST_PREFIX);
}
use of com.datastax.oss.driver.api.core.servererrors.ServerError in project java-driver by datastax.
the class GraphExecutionInfoConverterTest method setUp.
@Before
public void setUp() {
errors = Collections.singletonList(new SimpleEntry<>(node, new ServerError(node, "this is a server error")));
warnings = Collections.singletonList("this is a warning");
payload = ImmutableMap.of("key", Bytes.fromHexString("0xcafebabe"));
}
use of com.datastax.oss.driver.api.core.servererrors.ServerError in project java-driver by datastax.
the class DriverExecutionProfileSimulacronIT method should_use_profile_default_idempotence.
@Test
public void should_use_profile_default_idempotence() {
DriverConfigLoader loader = SessionUtils.configLoaderBuilder().startProfile("idem").withBoolean(DefaultDriverOption.REQUEST_DEFAULT_IDEMPOTENCE, true).build();
try (CqlSession session = SessionUtils.newSession(SIMULACRON_RULE, loader)) {
String query = "mockquery";
// configure query with server error which should invoke onRequestError in retry policy.
SIMULACRON_RULE.cluster().prime(when(query).then(serverError("fail")));
// Execute query without profile, should fail because couldn't be retried.
try {
session.execute(query);
fail("Should have failed with server error");
} catch (ServerError e) {
// expected.
}
// Execute query with profile, should retry on all hosts since query is idempotent.
Throwable t = catchThrowable(() -> session.execute(SimpleStatement.builder(query).setExecutionProfileName("idem").build()));
assertThat(t).isInstanceOf(AllNodesFailedException.class);
}
}
use of com.datastax.oss.driver.api.core.servererrors.ServerError in project java-driver by datastax.
the class RequestLoggerIT method should_log_failed_request_with_stack_trace.
@Test
public void should_log_failed_request_with_stack_trace() {
// Given
simulacronRule.cluster().prime(when(QUERY).then(serverError("test")));
// When
try {
sessionRuleRequest.session().execute(QUERY);
fail("Expected a ServerError");
} catch (ServerError error) {
// expected
}
// Then
verify(appender, timeout(5000)).doAppend(loggingEventCaptor.capture());
ILoggingEvent log = loggingEventCaptor.getValue();
assertThat(log.getFormattedMessage()).contains("Error", "[0 values]", QUERY).doesNotContain(ServerError.class.getName()).matches(WITH_PER_REQUEST_PREFIX);
assertThat(log.getThrowableProxy().getClassName()).isEqualTo(ServerError.class.getName());
}
use of com.datastax.oss.driver.api.core.servererrors.ServerError in project java-driver by datastax.
the class RequestLoggerIT method should_log_failed_request_without_stack_trace.
@Test
public void should_log_failed_request_without_stack_trace() {
// Given
simulacronRule.cluster().prime(when(QUERY).then(serverError("test")));
// When
try {
sessionRuleRequest.session().execute(SimpleStatement.builder(QUERY).setExecutionProfileName("no-traces").build());
fail("Expected a ServerError");
} catch (ServerError error) {
// expected
}
// Then
verify(appender, timeout(5000)).doAppend(loggingEventCaptor.capture());
ILoggingEvent log = loggingEventCaptor.getValue();
assertThat(log.getFormattedMessage()).contains("Error", "[0 values]", QUERY, ServerError.class.getName()).matches(WITH_PER_REQUEST_PREFIX);
assertThat(log.getThrowableProxy()).isNull();
}
Aggregations