World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
title: "Test Gravitino" slug: "/how-to-test" license: "This software is licensed under the Apache License version 2."
Introduction
Apache Gravitino has two types of tests:
- Unit tests, focus on the functionalities of the specific class, module, or component.
- Integration tests, end-to-end tests that cover the whole system.
:::note before test
- If you want to run the complete integration test suites, you need to install Docker in your environment.
- Refer to How to build Gravitino to make sure you have a build environment ready.
- Use OrbStack to replace Docker Desktop on macOS. OrbStack automatically configures the network between the Docker containers.
- If you are using Docker Desktop for macOS, launch the
mac-docker-connector before running the tests.
Read
$GRAVITINO_HOME/dev/docker/tools/README.mdand$GRAVITINO_HOME/dev/docker/tools/mac-docker-connector.shfor more details. :::
Run the Unit Tests
To run the unit tests, run the following command:
./gradlew test -PskipITs
This command runs all the unit tests and skips the integration tests.
Core test lanes
core tests run in four lanes, one CI job each. Each database lane selects its database through the gravitino.core.test.backend system property:
| Lane | Runs | Database | Needs Docker |
|---|---|---|---|
./gradlew :core:coreUnitTest |
tests with no database backend | none | no |
./gradlew :core:coreH2Test |
classes tagged for H2 | H2 | no |
./gradlew :core:coreMySQLTest -PskipDockerTests=false |
classes tagged for MySQL | MySQL | yes |
./gradlew :core:corePostgreSQLTest -PskipDockerTests=false |
classes tagged for PostgreSQL | PostgreSQL | yes |
A class joins a database lane through @CoreBackend.H2, @CoreBackend.MySQL, @CoreBackend.PostgreSQL or @CoreBackend.All. Subclasses of TestJDBCBackend and AbstractEntityStorageTest inherit @CoreBackend.All. A class with none of these runs in coreUnitTest. A class tagged gravitino-docker-test with none of these runs in no lane, and TestCoreLaneMembership fails until you add one.
To run one class or method, add --tests to its lane:
./gradlew :core:coreH2Test --tests 'org.apache.gravitino.storage.relational.service.TestYourService'
./gradlew :core:coreMySQLTest -PskipDockerTests=false --tests 'org.apache.gravitino.storage.relational.service.TestYourService.testInsert'
If the class is not in that lane, Gradle fails with "No tests found for given includes".
coreMySQLTest and corePostgreSQLTest run their test JVM with the system property gravitino.test.db.disposableData=true, so the MySQL and PostgreSQL containers keep their data in memory (tmpfs, 2 GB) and skip syncing commits to disk. No other task sets it. Other tasks run MySQL with the image's default settings and PostgreSQL with the Testcontainers module's default, fsync=off.
Database reuse and reset
In a database lane, each test class shares one database per backend. @DatabaseFixture(resetStrategy = ...) picks how much is rebuilt before each test, from cheapest to most isolated:
ResetStrategy.DELETE_ROWS(the default) deletes the rows of every non-empty table;AUTO_INCREMENTcounters keep counting.ResetStrategy.TRUNCATE_TABLEStruncates every table, so the counters restart; it is slower, sinceTRUNCATErecreates each table.ResetStrategy.FRESH_DATABASEgives each test a new database and backend. Use it when a test changes the schema, closes the backend itself, or leaves writers running after it ends.
@DatabaseFixture(resetStrategy = ResetStrategy.FRESH_DATABASE)
public class TestSQLScripts extends TestJDBCBackend { ... }
A method-level @DatabaseFixture replaces the class-level one. A class's backend is closed when the class finishes.
:core:test
In CI, build (17) skips core tests; their results appear under the core-test (17, <lane>) checks. ./gradlew :core:test runs all core tests in one task. It is deprecated, and no CI job uses it. It selects no database: every database test runs against H2, and with -PskipDockerTests=false also against MySQL and PostgreSQL, building a new backend at every change of database. Without Docker, it runs the database tests like coreH2Test.
Run the Integration Tests
Gravitino has two modes to run the integration tests, the default embedded mode and deploy mode.
- In
embeddedmode, the integration test starts an embeddedMiniGravitinoserver within the same process as the integration test to run the integration tests. - In
deploymode, you have to build (./gradlew compileDistribution) a Gravitino binary package beforehand. The integration test launches and connects to the local Gravitino server to run the integration tests.
Run the Integration Tests in Embedded Mode
Run the
./gradlew build -x testcommand to build the Gravitino project.Use the
./gradlew test [--rerun-tasks] -PskipTests -PtestMode=embeddedcommands to run the integration tests.
:::note
Running the ./gradlew build command triggers the build and runs the integration tests in embedded mode.
:::
Deploy the Server and Run the Integration Tests in Deploy Mode
To deploy the Gravitino server locally to run the integration tests, follow these steps:
- Run the
./gradlew build -x testcommand to build the Gravitino project. - Use the
./gradlew compileDistributioncommand to compile and package the Gravitino project in thedistributiondirectory. - Use the
./gradlew test [--rerun-tasks] -PskipTests -PtestMode=deploycommand to run the integration tests in thedistributiondirectory. - Use the
bash trino-connector/integration-test/trino-test-tools/trino_test.shcommand to run all the Trino test sets in thetrino-connector/integration-test/src/test/resources/trino-ci-testset/testsetsdirectory. Specify the--trino_worker_numparameter to make the Trino test sets run in a distributed environment. Specify the--trino_versionparameter to make the Trino test sets run with specific trino version. Specify the--trino_connector_dirparameter to run Trino tests using the JAR files located in thegravitino-trino-connectorplugin directory.
Skip Tests
- Skip unit tests by using the
./gradlew build -PskipTestscommand. - Skip integration tests by using the
./gradlew build -PskipITscommand. - Skip web frontend integration tests by using the
./gradlew build -x :web:integration-test:testcommand. - Skip both unit tests and integration tests by using the
./gradlew build -x testor./gradlew build -PskipTests -PskipITscommands.
Configure Parameters for Integration Tests
DISPLAY_WEBPAGE_IN_TESTING
By default, the Gravitino web frontend page will not pop up when running integration tests.
If you wish to display the web frontend page during integrations test, you can set the DISPLAY_WEBPAGE_IN_TESTING environment variable in setIntegrationTestEnvironment in file build.gradle.kts.
For example:
param.environment("DISPLAY_WEBPAGE_IN_TESTING", true)
Docker Test Environment
Some integration test cases depend on the Gravitino CI Docker image.
If an integration test relies on the specific Gravitino CI Docker image,
set the @tag(gravitino-docker-test) annotation in the test class.
For example, the integration-test/src/test/.../CatalogHiveIT.java test needs to connect to
the apache/gravitino-ci:hive-{hive-version} Docker container for testing the Hive data source.
Therefore, it should have the following @tag annotation:@tag(gravitino-docker-test). This annotation
helps identify the specific Docker container required for the integration test.
For example:
@Tag("gravitino-docker-test")
public class CatalogHiveIT extends AbstractIT {
...
}
Run All Integration Tests
:::note
- Make sure that the
Docker serveris running before running all the integration tests. Otherwise, it only runs the integration tests without thegravitino-docker-testtag. - To run Docker-related tests, make sure you have installed Docker in your environment and either
set skipDockerTests=false in the gradle.properties file (or use
-PskipDockerTests=falsein the command) or (2) export SKIP_DOCKER_TESTS=false in shell. Otherwise, all tests requiring Docker will be skipped. - On macOS, be sure to run the
${GRAVITINO_HOME}/dev/docker/tools/mac-docker-connector.shscript before running the integration tests; or make sure that OrbStack is running. :::
When integration tests run, they check the whole environment and output the status of the required environment, for example:
------------------ Check Docker environment ---------------------
Docker server status ............................................ [running]
mac-docker-connector status ..................................... [stop]
OrbStack status ................................................. [yes]
Using Gravitino IT Docker container to run all integration tests. [deploy test]
-----------------------------------------------------------------
Complete integration tests only run when all the required environments are met. Otherwise,
only parts of them without the gravitino-docker-test tag run.
Debug Server and Integration Tests in Embedded Mode
By default, the integration tests run in the embedded mode, in which MiniGravitino starts in the
same process. Debugging MiniGravitino is simple and easy, you can modify any code in the
Gravitino project and set breakpoints anywhere.
Debug Server and Integration Tests in Deploy Mode
This mode is closer to the actual environment, but more complex to debug. To debug the Gravitino server code, follow these steps:
- Run the
./gradlew build -x testcommand to build the Gravitino project. - Use the
./gradlew compileDistributioncommand to republish the packaged project in thedistributiondirectory. - If you are only debugging integration test codes, You don't have to do any setup to debug directly.
- If you need to debug Gravitino server codes, follow these steps:
- Enable the
GRAVITINO_DEBUG_OPTSenvironment variable in thedistribution/package/conf/gravitino-env.shfile to enable remote JVM debugging. - Manually start the Gravitino server using the
./distribution/package/bin/gravitino.sh startcommand. - Select the
gravitino.server.mainmodule classpath in theRemote JVM Debugto attach the Gravitino server process and debug it.
- Enable the
Run on GitHub Actions
- GitHub Actions automatically run integration tests in the embedded and deploy modes when you submit a pull request.
- View the test results in the
Actionstab of the pull request page. - Run the integration tests in several steps:
- The Gravitino integration tests pull the CI Docker image from the Docker Hub repository. This step typically takes around 15 seconds.
- The Gravitino project compiles and packages in the
distributiondirectory using the./gradlew compileDistributioncommand. - Run the
./gradlew test -PtestMode=[embedded|deploy]command.
Test Failure and Test Logs
If a test fails, you can retrieve valuable information from the logs and test reports. Test reports are in the ./build/reports directory. The integration test logs are in the ./integrate-test/build directory. In deploy mode, Gravitino server logs are in the ./distribution/package/logs/ directory.
In the event of a test failure within the GitHub workflow, the system generates archived logs and test reports. To obtain the archive, follow these steps:
Click the
detaillink associated with the failed integration test in the pull request. This redirects you to the job page.
On the job page, locate the
Summarybutton on the left-hand side and click it to access the workflow summary page.
Look for the Artifacts item on the summary page and download the archive from there.

You can also add the tag
upload logto your PR to upload the logs to the PR page. in this case, no matter the CI pipeline status, the logs will be uploaded to the PR page.