Skip to content

Commit

Permalink
fixed broken unit tests
Browse files Browse the repository at this point in the history
 - use select version()
  • Loading branch information
alexradzin committed Apr 4, 2024
1 parent f372a7d commit bf6c107
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public class FireboltDatabaseMetadata implements DatabaseMetaData {

private final String url;
private final FireboltConnection connection;
private String databaseVersion;
private volatile String databaseVersion;

public FireboltDatabaseMetadata(String url, FireboltConnection connection) {
this.url = url;
Expand Down Expand Up @@ -403,7 +403,7 @@ public int getDriverMinorVersion() {
@Override
public String getDatabaseProductVersion() throws SQLException {
if (databaseVersion == null) {
try (Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery("select version()")) {
try (Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery("SELECT VERSION()")) {
databaseVersion = rs.next() ? rs.getString(1) : "";
}
}
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/com/firebolt/jdbc/metadata/MetadataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

Expand Down Expand Up @@ -59,12 +58,6 @@ public String getTablesQuery(@SuppressWarnings("java:S1172") String catalog, Str
return queryBuilder.conditions(conditions).orderBy("table_schema, table_name").build().toSql();
}

public static String getDatabaseVersionQuery(String engine) {
return Query.builder().select("version").from("information_schema.engines")
.conditions(Collections.singletonList(format("engine_name iLIKE '%s%%'", engine))).build()
.toSql();
}

/**
* Represents a SQL query that can be sent to Firebolt to receive metadata info
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,32 +367,26 @@ void shouldGetJdbcManorVersion() throws SQLException {

@Test
void shouldGetDatabaseProductVersion() throws SQLException {
Statement statement = mock(FireboltStatement.class);
when(fireboltConnection.createStatement()).thenReturn(statement);
when(fireboltConnection.getEngine()).thenReturn("test");
when(statement.executeQuery("SELECT version FROM information_schema.engines WHERE engine_name iLIKE 'test%'"))
.thenReturn(new FireboltResultSet(getInputStreamForGetVersion()));
mockGetDatabaseVersion();
assertEquals("abcd_xxx_123", fireboltDatabaseMetadata.getDatabaseProductVersion());
}

@Test
void shouldGetDatabaseMajorVersion() throws SQLException {
Statement statement = mock(FireboltStatement.class);
when(fireboltConnection.createStatement()).thenReturn(statement);
when(fireboltConnection.getEngine()).thenReturn("test");
when(statement.executeQuery("SELECT version FROM information_schema.engines WHERE engine_name iLIKE 'test%'"))
.thenReturn(new FireboltResultSet(getInputStreamForGetVersion()));
mockGetDatabaseVersion();
assertEquals(0, fireboltDatabaseMetadata.getDatabaseMajorVersion());
}

@Test
void shouldGetDatabaseMinorVersion() throws SQLException {
mockGetDatabaseVersion();
assertEquals(0, fireboltDatabaseMetadata.getDatabaseMinorVersion());
}

private void mockGetDatabaseVersion() throws SQLException {
Statement statement = mock(FireboltStatement.class);
when(fireboltConnection.createStatement()).thenReturn(statement);
when(fireboltConnection.getEngine()).thenReturn("test");
when(statement.executeQuery("SELECT version FROM information_schema.engines WHERE engine_name iLIKE 'test%'"))
.thenReturn(new FireboltResultSet(getInputStreamForGetVersion()));
assertEquals(0, fireboltDatabaseMetadata.getDatabaseMinorVersion());
when(statement.executeQuery("SELECT VERSION()")).thenReturn(new FireboltResultSet(getInputStreamForGetVersion()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,4 @@ void shouldGetColumnsQueryWhenGettingQueryWithoutArguments() {
"SELECT table_schema, table_name, column_name, data_type, column_default, is_nullable, ordinal_position FROM information_schema.columns",
MetadataUtil.getColumnsQuery(null, null, null));
}

@Test
void shouldGetVersionQuery() {
assertEquals("SELECT version FROM information_schema.engines WHERE engine_name iLIKE 'test%'",
MetadataUtil.getDatabaseVersionQuery("test"));
}
}

0 comments on commit bf6c107

Please sign in to comment.