Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#222][#370] feat(CI): MiniGraviton integration test framework (#397)

Xun Liu44ef05b93095
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index fafc8aa3dc..9b6676561d 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -18,6 +18,7 @@ jobs:
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
+ timeout-minutes: 30
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
@@ -32,13 +33,13 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
- gradle-version: '8.1.1'
+ gradle-version: '8.2'
- name: Show gradle version
run: gradle --version
- name: Build with Gradle
- run: gradle build
+ run: gradle build -PskipITs
- name: Jacoco Report to PR
id: jacoco
diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml
index f8edfa53c6..77404bb8a8 100644
--- a/.github/workflows/docker-image.yml
+++ b/.github/workflows/docker-image.yml
@@ -17,7 +17,7 @@ env:
jobs:
publish-docker-image:
runs-on: ubuntu-latest
- timeout-minutes: 60
+ timeout-minutes: 30
env:
input_token: ${{ github.event.inputs.token }}
secrets_token: ${{ secrets.PUBLISH_DOCKER_TOKEN }}
diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml
index c3996a8e4f..1d84b1a8b3 100644
--- a/.github/workflows/integration-test.yml
+++ b/.github/workflows/integration-test.yml
@@ -20,7 +20,7 @@ jobs:
# Integration test for AMD64 architecture
test-amd64-arch:
runs-on: ubuntu-latest
- timeout-minutes: 60
+ timeout-minutes: 30
strategy:
matrix:
architecture: [linux/amd64]
@@ -53,14 +53,14 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
- gradle-version: '8.1.1'
+ gradle-version: '8.2'
- name: Show gradle version
run: gradle --version
- name: Package Graviton
run: |
- gradle build
+ gradle build -x test
gradle compileDistribution
- name: Check docker container status
@@ -79,10 +79,15 @@ jobs:
docker run --rm --name ${DOCKER_RUN_NAME} --platform ${PLATFORM} -d -p 8022:22 -p 8088:8088 -p 9000:9000 -p 9083:9083 -p 10000:10000 -p 10002:10002 -p 50070:50070 -p 50075:50075 ${HIVE_IMAGE_NAME}:${HIVE_IMAGE_TAG_NAME}
sleep 60
+ - name: Setup debug Github Action
+ if: ${{ contains(github.event.pull_request.labels.*.name, 'debug action') }}
+ uses: csexton/debugger-action@master
+
- name: Integration Test
id: integrationTest
run: |
- gradle integrationTest
+ gradle test --rerun-tasks -PskipTests -PtestMode=embedded
+ gradle test --rerun-tasks -PskipTests -PtestMode=deploy
- name: Print logs when Graviton integration tests failure
if: ${{ failure() && steps.integrationTest.outcome == 'failure' }}
diff --git a/build.gradle.kts b/build.gradle.kts
index 67a754f476..95d8ddc237 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -40,8 +40,8 @@ subprojects {
}
tasks.configureEach<Test> {
- // Integration test module are tested separately
- if (project.name != "integration-test") {
+ val skipTests = project.hasProperty("skipTests")
+ if (!skipTests) {
useJUnitPlatform()
finalizedBy(tasks.getByName("jacocoTestReport"))
}
@@ -231,11 +231,6 @@ tasks {
dependsOn(":catalog-hive:copyCatalogLibs", ":catalog-lakehouse:copyCatalogLibs")
}
- task("integrationTest") {
- mustRunAfter(":catalog-hive:copyDepends", ":catalog-lakehouse:copyDepends")
- dependsOn(":integration-test:integrationTest")
- }
-
clean {
dependsOn(cleanDistribution)
}
diff --git a/conf/log4j2.properties.template b/conf/log4j2.properties.template
index 3321548184..e5da7d9ebe 100644
--- a/conf/log4j2.properties.template
+++ b/conf/log4j2.properties.template
@@ -33,5 +33,5 @@ appender.rolling.strategy.delete.ifLastModified.type = IfLastModified
appender.rolling.strategy.delete.ifLastModified.age = 30d
# Configure root logger
-rootLogger.level = debug
+rootLogger.level = info
rootLogger.appenderRef.rolling.ref = fileLogger
diff --git a/core/src/main/java/com/datastrato/graviton/Config.java b/core/src/main/java/com/datastrato/graviton/Config.java
index 4889c29633..e49d27bed0 100644
--- a/core/src/main/java/com/datastrato/graviton/Config.java
+++ b/core/src/main/java/com/datastrato/graviton/Config.java
@@ -184,7 +184,7 @@ public abstract class Config {
* @param properties The properties object containing configuration key-value pairs.
*/
@VisibleForTesting
- void loadFromProperties(Properties properties) {
+ public void loadFromProperties(Properties properties) {
loadFromMap(Maps.fromProperties(properties));
}
@@ -196,7 +196,7 @@ public abstract class Config {
* @throws IOException If there's an issue loading the properties.
*/
@VisibleForTesting
- Properties loadPropertiesFromFile(File file) throws IOException {
+ public Properties loadPropertiesFromFile(File file) throws IOException {
Properties properties = new Properties();
try (InputStream in = Files.newInputStream(file.toPath())) {
properties.load(in);
diff --git a/dev/docker/hive/build-docker.sh b/dev/docker/hive/build-docker.sh
index 8c9d536cd1..38577d329f 100755
--- a/dev/docker/hive/build-docker.sh
+++ b/dev/docker/hive/build-docker.sh
@@ -10,7 +10,7 @@ bin="$(cd "${bin}">/dev/null; pwd)"
# Environment variables definition
HADOOP_VERSION="2.7.3"
HIVE_VERSION="2.3.9"
-IMAGE_NAME="datastrato/hive:0.1.0"
+IMAGE_NAME="datastrato/graviton-ci-hive:0.1.1"
HADOOP_PACKAGE_NAME="hadoop-${HADOOP_VERSION}.tar.gz"
HADOOP_DOWNLOAD_URL="http://archive.apache.org/dist/hadoop/core/hadoop-${HADOOP_VERSION}/${HADOOP_PACKAGE_NAME}"
diff --git a/docs/integration-test.md b/docs/integration-test.md
index c9cbd3ed77..336e5aa61f 100644
--- a/docs/integration-test.md
+++ b/docs/integration-test.md
@@ -5,31 +5,117 @@
# How to Run Integration Tests
## Introduction
-The `integration-test` module contains test cases that serve as integration tests to ensure the correctness of the Graviton Server, API, and Client.
-You can run these tests locally or on GitHub Actions.
-
-## Running on GitHub Actions
-When you submit a pull request to the `main` branch, GitHub Actions will automatically run the integration tests.
-You can view the test results in the `Actions` tab of the pull request page.
-The integration tests are executed in the following steps:
-
-1. If you set the `build docker image` label in the pull request, GitHub Actions will trigger the build of all Docker images under the `./dev/docker/` directory. This step usually takes around 10 minutes. If you have made changes to the Dockerfile, you need to set the `build docker image` label in the pull request.
-2. If you do not set the `build docker image` label in the pull request, GitHub Actions will pull the Docker image `datastrato/graviton-ci-hive:latest` from the Docker Hub repository. This step usually takes around 15 seconds.
-3. The Docker image is then run in the GitHub Actions environment.
-4. If you set the `debug action` label in the pull request, GitHub Actions will run an SSH server with `csexton/debugger-action@master`, allowing you to remotely log in to the Actions environment for debugging purposes.
-5. The Graviton project is compiled and packaged in the `distribution` directory using the `./gradlew compileDistribution` command.
-6. The integration test cases in the `integration-test` module are executed using the `./gradlew integrationTest` command.
-7. The Docker image is stopped.
-8. The test environment is cleaned up.
-
-## Running Locally
-Before running the tests, make sure Docker is installed.
-Then, execute blow steps:
-1. Execute the `./gradlew clean build` command to build Graviton project.
-2. The Graviton project is compiled and packaged in the `distribution` directory using the `./gradlew compileDistribution` command.
-3. Run a hive docker test environment container in the local using the `docker run --rm -d -p 8022:22 -p 8088:8088 -p 9000:9000 -p 9083:9083 -p 10000:10000 -p 10002:10002 -p 50070:50070 -p 50075:50075 datastrato/graviton-ci-hive` command.
-4. The integration test cases in the `integration-test` module are executed using the `./gradlew integrationTest` command.
+The `integration-test` module contains integration test cases to ensure the correctness of the
+Graviton Server, API, and Client. These tests can be run locally or on GitHub Actions.
+
+## Test Modes
+
+### MiniGraviton Embedded Mode
+The `MiniGraviton` is a lightweight Graviton Server that is embedded in the integration test module.
+1. Execute the `./gradlew build -x test` command to build the Graviton project.
+2. Use the `./gradlew test [--rerun-tasks]` or `./gradlew test [--rerun-tasks] -PtestMode=embedded` command to run the integration tests.
+> Execution the `./gradlew build` command to build the Graviton project and automatic run the integration tests in the embedded mode.
+
+It provides full Graviton Server functionality and supports the following abilities:
+- Running a Graviton Server in a single thread
+- Starting a Jetty Server to provide the Graviton Server API, using a random port to avoid port conflicts
+- Using a random storage path to store backend data, which is deleted when MiniGraviton is stopped
+
+### Deploying Graviton Server Locally
+The Graviton Server can be deployed locally to run the integration tests. Follow these steps:
+
+1. Execute the `./gradlew build -x test` command to build the Graviton project.
+2. Use the `./gradlew compileDistribution` command to compile and package the Graviton project in the `distribution` directory.
+3. Use the `./gradlew test [--rerun-tasks] -PtestMode=deploy` command to run the integration tests in the `distribution` directory.
+
+### Skipping Tests
++ You can skip unit tests by using the `./gradlew build -PskipTests` command.
++ You can skip integration tests by using the `./gradlew build -PskipITs` command.
++ You can both skip unit tests and integration tests by using the `./gradlew build -x test` or `./gradlew build -PskipTests -PskipITs` command.
+
+## Docker Test Environment
+Some integration test cases depend on the Graviton CI Docker environment.
+
+If an integration test relies on the specific Graviton CI Docker environment,
+you need to set the `@tag(CI-DOCKER-NAME)` annotation in the test class.
+For example, the `integration-test/src/test/.../CatalogHiveIT.java` test needs to connect to
+the `datastrato/graviton-ci-hive` Docker container for testing the Hive data source.
+Therefore, it should have the following `@tag` annotation:`@tag(CI-DOCKER-NAME)`, This annotation
+helps identify the specific Docker container required for the integration test.
+For example:
+```
+@Tag("graviton-ci-hive")
+public class CatalogHiveIT extends AbstractIT {
+...
+}
+```
+
+If you have Docker installed and a special CI Docker container running, the `./gradlew test -PtestMode=[embedded|deploy]`
+command will automatically execute all the test cases.
+```
+------------------- Check Docker environment ------------------
+Docker server status .......................................... [running]
+Graviton IT Docker container is already running ............... [yes]
+Use Graviton IT Docker container to run all integration test. [embbeded|deploy test]
+---------------------------------------------------------------
+```
+
+If Docker is not installed or the special CI Docker container is not running, the `./gradlew test -PtestMode=[embedded|deploy]`
+command will skip the test cases that depend on the special Docker environment.
+```
+------------------- Check Docker environment ------------------
+Docker server status .......................................... [running]
+Graviton IT Docker container is already running ............... [no]
+Run only test cases where tag is set `graviton-docker-it`. [embbeded|deploy test]
+---------------------------------------------------------------
+```
+> Graviton will run all integration test cases in the GitHub Actions environment.
+
+### Running Graviton CI Docker Environment
+Before running the tests, make sure Docker is installed.
+
+#### Running Graviton Hive CI Docker Environment
+1. Run a hive docker test environment container in the local using the `docker run --rm -d -p 8022:22 -p 8088:8088 -p 9000:9000 -p 9083:9083 -p 10000:10000 -p 10002:10002 -p 50070:50070 -p 50075:50075 datastrato/graviton-ci-hive` command.
Additionally, the Graviton Server and third-party data source Docker runtime environments will use certain ports. Ensure that these ports are not already in use:
- Graviton Server: Port `8090`
-- Hive Docker runtime environment: Ports is `22`, `7180`, `8088`, `8888`, `9000`, `9083`, `10000`, `10002`, `50070`, and ` 50075`
\ No newline at end of file
+- Hive Docker runtime environment: Ports is `22`, `7180`, `8088`, `8888`, `9000`, `9083`, `10000`, `10002`, `50070`, and ` 50075`
+
+## Debugging Graviton Server and Integration Tests
+By default, the integration tests are run using MiniGraviton.
+Debugging with MiniGraviton is simple and easy. You can modify any code in the Graviton project and set breakpoints anywhere.
+
+### How to Debug deploy mode Graviton Server and Integration Tests
+
+To debug the Graviton Server and integration tests, you have two modes: `embedded` and `deploy` mode.
+
+1. Embedded Mode (default):
+ - This mode is simpler to debug but not as close to the actual environment
+ - Debugging with `MiniGraviton` is simple and easy. You don't to do any setup to debug directly
+
+2. Deploy Mode:
+ - This mode is closer to the actual environment but more complex to debug
+ - To debug the Graviton Server code, follow these steps:
+ - Execute the `./gradlew build -x test` command to build the Graviton project
+ - Use the `./gradlew compileDistribution` command to republish the packaged project in the `distribution` directory
+ - If you only debug integration test codes, You don't to do any setup to debug directly
+ - If you need debug Graviton server codes, flow these steps:
+ - Enable the `GRAVITON_DEBUG_OPTS` environment variable in the `distribution/package/conf/graviton-env.sh` file to enable remote JVM debugging
+ - Manually start the Graviton Server using the `./distribution/package/bin/graviton-server.sh start` command
+ - Select `graviton.server.main` module classpath in the `Remote JVM Debug` to attach the Graviton Server process and debug it
+
+## Running on GitHub Actions:
+
+- When you submit a pull request to the `main` branch, GitHub Actions will automatically run integration tests in the embedded and deploy mode.
+- Test results can be viewed in the `Actions` tab of the pull request page.
+- The integration tests are executed in several steps:
+
+ + If you set the `build docker image` label in the pull request, GitHub Actions will trigger the build of all Docker
+ images under the `./dev/docker/` directory. This step usually takes around 10 minutes. If you have made changes to the Dockerfile,
+ you need to set the `build docker image` label in the pull request.
+ + Otherwise, GitHub Actions will pull the Docker image `datastrato/graviton-ci-hive` from the Docker Hub repository. This step usually takes around 15 seconds.
+ + If you set the `debug action` label in the pull request, GitHub Actions will run an SSH server with
+ `csexton/debugger-action@master`, allowing you to remotely log in to the Actions environment for debugging purposes.
+ + The Graviton project is compiled and packaged in the `distribution` directory using the `./gradlew compileDistribution` command.
+ + Execution the `./gradlew test -PtestMode=[embedded|deploy]` command.
+ + Stop Docker image and cleaned up.
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 3c257a15ac..f6584b9a0a 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -5,8 +5,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
# checksum was taken from https://gradle.org/release-checksums
-distributionSha256Sum=e111cb9948407e26351227dabce49822fb88c37ee72f1d1582a69c68af2e702f
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
+distributionSha256Sum=38f66cd6eef217b4c35855bb11ea4e9fbc53594ccccb5fb82dfd317ef8c2c5a3
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/integration-test/build.gradle.kts b/integration-test/build.gradle.kts
index 5519ec3fd3..1837b8516f 100644
--- a/integration-test/build.gradle.kts
+++ b/integration-test/build.gradle.kts
@@ -3,6 +3,9 @@
* This software is licensed under the Apache License version 2.
*/
+import java.io.IOException
+import kotlin.io.*
+
plugins {
`maven-publish`
id("java")
@@ -11,12 +14,18 @@ plugins {
}
dependencies {
- testImplementation(project(":api"))
- testImplementation(project(":core"))
- testImplementation(project(":common"))
- testImplementation(project(":client-java"))
- testImplementation(project(":catalog-hive"))
- testImplementation(project(":server"))
+ implementation(project(":server"))
+ implementation(project(":common"))
+ implementation(project(":client-java"))
+ implementation(project(":api"))
+ implementation(project(":core"))
+ implementation(project(":catalog-hive"))
+ implementation(libs.guava)
+ implementation(libs.bundles.log4j)
+ implementation(libs.bundles.jersey)
+ implementation(libs.bundles.jetty)
+ implementation(libs.httpclient5)
+ implementation(libs.commons.io)
testImplementation(libs.hive2.metastore) {
exclude("org.apache.hbase")
@@ -85,14 +94,117 @@ dependencies {
testImplementation(libs.httpclient5)
testRuntimeOnly(libs.junit.jupiter.engine)
testImplementation(libs.mockito.core)
+ testImplementation(libs.bundles.log4j)
+}
+
+/* Optimizing integration test execution conditions */
+// Use this variable to control if we need to run docker test or not.
+var HIVE_IMAGE_NAME = "datastrato/graviton-ci-hive"
+var HIVE_IMAGE_TAG_NAME = "${HIVE_IMAGE_NAME}:0.1.2"
+var EXCLUDE_DOCKER_TEST = true
+// Use these 3 variables allow for more detailed control in the future.
+project.extra["dockerRunning"] = false
+project.extra["hiveContainerRunning"] = false
+
+fun printDockerCheckInfo() {
+ val testMode = project.properties["testMode"] as? String ?: "embedded"
+ if (testMode != "deploy" && testMode != "embedded") {
+ return
+ }
+ val dockerRunning = project.extra["dockerRunning"] as? Boolean ?: false
+ val hiveContainerRunning = project.extra["hiveContainerRunning"] as? Boolean ?: false
+ if (dockerRunning && hiveContainerRunning) {
+ EXCLUDE_DOCKER_TEST = false
+ }
+
+ println("------------------ Check Docker environment -----------------")
+ println("Docker server status ........................................ [${if (dockerRunning) "running" else "stop"}]")
+ println("Graviton IT Docker container is already running ............. [${if (hiveContainerRunning) "yes" else "no"}]")
+
+ if (dockerRunning && hiveContainerRunning) {
+ println("Use Graviton IT Docker container to run all integration test. [$testMode test]")
+ } else {
+ println("Run only test cases where tag is set `graviton-docker-it`.... [$testMode test]")
+ }
+ println("-------------------------------------------------------------")
}
tasks {
- val integrationTest by creating(Test::class) {
- environment("GRAVITON_HOME", rootDir.path + "/distribution/package")
- environment("HADOOP_USER_NAME", "hive")
- environment("HADOOP_HOME", "/tmp")
- environment("PROJECT_VERSION", version)
- useJUnitPlatform()
+ // Use this task to check if docker container is running
+ register("checkContainerRunning") {
+ doLast {
+ try {
+ val process = ProcessBuilder("docker", "ps", "--format='{{.Image}}'").start()
+ val exitCode = process.waitFor()
+
+ if (exitCode == 0) {
+ val output = process.inputStream.bufferedReader().readText()
+ val haveHiveContainer = output.contains("${HIVE_IMAGE_NAME}")
+ if (haveHiveContainer) {
+ project.extra["hiveContainerRunning"] = true
+ }
+ } else {
+ println("checkContainerRunning command execution failed with exit code $exitCode")
+ }
+ } catch (e: IOException) {
+ println("checkContainerRunning command execution failed: ${e.message}")
+ }
+ }
+ }
+
+ // Use this task to check if docker is running
+ register("checkDockerRunning") {
+ dependsOn("checkContainerRunning")
+
+ doLast {
+ try {
+ val process = ProcessBuilder("docker", "info").start()
+ val exitCode = process.waitFor()
+
+ if (exitCode == 0) {
+ project.extra["dockerRunning"] = true
+ } else {
+ println("checkDockerRunning Command execution failed with exit code $exitCode")
+ }
+ } catch (e: IOException) {
+ println("checkDockerRunning command execution failed: ${e.message}")
+ }
+ printDockerCheckInfo()
+ }
+ }
+}
+
+tasks.test {
+ val skipITs = project.hasProperty("skipITs")
+ if (skipITs) {
+ exclude("**/integration/test/**")
+ } else {
+ dependsOn("checkDockerRunning")
+
+ doFirst {
+ // Default use MiniGraviton to run integration tests
+ environment("GRAVITON_ROOT_DIR", rootDir.path)
+ environment("HADOOP_USER_NAME", "hive")
+ environment("HADOOP_HOME", "/tmp")
+ environment("PROJECT_VERSION", version)
+
+ var testMode = project.properties["testMode"] as? String ?: "embedded"
+ if (testMode == "deploy") {
+ environment("GRAVITON_HOME", rootDir.path + "/distribution/package")
+ systemProperty("testMode", "deploy")
+ } else if (testMode == "embedded") {
+ environment("GRAVITON_HOME", rootDir.path)
+ environment("GRAVITON_TEST", "true")
+ systemProperty("testMode", "embedded")
+ } else {
+ throw GradleException("Graviton integration test only support [-PtestMode=embedded] or [-PtestMode=deploy] mode!")
+ }
+
+ useJUnitPlatform {
+ if (EXCLUDE_DOCKER_TEST) {
+ excludeTags("graviton-docker-it")
+ }
+ }
+ }
}
-}
\ No newline at end of file
+}
diff --git a/integration-test/src/main/java/com/datastrato/graviton/integration/test/MiniGraviton.java b/integration-test/src/main/java/com/datastrato/graviton/integration/test/MiniGraviton.java
new file mode 100644
index 0000000000..dae7da01bb
--- /dev/null
+++ b/integration-test/src/main/java/com/datastrato/graviton/integration/test/MiniGraviton.java
@@ -0,0 +1,196 @@
+/*
+ * Copyright 2023 Datastrato.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.graviton.integration.test;
+
+import static com.datastrato.graviton.Configs.ENTRY_KV_ROCKSDB_BACKEND_PATH;
+
+import com.datastrato.graviton.Config;
+import com.datastrato.graviton.Configs;
+import com.datastrato.graviton.client.ErrorHandlers;
+import com.datastrato.graviton.client.HTTPClient;
+import com.datastrato.graviton.client.RESTClient;
+import com.datastrato.graviton.dto.responses.VersionResponse;
+import com.datastrato.graviton.exceptions.RESTException;
+import com.datastrato.graviton.integration.test.util.ITUtils;
+import com.datastrato.graviton.rest.RESTUtils;
+import com.datastrato.graviton.server.GravitonServer;
+import com.datastrato.graviton.server.ServerConfig;
+import com.google.common.collect.ImmutableMap;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import org.apache.commons.io.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MiniGraviton {
+ private static final Logger LOG = LoggerFactory.getLogger(MiniGraviton.class);
+ private RESTClient restClient;
+ private final File mockConfDir;
+ private final ServerConfig serverConfig = new ServerConfig();
+ private final ExecutorService executor = Executors.newSingleThreadExecutor();
+
+ public MiniGraviton() throws IOException {
+ this.mockConfDir = Files.createTempDirectory("MiniGraviton").toFile();
+ mockConfDir.mkdirs();
+ }
+
+ public void start() throws Exception {
+ LOG.info("Staring MiniGraviton up...");
+
+ String gravitonRootDir = System.getenv("GRAVITON_ROOT_DIR");
+
+ // Generate random Graviton Server port and backend storage path, avoiding conflicts
+ customizeConfigFile(
+ ITUtils.joinDirPath(gravitonRootDir, "conf", "graviton.conf.template"),
+ ITUtils.joinDirPath(mockConfDir.getAbsolutePath(), GravitonServer.CONF_FILE));
+
+ Files.copy(
+ Paths.get(ITUtils.joinDirPath(gravitonRootDir, "conf", "graviton-env.sh.template")),
+ Paths.get(ITUtils.joinDirPath(mockConfDir.getAbsolutePath(), "graviton-env.sh")));
+
+ Properties properties =
+ serverConfig.loadPropertiesFromFile(
+ new File(ITUtils.joinDirPath(mockConfDir.getAbsolutePath(), "graviton.conf")));
+ serverConfig.loadFromProperties(properties);
+
+ // Prepare delete the rocksdb backend storage directory
+ try {
+ FileUtils.deleteDirectory(FileUtils.getFile(serverConfig.get(ENTRY_KV_ROCKSDB_BACKEND_PATH)));
+ } catch (Exception e) {
+ // Ignore
+ }
+
+ // Initialize the REST client
+ String host = serverConfig.get(ServerConfig.WEBSERVER_HOST);
+ int port = serverConfig.get(ServerConfig.WEBSERVER_HTTP_PORT);
+ String URI = String.format("http://%s:%d", host, port);
+ restClient = HTTPClient.builder(ImmutableMap.of()).uri(URI).build();
+
+ executor.submit(
+ () -> {
+ try {
+ GravitonServer.main(
+ new String[] {ITUtils.joinDirPath(mockConfDir.getAbsolutePath(), "graviton.conf")});
+ } catch (Exception e) {
+ LOG.error("Exception in startup MiniGraviton Server ", e);
+ throw new RuntimeException(e);
+ }
+ });
+ long beginTime = System.currentTimeMillis();
+ boolean started = false;
+ while (System.currentTimeMillis() - beginTime < 1000 * 60 * 3) {
+ Thread.sleep(500);
+ started = checkIfServerIsRunning();
+ if (started) {
+ break;
+ }
+ }
+ if (!started) {
+ throw new RuntimeException("Can not start Graviton server");
+ }
+
+ LOG.info("MiniGraviton stared.");
+ }
+
+ public void stop() throws IOException, InterruptedException {
+ LOG.debug("MiniGraviton shutDown...");
+
+ executor.shutdown();
+ Thread.sleep(500);
+ executor.shutdownNow();
+
+ long beginTime = System.currentTimeMillis();
+ boolean started = true;
+ while (System.currentTimeMillis() - beginTime < 1000 * 60 * 3) {
+ Thread.sleep(500);
+ started = checkIfServerIsRunning();
+ if (!started) {
+ break;
+ }
+ }
+
+ restClient.close();
+ try {
+ FileUtils.deleteDirectory(mockConfDir);
+ FileUtils.deleteDirectory(FileUtils.getFile(serverConfig.get(ENTRY_KV_ROCKSDB_BACKEND_PATH)));
+ } catch (Exception e) {
+ // Ignore
+ }
+
+ if (started) {
+ throw new RuntimeException("Can not stop Graviton server");
+ }
+
+ LOG.debug("MiniGraviton terminated.");
+ }
+
+ public Config getServerConfig() {
+ return serverConfig;
+ }
+
+ // Customize the config file
+ private void customizeConfigFile(String configTempFileName, String configFileName)
+ throws IOException {
+ Map<String, String> configMap = new HashMap<>();
+ configMap.put(
+ ServerConfig.WEBSERVER_HTTP_PORT.getKey(),
+ String.valueOf(RESTUtils.findAvailablePort(2000, 3000)));
+ configMap.put(
+ Configs.ENTRY_KV_ROCKSDB_BACKEND_PATH.getKey(), "/tmp/graviton-" + UUID.randomUUID());
+
+ Properties props = new Properties();
+
+ try (InputStream inputStream = Files.newInputStream(Paths.get(configTempFileName));
+ OutputStream outputStream = Files.newOutputStream(Paths.get(configFileName))) {
+ props.load(inputStream);
+
+ for (Map.Entry<String, String> entry : configMap.entrySet()) {
+ props.setProperty(entry.getKey(), entry.getValue());
+ }
+
+ props.store(outputStream, null);
+ } catch (IOException e) {
+ LOG.error("Exception in customizeConfigFile ", e);
+ }
+ }
+
+ private boolean checkIfServerIsRunning() {
+ String host = serverConfig.get(ServerConfig.WEBSERVER_HOST);
+ int port = serverConfig.get(ServerConfig.WEBSERVER_HTTP_PORT);
+ String URI = String.format("http://%s:%d", host, port);
+ LOG.info("checkIfServerIsRunning() URI: {}", URI);
+
+ restClient = HTTPClient.builder(ImmutableMap.of()).uri(URI).build();
+ VersionResponse response = null;
+ try {
+ response =
+ restClient.get(
+ "api/version",
+ VersionResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.restErrorHandler());
+ } catch (RESTException e) {
+ LOG.warn("checkIfServerIsRunning() fails, GravitonServer is not running");
+ }
+ if (response != null && response.getCode() == 0) {
+ return true;
+ } else {
+ LOG.warn("checkIfServerIsRunning() fails, GravitonServer is not running");
+ }
+
+ return false;
+ }
+}
diff --git a/integration-test/src/main/java/com/datastrato/graviton/integration/test/util/ITUtils.java b/integration-test/src/main/java/com/datastrato/graviton/integration/test/util/ITUtils.java
new file mode 100644
index 0000000000..edadc9ec78
--- /dev/null
+++ b/integration-test/src/main/java/com/datastrato/graviton/integration/test/util/ITUtils.java
@@ -0,0 +1,13 @@
+/*
+ * Copyright 2023 Datastrato.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.graviton.integration.test.util;
+
+import java.io.File;
+
+public class ITUtils {
+ public static String joinDirPath(String... dirs) {
+ return String.join(File.separator, dirs);
+ }
+}
diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/CatalogHiveIT.java b/integration-test/src/test/java/com/datastrato/graviton/integration/test/catalog/CatalogHiveIT.java
similarity index 98%
rename from integration-test/src/test/java/com/datastrato/graviton/integration/e2e/CatalogHiveIT.java
rename to integration-test/src/test/java/com/datastrato/graviton/integration/test/catalog/CatalogHiveIT.java
index 936a96f35c..c0f34c9d93 100644
--- a/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/CatalogHiveIT.java
+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/test/catalog/CatalogHiveIT.java
@@ -2,7 +2,7 @@
* Copyright 2023 Datastrato.
* This software is licensed under the Apache License version 2.
*/
-package com.datastrato.graviton.integration.e2e;
+package com.datastrato.graviton.integration.test.catalog;
import static com.datastrato.graviton.rel.transforms.Transforms.identity;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -12,8 +12,8 @@ import com.datastrato.graviton.NameIdentifier;
import com.datastrato.graviton.catalog.hive.HiveClientPool;
import com.datastrato.graviton.client.GravitonMetaLake;
import com.datastrato.graviton.dto.rel.ColumnDTO;
-import com.datastrato.graviton.integration.util.AbstractIT;
-import com.datastrato.graviton.integration.util.GravitonITUtils;
+import com.datastrato.graviton.integration.test.util.AbstractIT;
+import com.datastrato.graviton.integration.test.util.GravitonITUtils;
import com.datastrato.graviton.rel.Schema;
import com.datastrato.graviton.rel.SchemaChange;
import com.datastrato.graviton.rel.Table;
@@ -37,9 +37,11 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
+@Tag("graviton-docker-it")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class CatalogHiveIT extends AbstractIT {
public static String metalakeName = GravitonITUtils.genRandomName("CatalogHiveIT_metalake");
diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/MetalakeIT.java b/integration-test/src/test/java/com/datastrato/graviton/integration/test/client/MetalakeIT.java
similarity index 97%
rename from integration-test/src/test/java/com/datastrato/graviton/integration/e2e/MetalakeIT.java
rename to integration-test/src/test/java/com/datastrato/graviton/integration/test/client/MetalakeIT.java
index 1db1b36b97..0ad44e58d7 100644
--- a/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/MetalakeIT.java
+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/test/client/MetalakeIT.java
@@ -2,7 +2,7 @@
* Copyright 2023 Datastrato.
* This software is licensed under the Apache License version 2.
*/
-package com.datastrato.graviton.integration.e2e;
+package com.datastrato.graviton.integration.test.client;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -16,8 +16,8 @@ import com.datastrato.graviton.exceptions.IllegalNameIdentifierException;
import com.datastrato.graviton.exceptions.IllegalNamespaceException;
import com.datastrato.graviton.exceptions.MetalakeAlreadyExistsException;
import com.datastrato.graviton.exceptions.NoSuchMetalakeException;
-import com.datastrato.graviton.integration.util.AbstractIT;
-import com.datastrato.graviton.integration.util.GravitonITUtils;
+import com.datastrato.graviton.integration.test.util.AbstractIT;
+import com.datastrato.graviton.integration.test.util.GravitonITUtils;
import java.util.ArrayList;
import java.util.Collections;
import org.junit.jupiter.api.AfterEach;
diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/AbstractIT.java b/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/AbstractIT.java
new file mode 100644
index 0000000000..a8a4ab776e
--- /dev/null
+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/AbstractIT.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2023 Datastrato.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.graviton.integration.test.util;
+
+import static com.datastrato.graviton.Configs.ENTRY_KV_ROCKSDB_BACKEND_PATH;
+
+import com.datastrato.graviton.Config;
+import com.datastrato.graviton.client.GravitonClient;
+import com.datastrato.graviton.integration.test.MiniGraviton;
+import com.datastrato.graviton.server.GravitonServer;
+import com.datastrato.graviton.server.ServerConfig;
+import java.io.IOException;
+import org.apache.commons.io.FileUtils;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@ExtendWith(PrintFuncNameExtension.class)
+public class AbstractIT {
+ public static final Logger LOG = LoggerFactory.getLogger(AbstractIT.class);
+ protected static GravitonClient client;
+
+ private static MiniGraviton miniGraviton;
+
+ private static final String TEST_MODE = "testMode";
+ private static final String EMBEDDED_TEST_MODE = "embedded";
+
+ static String testMode =
+ System.getProperty(TEST_MODE) == null ? EMBEDDED_TEST_MODE : System.getProperty(TEST_MODE);
+
+ @BeforeAll
+ public static void startIntegrationTest() throws Exception {
+ LOG.info("Running Graviton Server in {} mode", testMode);
+
+ Config serverConfig = new ServerConfig();
+ if (testMode != null && testMode.equals(EMBEDDED_TEST_MODE)) {
+ miniGraviton = new MiniGraviton();
+ miniGraviton.start();
+ serverConfig = miniGraviton.getServerConfig();
+ } else {
+ serverConfig.loadFromFile(GravitonServer.CONF_FILE);
+
+ try {
+ FileUtils.deleteDirectory(
+ FileUtils.getFile(serverConfig.get(ENTRY_KV_ROCKSDB_BACKEND_PATH)));
+ } catch (Exception e) {
+ // Ignore
+ }
+
+ GravitonITUtils.startGravitonServer();
+ }
+
+ String uri =
+ "http://"
+ + serverConfig.get(ServerConfig.WEBSERVER_HOST)
+ + ":"
+ + serverConfig.get(ServerConfig.WEBSERVER_HTTP_PORT);
+ client = GravitonClient.builder(uri).build();
+ }
+
+ @AfterAll
+ public static void stopIntegrationTest() throws IOException, InterruptedException {
+ if (client != null) {
+ client.close();
+ }
+ if (testMode != null && testMode.equals(EMBEDDED_TEST_MODE)) {
+ miniGraviton.stop();
+ } else {
+ GravitonITUtils.stopGravitonServer();
+ }
+ LOG.info("Tearing down Graviton Server");
+ }
+}
diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/util/CommandExecutor.java b/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/CommandExecutor.java
similarity index 98%
rename from integration-test/src/test/java/com/datastrato/graviton/integration/util/CommandExecutor.java
rename to integration-test/src/test/java/com/datastrato/graviton/integration/test/util/CommandExecutor.java
index 084e112916..2af12ec3b2 100644
--- a/integration-test/src/test/java/com/datastrato/graviton/integration/util/CommandExecutor.java
+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/CommandExecutor.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.datastrato.graviton.integration.util;
+package com.datastrato.graviton.integration.test.util;
import java.io.IOException;
import java.util.ArrayList;
diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/util/GravitonITUtils.java b/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/GravitonITUtils.java
similarity index 97%
rename from integration-test/src/test/java/com/datastrato/graviton/integration/util/GravitonITUtils.java
rename to integration-test/src/test/java/com/datastrato/graviton/integration/test/util/GravitonITUtils.java
index d260d8d5d0..c74659fa03 100644
--- a/integration-test/src/test/java/com/datastrato/graviton/integration/util/GravitonITUtils.java
+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/GravitonITUtils.java
@@ -2,7 +2,7 @@
* Copyright 2023 Datastrato.
* This software is licensed under the Apache License version 2.
*/
-package com.datastrato.graviton.integration.util;
+package com.datastrato.graviton.integration.test.util;
import com.google.common.collect.Maps;
import java.util.Map;
diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/PrintFuncNameExtension.java b/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/PrintFuncNameExtension.java
new file mode 100644
index 0000000000..ad312e0902
--- /dev/null
+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/PrintFuncNameExtension.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2023 Datastrato.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.graviton.integration.test.util;
+
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PrintFuncNameExtension implements BeforeEachCallback, AfterEachCallback {
+ public static final Logger LOG = LoggerFactory.getLogger(PrintFuncNameExtension.class);
+
+ @Override
+ public void beforeEach(ExtensionContext context) {
+ LOG.info("===== Entry test: {} =====", context.getDisplayName());
+ }
+
+ @Override
+ public void afterEach(ExtensionContext context) {
+ LOG.info("====== Exit Test: {} ======", context.getDisplayName());
+ }
+}
diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/util/ProcessData.java b/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/ProcessData.java
similarity index 99%
rename from integration-test/src/test/java/com/datastrato/graviton/integration/util/ProcessData.java
rename to integration-test/src/test/java/com/datastrato/graviton/integration/test/util/ProcessData.java
index b9caffd65a..d095170064 100644
--- a/integration-test/src/test/java/com/datastrato/graviton/integration/util/ProcessData.java
+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/ProcessData.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.datastrato.graviton.integration.util;
+package com.datastrato.graviton.integration.test.util;
import java.io.BufferedReader;
import java.io.IOException;
diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/web/rest/VersionOperationsIT.java b/integration-test/src/test/java/com/datastrato/graviton/integration/test/web/rest/VersionOperationsIT.java
similarity index 76%
rename from integration-test/src/test/java/com/datastrato/graviton/integration/e2e/web/rest/VersionOperationsIT.java
rename to integration-test/src/test/java/com/datastrato/graviton/integration/test/web/rest/VersionOperationsIT.java
index 9ba73a2054..5a20b387c4 100644
--- a/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/web/rest/VersionOperationsIT.java
+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/test/web/rest/VersionOperationsIT.java
@@ -2,12 +2,12 @@
* Copyright 2023 Datastrato.
* This software is licensed under the Apache License version 2.
*/
-package com.datastrato.graviton.integration.e2e.web.rest;
+package com.datastrato.graviton.integration.test.web.rest;
import com.datastrato.graviton.client.GravitonVersion;
-import com.datastrato.graviton.integration.util.AbstractIT;
-import com.datastrato.graviton.integration.util.CommandExecutor;
-import com.datastrato.graviton.integration.util.ProcessData;
+import com.datastrato.graviton.integration.test.util.AbstractIT;
+import com.datastrato.graviton.integration.test.util.CommandExecutor;
+import com.datastrato.graviton.integration.test.util.ProcessData;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/util/AbstractIT.java b/integration-test/src/test/java/com/datastrato/graviton/integration/util/AbstractIT.java
deleted file mode 100644
index 5a04a4a25d..0000000000
--- a/integration-test/src/test/java/com/datastrato/graviton/integration/util/AbstractIT.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2023 Datastrato.
- * This software is licensed under the Apache License version 2.
- */
-package com.datastrato.graviton.integration.util;
-
-import static com.datastrato.graviton.Configs.ENTRY_KV_ROCKSDB_BACKEND_PATH;
-
-import com.datastrato.graviton.Config;
-import com.datastrato.graviton.client.GravitonClient;
-import com.datastrato.graviton.server.GravitonServer;
-import com.datastrato.graviton.server.ServerConfig;
-import org.apache.commons.io.FileUtils;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-
-public class AbstractIT {
- protected static GravitonClient client;
-
- @BeforeAll
- public static void startIntegrationTest() throws Exception {
- Config serverConfig = new ServerConfig();
- serverConfig.loadFromFile(GravitonServer.CONF_FILE);
-
- try {
- FileUtils.deleteDirectory(FileUtils.getFile(serverConfig.get(ENTRY_KV_ROCKSDB_BACKEND_PATH)));
- } catch (Exception e) {
- // Ignore
- }
-
- GravitonITUtils.startGravitonServer();
- String uri =
- "http://"
- + serverConfig.get(ServerConfig.WEBSERVER_HOST)
- + ":"
- + serverConfig.get(ServerConfig.WEBSERVER_HTTP_PORT);
- client = GravitonClient.builder(uri).build();
- }
-
- @AfterAll
- public static void stopIntegrationTest() {
- client.close();
- GravitonITUtils.stopGravitonServer();
- }
-}
diff --git a/integration-test/src/test/resources/log4j2.properties b/integration-test/src/test/resources/log4j2.properties
index 6c72a79ff4..4ae1dd9a2b 100644
--- a/integration-test/src/test/resources/log4j2.properties
+++ b/integration-test/src/test/resources/log4j2.properties
@@ -4,7 +4,7 @@
#
# Set to debug or trace if log4j initialization is failing
-status = warn
+status = info
# Name of the configuration
name = ConsoleLogConfigDemo
diff --git a/server/build.gradle.kts b/server/build.gradle.kts
index 63749d1904..818cf09c99 100644
--- a/server/build.gradle.kts
+++ b/server/build.gradle.kts
@@ -85,11 +85,16 @@ fun writeProjectPropertiesFile() {
}
}
-tasks.named("build") {
- writeProjectPropertiesFile()
- val file = file(propertiesFile)
- if (!file.exists()) {
- throw GradleException("$propertiesFile file not generated!")
+tasks {
+ build {
+ writeProjectPropertiesFile()
+ val file = file(propertiesFile)
+ if (!file.exists()) {
+ throw GradleException("$propertiesFile file not generated!")
+ }
+ }
+ test {
+ environment("GRAVITON_HOME", rootDir.path)
}
}
diff --git a/server/src/main/java/com/datastrato/graviton/server/GravitonServer.java b/server/src/main/java/com/datastrato/graviton/server/GravitonServer.java
index a3fbc53d20..0483844d1d 100644
--- a/server/src/main/java/com/datastrato/graviton/server/GravitonServer.java
+++ b/server/src/main/java/com/datastrato/graviton/server/GravitonServer.java
@@ -11,6 +11,8 @@ import com.datastrato.graviton.meta.MetalakeManager;
import com.datastrato.graviton.server.web.JettyServer;
import com.datastrato.graviton.server.web.ObjectMapperProvider;
import com.datastrato.graviton.server.web.VersioningFilter;
+import java.io.File;
+import java.util.Properties;
import javax.servlet.Servlet;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.jackson.JacksonFeature;
@@ -31,20 +33,13 @@ public class GravitonServer extends ResourceConfig {
private final GravitonEnv gravitonEnv;
- public GravitonServer() {
- serverConfig = new ServerConfig();
+ public GravitonServer(ServerConfig config) {
+ serverConfig = config;
server = new JettyServer();
gravitonEnv = GravitonEnv.getInstance();
}
public void initialize() {
- try {
- serverConfig.loadFromFile(CONF_FILE);
- } catch (Exception exception) {
- LOG.warn(
- "Failed to load conf from file {}, using default conf instead", CONF_FILE, exception);
- }
-
server.initialize(serverConfig);
gravitonEnv.initialize(serverConfig);
@@ -88,7 +83,9 @@ public class GravitonServer extends ResourceConfig {
public static void main(String[] args) {
LOG.info("Starting Graviton Server");
- GravitonServer server = new GravitonServer();
+ String confPath = System.getenv("GRAVITON_TEST") == null ? "" : args[0];
+ ServerConfig serverConfig = loadConfig(confPath);
+ GravitonServer server = new GravitonServer(serverConfig);
server.initialize();
try {
@@ -124,4 +121,20 @@ public class GravitonServer extends ResourceConfig {
LOG.error("Error while stopping Graviton Server", e);
}
}
+
+ static ServerConfig loadConfig(String confPath) {
+ ServerConfig serverConfig = new ServerConfig();
+ try {
+ if (confPath.isEmpty()) {
+ // Load default conf
+ serverConfig.loadFromFile(CONF_FILE);
+ } else {
+ Properties properties = serverConfig.loadPropertiesFromFile(new File(confPath));
+ serverConfig.loadFromProperties(properties);
+ }
+ } catch (Exception exception) {
+ throw new IllegalArgumentException("Failed to load conf from file " + confPath, exception);
+ }
+ return serverConfig;
+ }
}
diff --git a/server/src/test/java/com/datastrato/graviton/server/TestGravitonServer.java b/server/src/test/java/com/datastrato/graviton/server/TestGravitonServer.java
index 5525fbdac8..e23100cad9 100644
--- a/server/src/test/java/com/datastrato/graviton/server/TestGravitonServer.java
+++ b/server/src/test/java/com/datastrato/graviton/server/TestGravitonServer.java
@@ -6,6 +6,7 @@ package com.datastrato.graviton.server;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import java.io.File;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -16,7 +17,14 @@ public class TestGravitonServer {
@BeforeEach
public void setUp() {
- gravitonServer = new GravitonServer();
+ String confPath =
+ System.getenv("GRAVITON_HOME")
+ + File.separator
+ + "conf"
+ + File.separator
+ + "graviton.conf.template";
+ ServerConfig serverConfig = GravitonServer.loadConfig(confPath);
+ gravitonServer = new GravitonServer(serverConfig);
}
@AfterEach