Skip to content

Commit

Permalink
driver that can connect to both versions 1 and 2
Browse files Browse the repository at this point in the history
  • Loading branch information
alexradzin committed Nov 2, 2023
1 parent 4c1108b commit 54823cf
Show file tree
Hide file tree
Showing 41 changed files with 1,451 additions and 385 deletions.
69 changes: 49 additions & 20 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ name: Run integration tests
on:
workflow_dispatch:
inputs:
database:
description: 'Database - a new one will be created if not provided'
database1:
description: 'Database (v1) - a new one will be created if not provided'
required: false
default: ''
engine:
description: 'Engine - a new one will be created if not provided'
database2:
description: 'Database (v2) - a new one will be created if not provided'
required: false
default: ''
engine2:
description: 'Engine (v2) - a new one will be created if not provided'
required: false
account:
description: 'Account'
Expand All @@ -29,7 +33,7 @@ jobs:

steps:
- name: Validate database and engine
if: ${{ (github.event.inputs.database == '') != (github.event.inputs.engine == '') }}
if: ${{ (github.event.inputs.database2 == '') != (github.event.inputs.engine2 == '') }}
uses: actions/github-script@v3
with:
script: |
Expand All @@ -49,15 +53,28 @@ jobs:
- name: Determine env variables
run: |
if [ "${{ github.event.inputs.environment }}" == 'staging' ]; then
echo "USERNAME=${{ secrets.FIREBOLT_USERNAME_STAGING }}" >> "$GITHUB_ENV"
echo "PASSWORD=${{ secrets.FIREBOLT_PASSWORD_STAGING }}" >> "$GITHUB_ENV"
echo "SERVICE_ACCOUNT_ID=${{ secrets.FIREBOLT_CLIENT_ID_STG_NEW_IDN }}" >> "$GITHUB_ENV"
echo "SERVICE_ACCOUNT_SECRET=${{ secrets.FIREBOLT_CLIENT_SECRET_STG_NEW_IDN }}" >> "$GITHUB_ENV"
else
echo "USERNAME=${{ secrets.FIREBOLT_USERNAME_DEV }}" >> "$GITHUB_ENV"
echo "PASSWORD=${{ secrets.FIREBOLT_PASSWORD_DEV }}" >> "$GITHUB_ENV"
echo "SERVICE_ACCOUNT_ID=${{ secrets.FIREBOLT_CLIENT_ID_NEW_IDN }}" >> "$GITHUB_ENV"
echo "SERVICE_ACCOUNT_SECRET=${{ secrets.FIREBOLT_CLIENT_SECRET_NEW_IDN }}" >> "$GITHUB_ENV"
fi
- name: Setup database and engine
id: setup
- name: Setup database and engine (v1)
id: setup1
if: ${{ github.event.inputs.database == '' }}
uses: firebolt-db/integration-testing-setup@v1
with:
firebolt-username: ${{ env.USERNAME }}
firebolt-password: ${{ env.PASSWORD }}
api-endpoint: "api.${{ github.event.inputs.environment }}.firebolt.io"
region: "us-east-1"
instance-type: "B2"
- name: Setup database and engine (v2)
id: setup2
if: ${{ github.event.inputs.database == '' }}
uses: firebolt-db/integration-testing-setup@v2
with:
Expand All @@ -67,26 +84,38 @@ jobs:
api-endpoint: "api.${{ github.event.inputs.environment }}.firebolt.io"
instance-type: "B2"

