Skip to content

Commit

Permalink
Merge pull request #193 from liquibase/feature/updateContributedTests
Browse files Browse the repository at this point in the history
Fix for LTH tests
  • Loading branch information
filipelautert committed May 10, 2023
2 parents adca680 + e09745d commit f3f9a46
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 263 deletions.
55 changes: 11 additions & 44 deletions .github/workflows/lth.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,17 @@
name: Liquibase Test Harness

on:
workflow_dispatch:
pull_request:

types:
- opened
- reopened
- synchronize
push:
branches:
- main
-
jobs:
liquibase-test-harness:
name: Liquibase Test Harness
runs-on: ubuntu-latest

strategy:
matrix:
liquibase-support-level: [Contributed, Foundational, Advanced] # Define the different test levels to run
database-version: [3, 4]
fail-fast: false # Set fail-fast to false to run all test levels even if some of them fail

steps:
- name: Checkout code # Checkout the code from the repository
uses: actions/checkout@v3

- name: Start database container # Start the database container using Docker Compose
run: docker compose -f src/test/resources/docker/docker-compose.yml up -d

- name: Setup Temurin Java 17 # Set up Java 17 with Temurin distribution and cache the Maven packages
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
cache: 'maven'

- name: Build with Maven # Build the code with Maven (skip tests)
run: mvn -ntp -Dmaven.test.skip package

- name: Run ${{ matrix.liquibase-support-level }} Liquibase Test Harness # Run the Liquibase test harness at each test level
continue-on-error: true # Continue to run the action even if the previous steps fail
env:
LIQUIBASE_PRO_LICENSE_KEY: ${{ secrets.PRO_LICENSE_KEY }} # Set the environment variable for the Liquibase Pro license key
run: mvn -ntp -DdbVersion=${{ matrix.database-version }} -Dtest=liquibase.ext.cassandra.${{ matrix.liquibase-support-level }}ExtensionHarnessSuite test # Run the Liquibase test harness at each test level

- name: Test Reporter # Generate a test report using the Test Reporter action
uses: dorny/test-reporter@v1.6.0
if: always() # Run the action even if the previous steps fail
with:
name: Liquibase Test Harness - ${{ matrix.liquibase-support-level }} Reports # Set the name of the test report
path: target/surefire-reports/TEST-*.xml # Set the path to the test report files
reporter: java-junit # Set the reporter to use
fail-on-error: false # Set fail-on-error to false to show report even if it has failed tests

- name: Stop database container # Stop the database container using Docker Compose
run: docker-compose -f src/test/resources/docker/docker-compose.yml down
uses: liquibase/build-logic/.github/workflows/lth-docker.yml@main
secrets: inherit
329 changes: 166 additions & 163 deletions src/main/java/liquibase/ext/cassandra/database/CassandraDatabase.java
Original file line number Diff line number Diff line change
@@ -1,163 +1,166 @@
package liquibase.ext.cassandra.database;

import com.simba.cassandra.cassandra.core.CDBJDBCConnection;
import com.simba.cassandra.jdbc.jdbc42.S42Connection;
import liquibase.Scope;
import liquibase.database.AbstractJdbcDatabase;
import liquibase.database.DatabaseConnection;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.DatabaseException;
import liquibase.structure.core.Index;

import java.sql.Statement;

/**
* Cassandra 1.2.0 NoSQL database support.
*/
public class CassandraDatabase extends AbstractJdbcDatabase {
public static final String PRODUCT_NAME = "Cassandra";

private String keyspace;

@Override
public String getShortName() {
return "cassandra";
}

@Override
public int getPriority() {
return PRIORITY_DEFAULT;
}

@Override
protected String getDefaultDatabaseProductName() {
return "Cassandra";
}

@Override
public Integer getDefaultPort() {
return 9160;
}

@Override
public int getDatabaseMinorVersion() throws DatabaseException {
return 0;
}

@Override
public boolean supportsInitiallyDeferrableColumns() {
return false;
}

@Override
public boolean supportsSequences() {
return false;
}

@Override
public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException {
String databaseProductName = conn.getDatabaseProductName();
return PRODUCT_NAME.equalsIgnoreCase(databaseProductName);
}

@Override
public String getDefaultDriver(String url) {
if (String.valueOf(url).startsWith("jdbc:cassandra:")) {
return "com.simba.cassandra.jdbc42.Driver";
}
return null;
}

@Override
public boolean supportsTablespaces() {
return false;
}

@Override
public boolean supportsRestrictForeignKeys() {
return false;
}

@Override
public boolean supportsDropTableCascadeConstraints() {
return false;
}

@Override
public boolean isAutoCommit(){
return true;
}

@Override
public void setAutoCommit(boolean b){
}

@Override
public boolean isCaseSensitive() {
return true;
}

@Override
public String getCurrentDateTimeFunction() {
// no alternative in cassandra, using client time
return String.valueOf(System.currentTimeMillis());
}

public String getKeyspace() {
if (keyspace == null) {
try {
if (this.getConnection() instanceof JdbcConnection) {
keyspace = ((CDBJDBCConnection) ((S42Connection) ((JdbcConnection) (this).getConnection())
.getUnderlyingConnection()).getConnection()).getSession().getLoggedKeyspace();
}
} catch (Exception e) {
Scope.getCurrentScope().getLog(CassandraDatabase.class)
.severe("Could not get keyspace from connection", e);

}
}
return keyspace;

}

@Override
public boolean supportsSchemas() {
return false;
}

/**
* Cassandra actually doesn't support neither catalogs nor schemas, but keyspaces.
* As default liquibase classes don't know what is keyspace we gonna use keyspace instead of catalog
*/
@Override
public String getDefaultCatalogName() {
return getKeyspace();
}

public Statement getStatement() throws DatabaseException {
return ((JdbcConnection) super.getConnection()).createStatement();
}

@Override
public boolean jdbcCallsCatalogsSchemas() {
return true;
}

@Override
public boolean supportsNotNullConstraintNames() {
return false;
}

@Override
public boolean supportsPrimaryKeyNames() {
return false;
}

/**
* there shouldn't be keyspace name before the index name, queries fail otherwise
*/
@Override
public String escapeIndexName(String catalogName, String schemaName, String indexName) {
return this.escapeObjectName(indexName, Index.class);
}
}
package liquibase.ext.cassandra.database;

