Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 63 additions & 14 deletions src/integrationTest/java/integration/tests/StatementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@

import com.firebolt.jdbc.connection.FireboltConnection;
import com.firebolt.jdbc.exception.FireboltException;
import com.firebolt.jdbc.testutils.TestTag;
import integration.ConnectionInfo;
import integration.EnvironmentCondition;
import integration.IntegrationTest;
import kotlin.collections.ArrayDeque;
import lombok.CustomLog;
import org.apache.commons.lang3.RandomStringUtils;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
Expand All @@ -31,9 +19,20 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
import kotlin.collections.ArrayDeque;
import lombok.CustomLog;
import org.apache.commons.lang3.RandomStringUtils;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

import static integration.EnvironmentCondition.Attribute.databaseVersion;
import static integration.EnvironmentCondition.Attribute.fireboltVersion;
import static java.lang.String.format;
import static java.sql.Statement.SUCCESS_NO_INFO;
import static java.util.stream.Collectors.joining;
Expand Down Expand Up @@ -558,6 +557,56 @@ void unlimitedMaxFieldSize(int maxFieldSize) throws SQLException {
}
}

@Test
@Tag(TestTag.V2)
@EnvironmentCondition(value = "4.16.0", attribute = databaseVersion, comparison = EnvironmentCondition.Comparison.GE)
void canUseStatementTimeout() throws SQLException {
try (Connection connection = createConnection(); Statement statement = connection.createStatement()) {
statement.execute("set statement_timeout=1");
ResultSet resultSet = statement.executeQuery("SELECT * FROM GENERATE_SERIES(1, 10000000);");
boolean errorFound = false;
while (resultSet.next()) {
String object = resultSet.getString(1);
if (object.contains("Query was canceled with reason 'Query timeout expired (1 ms)")) {
errorFound = true;
}
}
assertTrue(errorFound, "Did not find the error for query timing out");
}
}

@Test
@Tag(TestTag.V2)
@EnvironmentCondition(value = "4.16.0", attribute = databaseVersion, comparison = EnvironmentCondition.Comparison.GE)
void canUseStatementQueryTimeout() throws SQLException {
try (Connection connection = createConnection(); Statement statement = connection.createStatement()) {
statement.setQueryTimeout(1);
ResultSet resultSet = statement.executeQuery("SELECT * FROM GENERATE_SERIES(1, 10000000);");
boolean errorFound = false;
while (resultSet.next()) {
String object = resultSet.getString(1);
if (object.contains("Query was canceled with reason 'Query timeout expired (1 ms)")) {
errorFound = true;
}
}
Comment on lines +583 to +591
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're meant to raise a Timeout exception here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a bit tricky. The spec mentions that a timeout exception should be thrown.
But I think that would be the case if the server did not start sending any response (for example, compute a complex join query). In this case, the server starts sending some response.
That's why I was asking in the Jira what is the expected behavior since the driver did not throw any exception even before with max_execution_time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think max_execution_time was never actually working on 2.0, it was ported from 1.0. Actually, just checked and it doesn't do anything on 1.0 right now either, so we shouldn't rely on the past behavior here.
Server side is separate and, as mentioned in the ticket, doesn't seem to be working correctly. However, we're concerned with the client-side behavior here and the expectation is that we throw an exception. If we can't do that with the server-side parameter then we would have to implement timeout on the client side and abort the connection when timeout is reached.

assertTrue(errorFound, "Did not find the error for query timing out");
}
}

@Test
@Tag(TestTag.V2)
@EnvironmentCondition(value = "4.16.0", attribute = databaseVersion, comparison = EnvironmentCondition.Comparison.GE)
void canExecuteStatementWithoutTimeout() throws SQLException {
try (Connection connection = createConnection(); Statement statement = connection.createStatement()) {
ResultSet resultSet = statement.executeQuery("SELECT * FROM GENERATE_SERIES(1, 10000000);");
int lastNumberReturned = 0;
while (resultSet.next()) {
lastNumberReturned++;
}
assertEquals(1000000, lastNumberReturned);
}
}

private Collection<String> readValues(Statement statement, String query, int columnIndex) throws SQLException {
List<String> values = new ArrayList<>();
try (ResultSet rs = statement.executeQuery(query)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private Map<String, String> getAllParameters(FireboltProperties fireboltProperti
params.put(FireboltQueryParameterKey.COMPRESS.getKey(), fireboltProperties.isCompress() ? "1" : "0");

if (queryTimeout > 0) {
params.put("max_execution_time", String.valueOf(queryTimeout));
params.put("statement_timeout", String.valueOf(queryTimeout));
}
}
params.put(FireboltQueryParameterKey.DATABASE.getKey(), fireboltProperties.getDatabase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class StatementClientImplTest {

@ParameterizedTest
@CsvSource({
"false,http://firebolt1:555/?database=db1&output_format=TabSeparatedWithNamesAndTypes&compress=1&max_execution_time=15",
"false,http://firebolt1:555/?database=db1&output_format=TabSeparatedWithNamesAndTypes&compress=1&statement_timeout=15",
"true,http://firebolt1:555/?database=db1&account_id=12345&output_format=TabSeparatedWithNamesAndTypes"
})
void shouldPostSqlQueryWithExpectedUrl(boolean systemEngine, String expectedUrl) throws SQLException, IOException {
Expand Down
Loading