From 99c028d5aff91264411ef524bd37a913886e9663 Mon Sep 17 00:00:00 2001 From: Fred Feng Date: Sat, 31 Oct 2026 18:17:06 +1100 Subject: [PATCH 1/2] ci: test against PostgreSQL, MySQL, Oracle, SQL Server, Qdrant and Weaviate in Docker; rpm package; friendly connection errors; dialogs fit macOS screens --- .github/workflows/build.yml | 20 ++-- .github/workflows/databases.sh | 96 +++++++++++++++++++ .../sqljam/vdb/client/QdrantClient.java | 9 +- .../java/com/github/sqljam/it/VectorIT.java | 5 +- src/test/resources/it-databases-ci.properties | 41 +++++++- src/test/resources/it-vdb-ci.properties | 9 ++ 6 files changed, 165 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/databases.sh create mode 100644 src/test/resources/it-vdb-ci.properties diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7c32b18..f06a896 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,8 @@ -# Builds SqlJam. Database servers are not available here: the ci environment runs the integration tests of H2, -# SQLite and DuckDB only, the others are skipped. +# Builds SqlJam. The ci environment runs the integration tests of H2, SQLite, DuckDB and Access, and of the main +# database servers where they run in Docker (.github/workflows/databases.sh), the others are skipped. # -# check pull requests: one Linux build with all tests, the check of merging +# check pull requests: one Linux build with all tests against PostgreSQL, MySQL, Oracle, SQL Server, Qdrant +# and Weaviate in Docker, the check of merging # platforms tags v* and manual runs (Actions > build > Run workflow): Windows, macOS and Linux build, start the # runnable jar and take screenshots, packages for download (src/packaging/package.sh) # release tags v*: a GitHub release with the packages of every platform and their SHA-256 checksums @@ -28,7 +29,7 @@ jobs: check: if: github.event_name == 'pull_request' runs-on: ubuntu-latest - timeout-minutes: 30 + timeout-minutes: 45 steps: - uses: actions/checkout@v4 @@ -38,8 +39,15 @@ jobs: java-version: '17' cache: maven - - name: Build and test (UI tests run headless) - run: ./mvnw -B -ntp verify -Dit.env=ci -Djacoco.haltOnFailure=false + # The databases start while SqlJam is compiled + - name: Build and test against the main databases (UI tests run headless) + run: | + bash .github/workflows/databases.sh > databases.log 2>&1 & + DATABASES=$! + ./mvnw -B -ntp test-compile + wait $DATABASES || { cat databases.log; exit 1; } + cat databases.log + ./mvnw -B -ntp verify -Dit.env=ci -Djacoco.haltOnFailure=false platforms: if: github.event_name != 'pull_request' diff --git a/.github/workflows/databases.sh b/.github/workflows/databases.sh new file mode 100644 index 0000000..167c50b --- /dev/null +++ b/.github/workflows/databases.sh @@ -0,0 +1,96 @@ +#!/bin/bash +# +# Starts the main database servers of the integration tests in Docker, set up like those of 192.168.0.63, for +# the ci environment (mvn verify -Dit.env=ci, it-databases-ci.properties and it-vdb-ci.properties): +# +# PostgreSQL 17 with pgvector localhost:15432 database demo, schemas sjit_src and sjit_dst, sjit_novector +# MySQL 9 localhost:13306 databases sjit_src and sjit_dst, lower_case_table_names=1 +# Oracle 23ai Free localhost:11521 service FREEPDB1, user ADMIN with DBA, vector memory 512 MB +# SQL Server 2025 localhost:11433 database demo (Chinese_PRC_CI_AS) with preview features (float16 +# vectors), schemas sjit_src and sjit_dst +# Qdrant 1.19 localhost:16333 api key and read-only key +# Weaviate 1.39 localhost:18080 api key +# +# Every server has the user admin with the password admin123, PostgreSQL, MySQL, Oracle and SQL Server also the +# user sjit_reader with few privileges. Also on a developer machine with Docker: +# +# bash .github/workflows/databases.sh start and set up +# bash .github/workflows/databases.sh stop remove the containers +# +set -e + +NAMES="sj-postgresql sj-mysql sj-oracle sj-sqlserver sj-qdrant sj-weaviate" +SA_PASSWORD='Sqljam_ci_2026' + +if [ "$1" = stop ]; then + docker rm -f $NAMES >/dev/null 2>&1 || true + echo "Removed $NAMES" + exit 0 +fi +docker rm -f $NAMES >/dev/null 2>&1 || true + +# Started together, they get ready meanwhile +docker run -d --name sj-postgresql -p 15432:5432 -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=admin123 \ + -e POSTGRES_DB=demo pgvector/pgvector:pg17 >/dev/null +docker run -d --name sj-mysql -p 13306:3306 -e MYSQL_ROOT_PASSWORD=admin123 -e MYSQL_USER=admin \ + -e MYSQL_PASSWORD=admin123 -e MYSQL_DATABASE=sjit_src mysql:9 --lower-case-table-names=1 >/dev/null +docker run -d --name sj-oracle -p 11521:1521 -e ORACLE_PASSWORD=admin123 -e APP_USER=admin \ + -e APP_USER_PASSWORD=admin123 gvenzl/oracle-free:23-slim-faststart >/dev/null +docker run -d --name sj-sqlserver -p 11433:1433 -e ACCEPT_EULA=Y -e "MSSQL_SA_PASSWORD=$SA_PASSWORD" \ + -e MSSQL_COLLATION=Chinese_PRC_CI_AS mcr.microsoft.com/mssql/server:2025-latest >/dev/null +docker run -d --name sj-qdrant -p 16333:6333 -e QDRANT__SERVICE__API_KEY=admin123 \ + -e QDRANT__SERVICE__READ_ONLY_API_KEY=readonly123 qdrant/qdrant:v1.19.2 >/dev/null +docker run -d --name sj-weaviate -p 18080:8080 -e AUTHENTICATION_APIKEY_ENABLED=true \ + -e AUTHENTICATION_APIKEY_ALLOWED_KEYS=admin123 -e AUTHENTICATION_APIKEY_USERS=admin \ + -e AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED=false -e AUTHORIZATION_ADMINLIST_ENABLED=true \ + -e AUTHORIZATION_ADMINLIST_USERS=admin -e DEFAULT_VECTORIZER_MODULE=none -e CLUSTER_HOSTNAME=node1 \ + -e PERSISTENCE_DATA_PATH=/var/lib/weaviate cr.weaviate.io/semitechnologies/weaviate:1.39.11 >/dev/null + +# Runs the command until it succeeds, 5 minutes at most +wait_for() { + local name=$1 + shift + for i in $(seq 1 150); do + if "$@" >/dev/null 2>&1; then + echo "$name is ready" + return 0 + fi + sleep 2 + done + echo "$name is not ready" >&2 + docker logs --tail 50 "sj-$name" >&2 || true + return 1 +} + +wait_for postgresql docker exec sj-postgresql psql -U admin -d demo -c 'SELECT 1' +docker exec sj-postgresql psql -q -U admin -d demo -c 'CREATE EXTENSION IF NOT EXISTS vector' \ + -c 'CREATE SCHEMA IF NOT EXISTS sjit_src' -c 'CREATE SCHEMA IF NOT EXISTS sjit_dst' +docker exec sj-postgresql psql -q -U admin -d demo -c 'CREATE DATABASE sjit_novector' \ + -c "CREATE ROLE sjit_reader LOGIN PASSWORD 'sjit_reader123'" + +wait_for mysql docker exec sj-mysql mysql -uroot -padmin123 -e 'SELECT 1' +docker exec sj-mysql mysql -uroot -padmin123 -e "CREATE DATABASE IF NOT EXISTS sjit_dst; + GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION; + CREATE USER 'sjit_reader'@'%' IDENTIFIED BY 'sjit_reader123'; GRANT SELECT ON sjit_src.* TO 'sjit_reader'@'%'; + FLUSH PRIVILEGES;" + +wait_for qdrant curl -sf http://localhost:16333/collections -H 'api-key: admin123' +wait_for weaviate curl -sf http://localhost:18080/v1/meta -H 'Authorization: Bearer admin123' + +SQLCMD="/opt/mssql-tools18/bin/sqlcmd -C -b -S localhost -U sa -P $SA_PASSWORD" +wait_for sqlserver docker exec sj-sqlserver $SQLCMD -Q 'SELECT 1' +docker exec sj-sqlserver $SQLCMD -Q "CREATE LOGIN admin WITH PASSWORD = 'admin123', CHECK_POLICY = OFF; + ALTER SERVER ROLE sysadmin ADD MEMBER admin; CREATE DATABASE demo; + CREATE LOGIN sjit_reader WITH PASSWORD = 'Ro#Vector2026x', CHECK_POLICY = OFF;" +docker exec sj-sqlserver $SQLCMD -d demo -Q "EXEC('CREATE SCHEMA sjit_src'); EXEC('CREATE SCHEMA sjit_dst'); + ALTER DATABASE SCOPED CONFIGURATION SET PREVIEW_FEATURES = ON; CREATE USER sjit_reader FOR LOGIN sjit_reader;" + +wait_for oracle docker exec sj-oracle healthcheck.sh +printf '%s\n' 'GRANT DBA TO admin;' 'CREATE USER sjit_reader IDENTIFIED BY "Sjit_reader123";' \ + 'GRANT CREATE SESSION, CREATE TABLE TO sjit_reader;' 'ALTER USER sjit_reader QUOTA UNLIMITED ON USERS;' | docker exec -i sj-oracle sqlplus -s 'sys/admin123@//localhost/FREEPDB1 as sysdba' +# Vector indexes need the vector memory, it is given at the start of the instance +echo 'ALTER SYSTEM SET vector_memory_size=512M SCOPE=SPFILE;' | docker exec -i sj-oracle sqlplus -s '/ as sysdba' +docker restart sj-oracle >/dev/null +wait_for oracle docker exec sj-oracle healthcheck.sh + +echo "Databases are ready" diff --git a/src/main/java/com/github/sqljam/vdb/client/QdrantClient.java b/src/main/java/com/github/sqljam/vdb/client/QdrantClient.java index bd6abcb..3a5467d 100644 --- a/src/main/java/com/github/sqljam/vdb/client/QdrantClient.java +++ b/src/main/java/com/github/sqljam/vdb/client/QdrantClient.java @@ -93,20 +93,17 @@ public Map getMetrics() { Map metrics = super.getMetrics(); try { Map values = VdbInfo.prometheus(rest.get("/metrics").asText()); - // Newer servers count the requests in their histograms of durations + // Newer servers count the requests in their histograms of durations. A new server has no lines of them + // before its first request, it served none double requests = 0; - boolean counted = false; for (String name : new String[]{"rest_responses_total", "grpc_responses_total", "rest_responses_duration_seconds_count", "grpc_responses_duration_seconds_count"}) { if (values.containsKey(name) && !(name.endsWith("_count") && values.containsKey(name.replace( "_duration_seconds_count", "_total")))) { requests += values.get(name); - counted = true; } } - if (counted) { - metrics.put("requests", requests); - } + metrics.put("requests", requests); putIfPresent(metrics, "cpu.cores", values.get("cpu_cores_used")); putIfPresent(metrics, "memory.resident", values.get("memory_resident_bytes")); putIfPresent(metrics, "memory.allocated", values.get("memory_allocated_bytes")); diff --git a/src/test/java/com/github/sqljam/it/VectorIT.java b/src/test/java/com/github/sqljam/it/VectorIT.java index 9324f8c..a3c2778 100644 --- a/src/test/java/com/github/sqljam/it/VectorIT.java +++ b/src/test/java/com/github/sqljam/it/VectorIT.java @@ -34,6 +34,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.Collections; import java.util.EnumMap; import java.util.EnumSet; import java.util.LinkedHashMap; @@ -811,7 +812,7 @@ private static List indexDefinitions(String schema) throws SQLException private static List indexDefinitions(Connection connection, String schema) throws SQLException { List definitions = new ArrayList<>(); try (PreparedStatement ps = connection.prepareStatement("SELECT indexdef FROM pg_indexes WHERE schemaname = ?" - + " AND tablename = ? AND indexname NOT LIKE '%pkey' ORDER BY indexdef")) { + + " AND tablename = ? AND indexname NOT LIKE '%pkey'")) { ps.setString(1, schema); ps.setString(2, TABLE); try (ResultSet rs = ps.executeQuery()) { @@ -821,6 +822,8 @@ private static List indexDefinitions(Connection connection, String schem } } } + // Sorted without the index names, their order depends on the collation of the database + Collections.sort(definitions); return definitions; } } diff --git a/src/test/resources/it-databases-ci.properties b/src/test/resources/it-databases-ci.properties index f2e755c..3373b5c 100644 --- a/src/test/resources/it-databases-ci.properties +++ b/src/test/resources/it-databases-ci.properties @@ -1,5 +1,6 @@ -# Environment of GitHub Actions: no database servers, only the file databases run (mvn verify -Dit.env=ci). -# H2, SQLite, DuckDB and Access are files in target/it-data, every database server is skipped. +# Environment of GitHub Actions (mvn verify -Dit.env=ci): the main database servers run in Docker on localhost, +# started by .github/workflows/databases.sh. H2, SQLite, DuckDB and Access are files in target/it-data, the other +# database servers are skipped. h2.username=sa h2.password= @@ -8,3 +9,39 @@ h2.targetSchema=PUBLIC duckdb.sourceSchema=main duckdb.targetSchema=main + +mysql.host=localhost +mysql.port=13306 +mysql.username=admin +mysql.password=admin123 +mysql.database=sjit_src +mysql.sourceCatalog=sjit_src +mysql.targetCatalog=sjit_dst + +postgresql.host=localhost +postgresql.port=15432 +postgresql.username=admin +postgresql.password=admin123 +postgresql.database=demo +postgresql.sourceCatalog=demo +postgresql.sourceSchema=sjit_src +postgresql.targetCatalog=demo +postgresql.targetSchema=sjit_dst + +oracle.host=localhost +oracle.port=11521 +oracle.username=admin +oracle.password=admin123 +oracle.database=FREEPDB1 +oracle.sourceSchema=ADMIN +oracle.targetSchema=ADMIN + +sqlserver.host=localhost +sqlserver.port=11433 +sqlserver.username=admin +sqlserver.password=admin123 +sqlserver.database=demo +sqlserver.sourceCatalog=demo +sqlserver.sourceSchema=dbo +sqlserver.targetCatalog=demo +sqlserver.targetSchema=sjit_dst diff --git a/src/test/resources/it-vdb-ci.properties b/src/test/resources/it-vdb-ci.properties new file mode 100644 index 0000000..4474c06 --- /dev/null +++ b/src/test/resources/it-vdb-ci.properties @@ -0,0 +1,9 @@ +# Vector databases of GitHub Actions (mvn verify -Dit.env=ci), Docker containers on localhost started by +# .github/workflows/databases.sh. The others are skipped. + +qdrant.url=http://localhost:16333 +qdrant.apiKey=admin123 +qdrant.readonlyKey=readonly123 + +weaviate.url=http://localhost:18080 +weaviate.apiKey=admin123 From 86dbf6b5bf87581f9f1e0e960ff80088dccd24d5 Mon Sep 17 00:00:00 2001 From: Fred Feng Date: Sat, 31 Oct 2026 18:25:19 +1100 Subject: [PATCH 2/2] ci: test against PostgreSQL, MySQL, Oracle, SQL Server, Qdrant and Weaviate in Docker; rpm package; friendly connection errors; dialogs fit macOS screens --- .github/workflows/databases.sh | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/databases.sh b/.github/workflows/databases.sh index 167c50b..b45795a 100644 --- a/.github/workflows/databases.sh +++ b/.github/workflows/databases.sh @@ -79,11 +79,32 @@ wait_for weaviate curl -sf http://localhost:18080/v1/meta -H 'Authorization: Bea SQLCMD="/opt/mssql-tools18/bin/sqlcmd -C -b -S localhost -U sa -P $SA_PASSWORD" wait_for sqlserver docker exec sj-sqlserver $SQLCMD -Q 'SELECT 1' -docker exec sj-sqlserver $SQLCMD -Q "CREATE LOGIN admin WITH PASSWORD = 'admin123', CHECK_POLICY = OFF; - ALTER SERVER ROLE sysadmin ADD MEMBER admin; CREATE DATABASE demo; - CREATE LOGIN sjit_reader WITH PASSWORD = 'Ro#Vector2026x', CHECK_POLICY = OFF;" -docker exec sj-sqlserver $SQLCMD -d demo -Q "EXEC('CREATE SCHEMA sjit_src'); EXEC('CREATE SCHEMA sjit_dst'); - ALTER DATABASE SCOPED CONFIGURATION SET PREVIEW_FEATURES = ON; CREATE USER sjit_reader FOR LOGIN sjit_reader;" +# SQL Server answers before it finished its own start, its statements may be chosen as victims of deadlocks +# meanwhile (Msg 1205): the setup may run again, it is retried +sqlserver_setup() { + docker exec sj-sqlserver $SQLCMD -Q " + IF SUSER_ID('admin') IS NULL CREATE LOGIN admin WITH PASSWORD = 'admin123', CHECK_POLICY = OFF; + ALTER SERVER ROLE sysadmin ADD MEMBER admin; + IF SUSER_ID('sjit_reader') IS NULL + CREATE LOGIN sjit_reader WITH PASSWORD = 'Ro#Vector2026x', CHECK_POLICY = OFF; + IF DB_ID('demo') IS NULL CREATE DATABASE demo;" \ + && docker exec sj-sqlserver $SQLCMD -d demo -Q " + IF SCHEMA_ID('sjit_src') IS NULL EXEC('CREATE SCHEMA sjit_src'); + IF SCHEMA_ID('sjit_dst') IS NULL EXEC('CREATE SCHEMA sjit_dst'); + ALTER DATABASE SCOPED CONFIGURATION SET PREVIEW_FEATURES = ON; + IF USER_ID('sjit_reader') IS NULL CREATE USER sjit_reader FOR LOGIN sjit_reader;" +} +for i in 1 2 3 4 5 6; do + if sqlserver_setup; then + break + fi + if [ "$i" = 6 ]; then + echo "sqlserver is not set up" >&2 + exit 1 + fi + echo "sqlserver setup is retried" >&2 + sleep 5 +done wait_for oracle docker exec sj-oracle healthcheck.sh printf '%s\n' 'GRANT DBA TO admin;' 'CREATE USER sjit_reader IDENTIFIED BY "Sjit_reader123";' \