import com.simba.cassandra.cassandra.core.CDBJDBCConnection;
import com.simba.cassandra.jdbc.jdbc42.S42Connection;
import liquibase.Scope;
import liquibase.database.AbstractJdbcDatabase;
import liquibase.database.DatabaseConnection;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.DatabaseException;
import liquibase.structure.core.Index;

import java.sql.Statement;

/**
* Cassandra 1.2.0 NoSQL database support.
*/
public class CassandraDatabase extends AbstractJdbcDatabase {
public static final String PRODUCT_NAME = "Cassandra";
public static final String SHORT_PRODUCT_NAME = "cassandra";
public static final Integer DEFAULT_PORT = 9160;
public static final String DEFULT_DRIVER = "com.simba.cassandra.jdbc.Driver";

private String keyspace;

@Override
public String getShortName() {
return SHORT_PRODUCT_NAME;
}

@Override
public int getPriority() {
return PRIORITY_DEFAULT;
}

@Override
protected String getDefaultDatabaseProductName() {
return PRODUCT_NAME;
}

@Override
public Integer getDefaultPort() {
return DEFAULT_PORT;
}

@Override
public int getDatabaseMinorVersion() throws DatabaseException {
return 0;
}

@Override
public boolean supportsInitiallyDeferrableColumns() {
return false;
}

@Override
public boolean supportsSequences() {
return false;
}

@Override
public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException {
String databaseProductName = conn.getDatabaseProductName();
return PRODUCT_NAME.equalsIgnoreCase(databaseProductName);
}

@Override
public String getDefaultDriver(String url) {
if (String.valueOf(url).startsWith("jdbc:cassandra:")) {
return DEFULT_DRIVER;
}
return null;
}

@Override
public boolean supportsTablespaces() {
return false;
}

@Override
public boolean supportsRestrictForeignKeys() {
return false;
}

@Override
public boolean supportsDropTableCascadeConstraints() {
return false;
}

@Override
public boolean isAutoCommit(){
return true;
}

@Override
public void setAutoCommit(boolean b){
}

@Override
public boolean isCaseSensitive() {
return true;
}

@Override
public String getCurrentDateTimeFunction() {
// no alternative in cassandra, using client time
return String.valueOf(System.currentTimeMillis());
}

public String getKeyspace() {
if (keyspace == null) {
try {
if (this.getConnection() instanceof JdbcConnection) {
keyspace = ((CDBJDBCConnection) ((S42Connection) ((JdbcConnection) (this).getConnection())
.getUnderlyingConnection()).getConnection()).getSession().getLoggedKeyspace();
}
} catch (Exception e) {
Scope.getCurrentScope().getLog(CassandraDatabase.class)
.severe("Could not get keyspace from connection", e);

}
}
return keyspace;

}

@Override
public boolean supportsSchemas() {
return false;
}

/**
* Cassandra actually doesn't support neither catalogs nor schemas, but keyspaces.
* As default liquibase classes don't know what is keyspace we gonna use keyspace instead of catalog
*/
@Override
public String getDefaultCatalogName() {
return getKeyspace();
}

public Statement getStatement() throws DatabaseException {
return ((JdbcConnection) super.getConnection()).createStatement();
}

@Override
public boolean jdbcCallsCatalogsSchemas() {
return true;
}

@Override
public boolean supportsNotNullConstraintNames() {
return false;
}

@Override
public boolean supportsPrimaryKeyNames() {
return false;
}

/**
* there shouldn't be keyspace name before the index name, queries fail otherwise
*/
@Override
public String escapeIndexName(String catalogName, String schemaName, String indexName) {
return this.escapeObjectName(indexName, Index.class);
}
}
Loading

0 comments on commit f3f9a46

Please sign in to comment.