Skip to content

Commit

Permalink
Enable more tests
Browse files Browse the repository at this point in the history
* Create missing profiles for H2, in pom and github workflows
* Add test classpath for H2 remote, so that UDF tests can run
* Make each H2 test config use different directories/ports
* Enable CockroachDB engine schema tests (required upgrading Docker image version, due to a bug cockroachdb/cockroach#62601)
* Add flag to MySQL test configs to allow connecting to newer versions of the server
* Other improvements and cleanups
  • Loading branch information
José Fidalgo committed Feb 14, 2022
1 parent 968dc8d commit b3b5cd9
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 161 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/test-h2remote.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: PDB tests with H2 remote

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-latest
name: Test H2 remote PDB Java ${{ matrix.java-version }}

strategy:
matrix:
java-version: [ 8, 11, 17 ]
steps:
- uses: actions/checkout@v2
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v2.3.1
with:
java-version: ${{ matrix.java-version }}
distribution: zulu

- name: Cache Maven packages
uses: actions/cache@v2.1.6
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-java${{ matrix.java-version }}

- name: Test with H2 remote
run: mvn -B clean test -Ph2remote
4 changes: 2 additions & 2 deletions .github/workflows/test-h2v2.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: PDB tests with H2v2
name: PDB tests with H2v2 embedded

on:
push:
Expand Down Expand Up @@ -33,4 +33,4 @@ jobs:
restore-keys: ${{ runner.os }}-m2-java${{ matrix.java-version }}

- name: Test with H2v2
run: mvn -B clean test -Ph2v2remote
run: mvn -B clean test -Ph2v2
36 changes: 36 additions & 0 deletions .github/workflows/test-h2v2remote.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: PDB tests with H2v2 remote

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-latest
name: Test H2V2 remote PDB Java ${{ matrix.java-version }}

strategy:
matrix:
java-version: [ 8, 11, 17 ]
steps:
- uses: actions/checkout@v2
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v2.3.1
with:
java-version: ${{ matrix.java-version }}
distribution: zulu

- name: Cache Maven packages
uses: actions/cache@v2.1.6
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-java${{ matrix.java-version }}

- name: Test with H2v2 remote
run: mvn -B clean test -Ph2v2remote
56 changes: 35 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down Expand Up @@ -348,6 +353,10 @@
<argLine>${default.test.cmdArgs}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
Expand Down Expand Up @@ -376,7 +385,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -390,7 +398,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<doclint>none</doclint>
</configuration>
Expand All @@ -407,7 +414,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down Expand Up @@ -445,13 +451,6 @@
<profiles>
<profile>
<id>h2remote</id>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand All @@ -467,7 +466,6 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>test-compile</phase>
Expand All @@ -478,6 +476,8 @@
</executions>
<configuration>
<executable>java</executable>
<!-- add test artifacts (UDFs) to server classpath -->
<classpathScope>test</classpathScope>
<arguments>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies,
Expand All @@ -501,14 +501,24 @@
</profile>

<profile>
<id>h2v2remote</id>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
<id>h2v2</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<instances>h2v2</instances>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>h2v2remote</id>
<build>
<plugins>
<plugin>
Expand All @@ -524,7 +534,6 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>test-compile</phase>
Expand All @@ -535,6 +544,8 @@
</executions>
<configuration>
<executable>java</executable>
<!-- add test artifacts (UDFs) to server classpath -->
<classpathScope>test</classpathScope>
<arguments>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies,
Expand All @@ -543,6 +554,9 @@
<argument>org.h2.tools.Server</argument>
<!-- make db available via tcp -->
<argument>-tcp</argument>
<!-- use port 9093, different from the one used in h2remote profile (the default 9092) -->
<argument>-tcpPort</argument>
<argument>9093</argument>
<!-- set local file inside test output directory -->
<argument>-baseDir</argument>
<argument>${project.build.testOutputDirectory}/pdb-h2v2-remote</argument>
Expand Down Expand Up @@ -713,7 +727,7 @@
<profile>
<id>cockroach</id>
<properties>
<image.cockroach>cockroachdb/cockroach:v19.2.0</image.cockroach>
<image.cockroach>cockroachdb/cockroach:v21.2.5</image.cockroach>
</properties>
<build>
<plugins>
Expand Down Expand Up @@ -743,7 +757,7 @@
<port>8080:8080</port>
<port>26257:26257</port>
</ports>
<cmd>start --insecure</cmd>
<cmd>start-single-node --insecure</cmd>
<wait>
<time>40000</time>
<log>CockroachDB node starting</log>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected Ieee754Support getIeee754Support() {


/**
* Gets the test schema to be used in tests that need a schema other then the default/configured.
* Gets the test schema to be used in tests that need a schema other than the default/configured.
*
* @return The test schema.
* @since 2.1.13
Expand Down Expand Up @@ -811,8 +811,7 @@ protected EntityEntry createSpecialValueEntry(final Object columnValue) {
* @param engine The database engine.
* @throws DatabaseEngineException If anything goes wrong creating the UDF.
*/
protected void defineUDFGetOne(final DatabaseEngine engine) throws DatabaseEngineException {
}
protected abstract void defineUDFGetOne(final DatabaseEngine engine) throws DatabaseEngineException;

/**
* Defines the UDF "TimesTwo" in the database engine.
Expand All @@ -822,8 +821,7 @@ protected void defineUDFGetOne(final DatabaseEngine engine) throws DatabaseEngin
* @param engine The database engine.
* @throws DatabaseEngineException If anything goes wrong creating the UDF.
*/
protected void defineUDFTimesTwo(final DatabaseEngine engine) throws DatabaseEngineException {
}
protected abstract void defineUDFTimesTwo(final DatabaseEngine engine) throws DatabaseEngineException;

/**
* Creates the {@link #getTestSchema() test schema} in the database, dropping it first if necessary.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2022 Feedzai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.feedzai.commons.sql.abstraction.engine.impl.cockroach;

import com.feedzai.commons.sql.abstraction.engine.impl.postgresql.PostgreSqlEngineSchemaTest;
import com.feedzai.commons.sql.abstraction.engine.testconfig.DatabaseConfiguration;
import com.feedzai.commons.sql.abstraction.engine.testconfig.DatabaseTestUtil;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Collection;

/**
* Schema related tests for CockroachDB.
*
* @author José Fidalgo (jose.fidalgo@feedzai.com)
*/
@RunWith(Parameterized.class)
public class CockroachDBEngineSchemaTest extends PostgreSqlEngineSchemaTest {

@Parameterized.Parameters
public static Collection<DatabaseConfiguration> data() throws Exception {
return DatabaseTestUtil.loadConfigurations("cockroach");
}

@Override
@Test
@Ignore("CockroachDB doesn't support stored procedures; see https://github.com/cockroachdb/cockroach/issues/17511")
public void udfGetOneTest() {
}

@Override
@Test
@Ignore("CockroachDB doesn't support stored procedures; see https://github.com/cockroachdb/cockroach/issues/17511")
public void udfTimesTwoTest() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ public static Collection<DatabaseConfiguration> data() throws Exception {
@Override
protected void defineUDFGetOne(final DatabaseEngine engine) throws DatabaseEngineException {
engine.executeUpdate(
"CREATE OR REPLACE FUNCTION GETONE () " +
" RETURNS INTEGER " +
" NO EXTERNAL ACTION " +
"F1: BEGIN ATOMIC " +
"RETURN 1; " +
"END"
"CREATE OR REPLACE FUNCTION GETONE()" +
" RETURNS INTEGER" +
" NO EXTERNAL ACTION" +
" F1: BEGIN ATOMIC" +
" RETURN 1;" +
" END"
);
}

@Override
protected void defineUDFTimesTwo(final DatabaseEngine engine) throws DatabaseEngineException {
engine.executeUpdate(
"CREATE OR REPLACE FUNCTION \"" + getTestSchema() + "\".TimesTwo (VARNAME VARCHAR(128)) " +
" RETURNS INTEGER " +
" NO EXTERNAL ACTION " +
"F1: BEGIN ATOMIC " +
" RETURN VARNAME * 2; " +
"END"
"CREATE OR REPLACE FUNCTION \"" + getTestSchema() + "\".TimesTwo(N VARCHAR(128))" +
" RETURNS INTEGER" +
" NO EXTERNAL ACTION" +
" F1: BEGIN ATOMIC" +
" RETURN N * 2;" +
" END"
);
}

Expand Down
Loading

0 comments on commit b3b5cd9

Please sign in to comment.