- name: Determine database name
id: find-database-name
- name: Determine database (v1) name
id: find-database-name1
run: |
if ! [[ -z "${{ github.event.inputs.database1 }}" ]]; then
echo "database_name1=${{ github.event.inputs.database1 }}" >> $GITHUB_OUTPUT
else
echo "database_name1=${{ steps.setup.outputs.database_name }}" >> $GITHUB_OUTPUT
fi
- name: Determine database (v2) name
id: find-database-name2
run: |
if ! [[ -z "${{ github.event.inputs.database }}" ]]; then
echo "database_name=${{ github.event.inputs.database }}" >> $GITHUB_OUTPUT
if ! [[ -z "${{ github.event.inputs.database2 }}" ]]; then
echo "database_name1=${{ github.event.inputs.database2 }}" >> $GITHUB_OUTPUT
else
echo "database_name=${{ steps.setup.outputs.database_name }}" >> $GITHUB_OUTPUT
echo "database_name1=${{ steps.setup.outputs.database_name2 }}" >> $GITHUB_OUTPUT
fi
- name: Determine engine name
id: find-engine-name
- name: Determine engine (v2) name
id: find-engine-name2
run: |
if ! [[ -z "${{ github.event.inputs.engine }}" ]]; then
echo "engine_name=${{ github.event.inputs.engine }}" >> $GITHUB_OUTPUT
if ! [[ -z "${{ github.event.inputs.engine2 }}" ]]; then
echo "engine_name2=${{ github.event.inputs.engine2 }}" >> $GITHUB_OUTPUT
else
echo "engine_name=${{ steps.setup.outputs.engine_name }}" >> $GITHUB_OUTPUT
echo "engine_name2=${{ steps.setup.outputs.engine_name2 }}" >> $GITHUB_OUTPUT
fi
- name: Run integration tests
run: ./gradlew integrationTest -Ddb=${{ steps.find-database-name.outputs.database_name }} -Denv=${{ github.event.inputs.environment }} -Dclient_secret="${{ env.SERVICE_ACCOUNT_SECRET }}" -Dclient_id="${{ env.SERVICE_ACCOUNT_ID }}" -Daccount="${{ github.event.inputs.account }}" -Dengine="${{ steps.find-engine-name.outputs.engine_name }}"
- name: Run integration tests (v1)
run: ./gradlew integrationTest -Ddb=${{ steps.find-database-name.outputs.database_name1 }} -Dapi=api.${{ github.event.inputs.environment }}.firebolt.io -Dpassword="${{ env.SERVICE_ACCOUNT_SECRET }}" -Duser="${{ env.SERVICE_ACCOUNT_ID }}" -DincludeTags="common,v1"

- name: Run integration tests (v2)
run: ./gradlew integrationTest -Ddb=${{ steps.find-database-name.outputs.database_name2 }} -Denv=${{ github.event.inputs.environment }} -Dclient_secret="${{ env.SERVICE_ACCOUNT_SECRET }}" -Dclient_id="${{ env.SERVICE_ACCOUNT_ID }}" -Daccount="${{ github.event.inputs.account }}" -Dengine="${{ steps.find-engine-name.outputs.engine_name2 }}" -DincludeTags="common,v2"

