Search in sources :

Example 1 with ServerError

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);
}
Also used : ServerError(com.datastax.oss.driver.api.core.servererrors.ServerError) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Example 2 with ServerError

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"));
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) ServerError(com.datastax.oss.driver.api.core.servererrors.ServerError) Before(org.junit.Before)

Example 3 with ServerError

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);
    }
}
Also used : ServerError(com.datastax.oss.driver.api.core.servererrors.ServerError) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 4 with ServerError

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());
}
Also used : ServerError(com.datastax.oss.driver.api.core.servererrors.ServerError) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Example 5 with ServerError

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();
}
Also used : ServerError(com.datastax.oss.driver.api.core.servererrors.ServerError) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Aggregations

ServerError (com.datastax.oss.driver.api.core.servererrors.ServerError)5 Test (org.junit.Test)4 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)3 CqlSession (com.datastax.oss.driver.api.core.CqlSession)1 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1 Before (org.junit.Before)1