Skip to content

Commit

Permalink
fixed integration tests according to changes on server side
Browse files Browse the repository at this point in the history
 - default nullability in tests
 - table type "BASE TABLE"
 - test that was broken by previous fix that avoids checking whether DB exists for local connection
 - float is now alias to double
 - use query_label request parameter
 - avoid using checksum() function that is not supported in new version for timeout test
 - additional tests for infra version
  • Loading branch information
alexradzin committed Apr 3, 2024
1 parent 33baf35 commit 6a18f91
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@

public abstract class MockWebServerAwareIntegrationTest extends IntegrationTest {
protected MockWebServer mockBackEnd;
private final int INIT_STATEMENTS_COUNT = 1; // The statement that validates that DB exists.

@BeforeEach
void setUp() throws IOException {
mockBackEnd = new MockWebServer();
mockBackEnd.start();
mockBackEnd.enqueue(new MockResponse().setResponseCode(200).setBody(format("database_name%nstring%n%s", System.getProperty("db"))));
}

@AfterEach
Expand All @@ -28,6 +26,6 @@ void tearDown() throws IOException {


protected void assertMockBackendRequestsCount(int expected) {
assertEquals(INIT_STATEMENTS_COUNT + expected, mockBackEnd.getRequestCount());
assertEquals(expected, mockBackEnd.getRequestCount());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package integration.tests;

import integration.ConnectionInfo;
import integration.InfraVersion;
import integration.IntegrationTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
Expand Down Expand Up @@ -63,12 +64,12 @@

class DatabaseMetaDataTest extends IntegrationTest {

@BeforeEach
@BeforeAll
void beforeAll() {
executeStatementFromFile("/statements/metadata/ddl.sql");
}

@AfterEach
@AfterAll
void afterEach() {
executeStatementFromFile("/statements/metadata/cleanup.sql");
}
Expand Down Expand Up @@ -121,11 +122,11 @@ void shouldReturnTable() throws SQLException {
@ParameterizedTest
@CsvSource({
// table types
",,,,tables;query_history;integration_test,",
",,,TABLE;VIEW,tables;query_history;integration_test,",
",,,VIEW;TABLE,integration_test;tables;query_history,",
",,,TABLE,integration_test,query_history;tables",
",,,VIEW,query_history;tables,integration_test",
",,,,tables;databases;integration_test,",
",,,TABLE;VIEW,tables;databases;integration_test,",
",,,VIEW;TABLE,integration_test;tables;databases,",
",,,TABLE,integration_test,databases;tables",
",,,VIEW,databases;tables,integration_test",

// table name pattern
",,%account%,,service_account_users;service_accounts,tables;columns;databases",
Expand All @@ -135,12 +136,17 @@ void shouldReturnTable() throws SQLException {
",public,,,integration_test,tables;columns;databases",
",information_schema,,,tables;columns,integration_test",

// They say that catalog schema is deprecated and will be removed. In this case this test will fail and should be changed or removed
",catalog,,,query_history,users;views;integration_test",
// schema name pattern and table types
",public,,TABLE,integration_test,tables;columns;databases",
",public,,TABLE;VIEW,integration_test,tables;columns;databases",
",public,,VIEW,,tables;columns;databases",
",information_schema,,TABLE,,integration_test",
",information_schema,,TABLE;VIEW,tables;columns,integration_test",
",information_schema,,VIEW,tables;columns,",
})
void getTables(String catalog, String schemaPattern, String tableNamePattern, String typesStr, String expectedNamesStr, String unexpectedNamesStr) throws SQLException {
String[] types = typesStr == null ? null : typesStr.split(";");
Collection<String> expectedNames = Set.of(expectedNamesStr.split(";"));
Collection<String> expectedNames = expectedNamesStr == null ? Set.of() : Set.of(expectedNamesStr.split(";"));
Collection<String> unexpectedNames = unexpectedNamesStr == null ? Set.of() : Set.of(unexpectedNamesStr.split(";"));
List<String> names = new ArrayList<>();
try (Connection connection = createConnection();
Expand All @@ -155,7 +161,18 @@ void getTables(String catalog, String schemaPattern, String tableNamePattern, St
}

@Test
void shouldReturnColumns() throws SQLException {
@InfraVersion(value = 2, comparison = InfraVersion.Comparison.LT)
void shouldReturnColumnsV1() throws SQLException {
shouldReturnColumns(false);
}

@Test
@InfraVersion(value = 2, comparison = InfraVersion.Comparison.GE)
void shouldReturnColumnsEngineV2() throws SQLException {
shouldReturnColumns(true);
}

private void shouldReturnColumns(boolean nullableByDefault) throws SQLException {
Map<String, List<String>> result = new HashMap<>();
try (Connection connection = createConnection();
ResultSet rs = connection.getMetaData().getColumns(connection.getCatalog(), "public", "integration_test", null)) {
Expand All @@ -170,7 +187,7 @@ void shouldReturnColumns() throws SQLException {
String tableName = "integration_test";
String schemaName = "public";
assertThat(result.get(SCOPE_TABLE), contains(null, null, null, null, null, null, null));
assertThat(result.get(IS_NULLABLE), contains("NO", "YES", "YES", "YES", "YES", "YES", "NO"));
assertThat(result.get(IS_NULLABLE), contains("NO", "YES", "YES", "YES", "YES", nullableByDefault ? "YES" : "NO", "NO"));
assertThat(result.get(BUFFER_LENGTH), contains(null, null, null, null, null, null, null));
assertThat(result.get(TABLE_CAT), contains(database, database, database, database, database, database, database));
assertThat(result.get(SCOPE_CATALOG), contains(null, null, null, null, null, null, null));
Expand All @@ -179,7 +196,7 @@ void shouldReturnColumns() throws SQLException {
assertThat(result.get(COLUMN_NAME), contains("id", "ts", "tstz", "tsntz", "content", "success", "year"));
assertThat(result.get(TABLE_SCHEM), contains(schemaName, schemaName, schemaName, schemaName, schemaName, schemaName, schemaName));
assertThat(result.get(REMARKS), contains(null, null, null, null, null, null, null));
assertThat(result.get(NULLABLE), contains("0", "1", "1", "1", "1", "1", "0"));
assertThat(result.get(NULLABLE), contains("0", "1", "1", "1", "1", nullableByDefault ? "1" : "0", "0"));
assertThat(result.get(DECIMAL_DIGITS), contains("0", "0", "0", "0", "0", "0", "0"));
assertThat(result.get(SQL_DATETIME_SUB), contains(null, null, null, null, null, null, null));
assertThat(result.get(NUM_PREC_RADIX), contains("10", "10", "10", "10", "10", "10", "10"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class NullableValuesTest extends IntegrationTest {
@BeforeEach
void beforeAll() {
void beforeEach() {
executeStatementFromFile("/statements/nullable-types/ddl.sql");
}

Expand Down
61 changes: 61 additions & 0 deletions src/integrationTest/java/integration/tests/SpecialValuesTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package integration.tests;

import integration.InfraVersion;
import integration.IntegrationTest;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -32,10 +33,30 @@ void afterAll() throws SQLException {

@ParameterizedTest
@ValueSource(strings = {"select 'inf'::float", "select '+inf'::float"})
@InfraVersion(value = 2, comparison = InfraVersion.Comparison.LT)
void infFloatUserEngine(String query) throws SQLException {
specialSelect(userConnection, query, Float.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
}

@ParameterizedTest
@ValueSource(strings = {"select 'inf'::real", "select '+inf'::real"})
void infRealUserEngine(String query) throws SQLException {
specialSelect(userConnection, query, Float.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
}

@ParameterizedTest
@ValueSource(strings = {"select 'inf'::real", "select '+inf'::real"})
void infRealSystemEngine(String query) throws SQLException {
specialSelect(userConnection, query, Float.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
}

@ParameterizedTest
@ValueSource(strings = {"select 'inf'::float", "select '+inf'::float"})
@InfraVersion(value = 2, comparison = InfraVersion.Comparison.GE)
void infFloatAsDoubleUserEngine(String query) throws SQLException {
specialSelect(userConnection, query, Float.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
}

@ParameterizedTest
@ValueSource(strings = {"select 'inf'::float", "select '+inf'::float", "select 'inf'::double", "select '+inf'::double"})
void infSystemEngine(String query) throws SQLException {
Expand All @@ -51,10 +72,30 @@ void infDoubleUserEngine(String query) throws SQLException {

@ParameterizedTest
@ValueSource(strings = {"select '-inf'::float"})
@InfraVersion(value = 2, comparison = InfraVersion.Comparison.LT)
void minusInfFloatUserEngine(String query) throws SQLException {
specialSelect(userConnection, query, Float.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
}

@ParameterizedTest
@ValueSource(strings = {"select '-inf'::float"})
@InfraVersion(value = 2, comparison = InfraVersion.Comparison.GE)
void minusInfFloatAsDoubleUserEngine(String query) throws SQLException {
specialSelect(userConnection, query, Float.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
}

@ParameterizedTest
@ValueSource(strings = {"select '-inf'::real"})
void minusInfRealUserEngine(String query) throws SQLException {
specialSelect(userConnection, query, Float.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
}

@ParameterizedTest
@ValueSource(strings = {"select '-inf'::real"})
void minusInfRealSystemEngine(String query) throws SQLException {
specialSelect(systemConnection, query, Float.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
}

@ParameterizedTest
@ValueSource(strings = {"select '-inf'::float"})
void minusInfSystemEngine(String query) throws SQLException {
Expand All @@ -70,10 +111,30 @@ void minusInfDoubleUserEngine(String query) throws SQLException {

@ParameterizedTest
@ValueSource(strings = {"select 'nan'::float", "select '+nan'::float", "select '-nan'::float"})
@InfraVersion(value = 2, comparison = InfraVersion.Comparison.LT)
void nanFloatUserEngine(String query) throws SQLException {
specialSelect(userConnection, query, Float.NaN, Double.NaN, Float.NaN);
}

@ParameterizedTest
@ValueSource(strings = {"select 'nan'::real", "select '+nan'::real", "select '-nan'::real"})
void nanRealUserEngine(String query) throws SQLException {
specialSelect(userConnection, query, Float.NaN, Double.NaN, Float.NaN);
}

@ParameterizedTest
@ValueSource(strings = {"select 'nan'::real", "select '+nan'::real", "select '-nan'::real"})
void nanRealSystemEngine(String query) throws SQLException {
specialSelect(systemConnection, query, Float.NaN, Double.NaN, Float.NaN);
}

@ParameterizedTest
@ValueSource(strings = {"select 'nan'::float", "select '+nan'::float", "select '-nan'::float"})
@InfraVersion(value = 2, comparison = InfraVersion.Comparison.GE)
void nanFloatAsDoubleUserEngine(String query) throws SQLException {
specialSelect(userConnection, query, Float.NaN, Double.NaN, Double.NaN);
}

@ParameterizedTest
@ValueSource(strings = {
"select 'nan'::float", "select '+nan'::float", "select '-nan'::float",
Expand Down
4 changes: 2 additions & 2 deletions src/integrationTest/java/integration/tests/TimeoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@CustomLog
class TimeoutTest extends IntegrationTest {
private static final int MIN_TIME_SECONDS = 350;
private static final Map<Integer, Long> SERIES_SIZE = Map.of(1, 300000000000L, 2, 500000000000L);
private static final Map<Integer, Long> SERIES_SIZE = Map.of(1, 50000000000L, 2, 180000000000L);
private long startTime;

@BeforeEach
Expand All @@ -43,7 +43,7 @@ void after() {
void shouldExecuteRequestWithoutTimeout() throws SQLException {
try (Connection con = createConnection(); Statement stmt = con.createStatement()) {
int infraVersion = ((FireboltConnection)con).getInfraVersion();
stmt.executeQuery(format("SELECT checksum(*) FROM generate_series(1, %d)", SERIES_SIZE.get(infraVersion)));
stmt.executeQuery(format("SELECT (max(x) - min(x))/count(x) + avg(x) FROM generate_series(1,%d) r(x)", SERIES_SIZE.get(infraVersion)));
}
}
}
6 changes: 3 additions & 3 deletions src/integrationTest/resources/statements/metadata/ddl.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
DROP TABLE IF EXISTS "integration_test" CASCADE;
CREATE
FACT TABLE IF NOT EXISTS "integration_test" (
id BIGINT,
id BIGINT NOT NULL,
ts timestamp NULL,
tstz timestamptz NULL,
tsntz timestampntz NULL,
content text NULL,
success BOOLEAN NULL,
year int
success BOOLEAN,
year int NOT NULL
)
primary index id
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
DROP TABLE IF EXISTS prepared_statement_test;
CREATE
FACT TABLE IF NOT EXISTS prepared_statement_test (
make STRING,
sales bigint,
make STRING not null,
sales bigint not null,
signature bytea null
)
PRIMARY INDEX make;
Loading

0 comments on commit 6a18f91

Please sign in to comment.