- name: "Foresight: Analyze Test Results"
uses: runforesight/foresight-test-kit-action@v1
Expand Down
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ test {

tasks.register('integrationTest', Test) {
description = 'Runs integration tests.'
useJUnitPlatform()
useJUnitPlatform() {
includeTags(System.getProperty("includeTags", "common").split(","))
excludeTags(System.getProperty("excludeTags", "nothing").split(","))
}
reports {
junitXml {
outputPerTestCase = true // defaults to false
Expand Down
22 changes: 20 additions & 2 deletions src/integrationTest/java/integration/ConnectionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;

import static java.lang.String.format;
Expand All @@ -18,6 +19,8 @@ public class ConnectionInfo {
private final String database;
private final String account;
private final String engine;
private final String api;
private final Supplier<String> jdbcUrlSupplier;

private ConnectionInfo() {
this(
Expand All @@ -26,17 +29,20 @@ private ConnectionInfo() {
getProperty("env"),
getProperty("db"),
getProperty("account"),
getProperty("engine")
getProperty("engine"),
getProperty("api")
);
}

public ConnectionInfo(String principal, String secret, String env, String database, String account, String engine) {
public ConnectionInfo(String principal, String secret, String env, String database, String account, String engine, String api) {
this.principal = principal;
this.secret = secret;
this.env = env;
this.database = database;
this.account = account;
this.engine = engine;
this.api = api;
jdbcUrlSupplier = api == null ? this::toJdbcUrl2 : this::toJdbcUrl1;
}

public static ConnectionInfo getInstance() {
Expand Down Expand Up @@ -78,7 +84,19 @@ public String getEngine() {
return engine;
}

public String getApi() {
return api;
}

public String toJdbcUrl() {
return jdbcUrlSupplier.get();
}

private String toJdbcUrl1() {
return "jdbc:firebolt://" + api + "/" + database + (engine == null ? "" : "?engine=" + engine);
}

private String toJdbcUrl2() {
String params = Stream.of(param("env", env), param("engine", engine), param("account", account)).filter(Objects::nonNull).collect(joining("&"));
if (!params.isEmpty()) {
params = "?" + params;
Expand Down
4 changes: 3 additions & 1 deletion src/integrationTest/java/integration/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.firebolt.jdbc.client.HttpClientConfig;
import lombok.CustomLog;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.TestInstance;

import java.io.InputStream;
Expand All @@ -17,6 +18,7 @@

@CustomLog
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Tag("common")
public abstract class IntegrationTest {

private static final String JDBC_URL_PREFIX = "jdbc:firebolt:";
Expand All @@ -38,7 +40,7 @@ protected Connection createConnection() throws SQLException {
protected Connection createConnection(String engine) throws SQLException {
ConnectionInfo current = integration.ConnectionInfo.getInstance();
ConnectionInfo updated = new ConnectionInfo(current.getPrincipal(), current.getSecret(),
current.getEnv(), current.getDatabase(), current.getAccount(), engine);
current.getEnv(), current.getDatabase(), current.getAccount(), engine, current.getApi());
return DriverManager.getConnection(updated.toJdbcUrl(),
integration.ConnectionInfo.getInstance().getPrincipal(),
integration.ConnectionInfo.getInstance().getSecret());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integration.tests;

import integration.ConnectionInfo;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

Expand All @@ -21,6 +22,7 @@ public class ConnectionTest {
* @throws SQLException if something went wrong
*/
@Test
@Tag("v2")
void connectionWithAdditionalProperties() throws SQLException {
ConnectionInfo params = integration.ConnectionInfo.getInstance();
String url = format("jdbc:firebolt:%s?env=%s&engine=%s&account=%s&use_standard_sql=1", params.getDatabase(), params.getEnv(), params.getEngine(), params.getAccount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import integration.ConnectionInfo;
import integration.IntegrationTest;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

Expand All @@ -13,16 +14,17 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class MissingDataTest extends IntegrationTest {
public class MissingDataTest {
@Test
@Tag("v2")
void missingAccount() throws SQLException {
ConnectionInfo current = integration.ConnectionInfo.getInstance();
try (Connection good = DriverManager.getConnection(current.toJdbcUrl(), current.getPrincipal(), current.getSecret())) {
assertNotNull(good);
}

ConnectionInfo noAccount = new ConnectionInfo(current.getPrincipal(), current.getSecret(),
current.getEnv(), current.getDatabase(), null, current.getEngine());
current.getEnv(), current.getDatabase(), null, current.getEngine(), current.getApi());
assertThrows(SQLException.class, () -> DriverManager.getConnection(noAccount.toJdbcUrl(), noAccount.getPrincipal(), noAccount.getSecret()));
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package integration.tests;

import static java.sql.Statement.SUCCESS_NO_INFO;
import static org.junit.jupiter.api.Assertions.*;

import java.sql.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.firebolt.jdbc.QueryResult;
import com.firebolt.jdbc.resultset.FireboltResultSet;
import com.firebolt.jdbc.testutils.AssertionUtil;
import com.firebolt.jdbc.type.FireboltDataType;

import integration.ConnectionInfo;
import integration.IntegrationTest;
import lombok.Builder;
import lombok.CustomLog;
import lombok.Value;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static java.sql.Statement.SUCCESS_NO_INFO;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

@CustomLog
class PreparedStatementTest extends IntegrationTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void afterAll() {
}

@Test
@Tag("slow")
void shouldExecuteEngineManagementQueries() throws SQLException {
try (Connection connection = this.createConnection(null)) {
List<String> queries = Arrays.asList(String.format("CREATE DATABASE IF NOT EXISTS %s", DATABASE_NAME),
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/firebolt/FireboltDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Properties;
import java.util.logging.Logger;

import com.firebolt.jdbc.connection.FireboltConnectionServiceSecretAuthentication;
import org.apache.commons.lang3.StringUtils;

import com.firebolt.jdbc.util.PropertyUtil;
Expand All @@ -29,7 +30,7 @@ public class FireboltDriver implements Driver {

@Override
public Connection connect(String url, Properties connectionSettings) throws SQLException {
return acceptsURL(url) ? new FireboltConnection(url, connectionSettings) : null;
return acceptsURL(url) ? FireboltConnection.create(url, connectionSettings) : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class FireboltObjectMapper {
private FireboltObjectMapper() {
}

public static com.fasterxml.jackson.databind.ObjectMapper getInstance() {
public static ObjectMapper getInstance() {
return MAPPER;
}
}
Loading

0 comments on commit 54823cf

Please sign in to comment.