Skip to content

Commit

Permalink
Improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Oct 18, 2023
1 parent 8886985 commit a2b045a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion error_code_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ error-tags:
- com.exasol.support
- com.exasol.clusterlogs
- com.exasol.bucketfs.testcontainers
highest-index: 23
highest-index: 24
10 changes: 5 additions & 5 deletions src/main/java/com/exasol/containers/ExasolContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ private void waitUntilStatementCanBeExecuted() {
+ " after {{after}} seconds. Last connection exception was: {{exception}}")
.parameter("url", getJdbcUrl(), "JDBC URL of the connection to the Exasol Testcontainer")
.parameter("query", getTestQueryString(), "Query used to test the connection")
.parameter("after", timeoutAfter.toSeconds() + "." + timeoutAfter.toSecondsPart())
.parameter("after", timeoutAfter.toSeconds())
.parameter("exception",
(this.lastConnectionException == null) ? "none" : this.lastConnectionException.getMessage(),
"exception thrown on last connection attempt")
Expand All @@ -741,9 +741,9 @@ private boolean isConnectionAvailable() {
throw new ContainerLaunchException("Startup check query failed. Exasol container start-up failed.");
}
} catch (final NoDriverFoundException exception) {
throw new ContainerLaunchException(
"Unable to determine start status of container, because the referenced JDBC driver was not found.",
exception);
throw new ContainerLaunchException(ExaError.messageBuilder("E-ETC-24").message(
"Unable to determine start status of container, because the referenced JDBC driver was not found: {{cause}}",
exception.getMessage()).toString(), exception);
} catch (final SQLException exception) {
this.lastConnectionException = exception;
sleepBeforeNextConnectionAttempt();
Expand Down Expand Up @@ -1067,4 +1067,4 @@ public ExecResult probeFile(final String path) {
throw new SshException("Probing file " + path + "was interrupted", interruptedException);
}
}
}
}
27 changes: 19 additions & 8 deletions src/test/java/com/exasol/containers/ExasolContainerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.sql.SQLException;
import java.time.Duration;

import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.function.Executable;
Expand All @@ -36,8 +38,9 @@ class ExasolContainerTest {

@BeforeEach
void beforeEach() throws NoDriverFoundException {
final ExasolContainer<?> container = new ExasolContainer<>();
final ExasolContainer<? extends ExasolContainer<?>> container = new ExasolContainer<>();
container.withRequiredServices();
container.withJdbcConnectionTimeout(10);
this.containerSpy = spy(container);
}

Expand All @@ -48,20 +51,28 @@ void testWaitUntilContainerStartedTimesOut() throws Exception {
doNothing().when(this.containerSpy).waitUntilClusterConfigurationAvailable();
doReturn(this.connectionMock).when(this.containerSpy).createConnection(any());
when(this.connectionMock.createStatement()).thenThrow(new SQLException("Mock Exception"));
assertThrowsLaunchException("timed out", () -> this.containerSpy.waitUntilContainerStarted());
assertThrowsLaunchException(
allOf(Matchers
.startsWith("F-ETC-5: Exasol container start-up timed out trying connection to 'jdbc:exa:"),
Matchers.endsWith("Last connection exception was: 'Mock Exception'")),
() -> this.containerSpy.waitUntilContainerStarted());
}

private void assertThrowsLaunchException(final String expectedMessageFragment, final Executable executable) {
private void assertThrowsLaunchException(final Matcher<String> expectedMessage, final Executable executable) {
final ContainerLaunchException exception = assertThrows(ContainerLaunchException.class, executable);
assertThat(exception.getMessage(), containsString(expectedMessageFragment));
assertThat(exception.getMessage(), expectedMessage);
}

@Test
void testWaitUntilContainerStartedThrowsExceptionOnMissingJdbcDriver() throws NoDriverFoundException, SQLException {
doNothing().when(this.containerSpy).waitUntilClusterConfigurationAvailable();
Mockito.doThrow(new NoDriverFoundException("Mock Driver-Not-Found Exception", new Exception("Mock cause")))
.when(this.containerSpy).createConnection(anyString());
assertThrowsLaunchException("driver was not found", () -> this.containerSpy.waitUntilContainerStarted());
final String message = "Mock Driver-Not-Found Exception";
Mockito.doThrow(new NoDriverFoundException(message, new Exception("Mock cause"))).when(this.containerSpy)
.createConnection(anyString());
assertThrowsLaunchException(equalTo(
"E-ETC-24: Unable to determine start status of container, because the referenced JDBC driver was not found: '"
+ message + "'"),
() -> this.containerSpy.waitUntilContainerStarted());
}

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -182,4 +193,4 @@ void sessionBuilder() {
assertThat(session.getPort(), equalTo(321));
assertThat(session.getUserName(), equalTo(SSH_USER));
}
}
}

0 comments on commit a2b045a

Please sign in to comment.