Skip to content

Commit

Permalink
Run integration test with a given JDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Torch3333 committed May 21, 2024
1 parent 90f23ef commit d10c9d5
Show file tree
Hide file tree
Showing 14 changed files with 460 additions and 97 deletions.
263 changes: 218 additions & 45 deletions .github/workflows/ci.yaml

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ subprojects {
// apply plugin: 'jacoco'
apply plugin: 'java-library-distribution'
apply plugin: 'com.diffplug.spotless'
apply plugin: 'com.scalar.db.jdk-configuration'

project.version = '4.0.0-SNAPSHOT'

Expand Down Expand Up @@ -53,10 +54,9 @@ subprojects {
log4jVersion = '2.23.1'
stefanbirknerSystemLambdaVersion = '1.2.1'
spotbugsPluginVersion = '5.2.5'
errorpronePluginVersion = '2.0.2'
errorpronePluginVersion = '3.1.0'
protobufPluginVersion = '0.8.19'
shadowPluginVersion = '7.1.2'
dockerPluginVersion = '0.34.0'
// Make JDK11+ use the same version as JDK8 uses
googleJavaFormatVersion = '1.7'
}
Expand All @@ -70,12 +70,11 @@ subprojects {
testLogging.showStandardStreams = true
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

group = "com.scalar-labs"

java {
sourceCompatibility = JavaLanguageVersion.of(8)
targetCompatibility = JavaLanguageVersion.of(8)
withJavadocJar()
withSourcesJar()
}
Expand All @@ -98,3 +97,4 @@ subprojects {
duplicatesStrategy DuplicatesStrategy.EXCLUDE
}
}

26 changes: 26 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
plugins {
id 'java-gradle-plugin'
id "com.diffplug.spotless" version "6.13.0"
}

repositories {
mavenCentral()
}

gradlePlugin {
plugins {
jdkConfiguration {
id = 'com.scalar.db.jdk-configuration'
implementationClass = 'com.scalar.db.JdkConfigurationPlugin'
}
}
}

spotless {
java {
target 'src/*/java/**/*.java'
importOrder()
removeUnusedImports()
googleJavaFormat("1.7")
}
}
137 changes: 137 additions & 0 deletions buildSrc/src/main/java/com/scalar/db/JdkConfigurationPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package com.scalar.db;

import java.util.Objects;
import java.util.function.Consumer;
import javax.annotation.Nullable;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.api.tasks.testing.Test;
import org.gradle.jvm.toolchain.JavaLanguageVersion;
import org.gradle.jvm.toolchain.JavaToolchainService;
import org.gradle.jvm.toolchain.JvmVendorSpec;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Plugin configuring compilation and integration test tasks to use a given SDK defined by the following Gradle properties:
* <ul>
* <li> `compilationJavaVendor` : configure the SDK vendor used by compilation tasks </li>
* <li> `integrationTestJavaVersion` : configure all tasks name starting with "integrationTest" to run with the given SDK version </li>
* <li> `integrationTestJavaVendor` : configure all tasks name starting with "integrationTest" to run with the given SDK vendor </li>
</ul>
*
* Usage example using the CLI :
* <pre><code>
* gradle integrationTestJdbc -PcompilationJavaVendor=amazon -PintegrationTestJavaVersion=11 -PintegrationJavaVendor=temurin
* </code></pre>
*/
public class JdkConfigurationPlugin implements Plugin<Project> {
private static final Logger logger = LoggerFactory.getLogger(JdkConfigurationPlugin.class);

private static final JavaLanguageVersion COMPILATION_JAVA_VERSION = JavaLanguageVersion.of(8);
@Nullable private JvmVendorSpec compilationJavaVendor;
@Nullable private JavaLanguageVersion integrationTestJavaVersion;
@Nullable private JvmVendorSpec integrationTestJavaVendor;

@Override
public void apply(@NotNull Project project) {
parseInputParameters(project);
configureJdkForCompilationTasks(project);
configureJdkForIntegrationTestTasks(project);
}

private void configureJdkForCompilationTasks(Project project) {
project
.getTasks()
.withType(JavaCompile.class)
.configureEach(
javaCompileTask -> {
javaCompileTask
.getJavaCompiler()
.set(
getJavaToolchainService(project)
.compilerFor(
config -> {
config.getLanguageVersion().set(COMPILATION_JAVA_VERSION);
logVersion(javaCompileTask.getName(), COMPILATION_JAVA_VERSION);
if (compilationJavaVendor != null) {
config.getVendor().set(compilationJavaVendor);
logVendor(javaCompileTask.getName(), compilationJavaVendor);
}
}));
});
}

private void configureJdkForIntegrationTestTasks(Project project) {
project
.getTasks()
.withType(Test.class)
.matching(testTask -> testTask.getName().startsWith("integrationTest"))
.configureEach(
integrationTestTask ->
integrationTestTask
.getJavaLauncher()
.set(
getJavaToolchainService(project)
.launcherFor(
config -> {
if (integrationTestJavaVersion == null) {
return;
}
config.getLanguageVersion().set(integrationTestJavaVersion);
logVersion(
integrationTestTask.getName(), integrationTestJavaVersion);
if (integrationTestJavaVendor != null) {
config.getVendor().set(integrationTestJavaVendor);
logVendor(
integrationTestTask.getName(), integrationTestJavaVendor);
}
})));
}

private static @NotNull JavaToolchainService getJavaToolchainService(Project project) {
return project.getExtensions().getByType(JavaToolchainService.class);
}

private void parseInputParameters(Project project) {
parseVendor(project, "compilationJavaVendor", (vendor) -> compilationJavaVendor = vendor);
parseVendor(
project, "integrationTestJavaVendor", (vendor) -> integrationTestJavaVendor = vendor);
if (project.hasProperty("integrationTestJavaVersion")) {
integrationTestJavaVersion =
JavaLanguageVersion.of(Objects.toString(project.property("integrationTestJavaVersion")));
}
if (integrationTestJavaVersion == null && integrationTestJavaVendor != null) {
throw new IllegalArgumentException(
"When configuring the JDK vendor to run integration test, you also need to set the JDK version using the \"integrationTestJavaVersion\" project property.");
}
}

private void parseVendor(
Project project, String parameterName, Consumer<JvmVendorSpec> attributeSetter) {
if (!project.getRootProject().hasProperty(parameterName)) {
return;
}
String propertyValue = Objects.toString(project.property(parameterName));
switch (propertyValue) {
case "corretto":
attributeSetter.accept(JvmVendorSpec.AMAZON);
break;
case "temurin":
attributeSetter.accept(JvmVendorSpec.ADOPTIUM);
break;
default:
attributeSetter.accept(JvmVendorSpec.matching(propertyValue));
}
}

private void logVersion(String taskName, Object version) {
logger.debug("Configure task '{}' to use JDK version {}", taskName, version);
}

private void logVendor(String taskName, JvmVendorSpec vendor) {
logger.debug("Configure task '{}' to use {} JDK vendor", taskName, vendor);
}
}
16 changes: 9 additions & 7 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'net.ltgt.errorprone' version "${errorpronePluginVersion}"
id 'maven-publish'
id 'signing'
id 'base'
}

sourceSets {
Expand Down Expand Up @@ -126,15 +127,14 @@ javadoc {
title = "ScalarDB"
}


task integrationTestCassandra(type: Test) {
description = 'Runs the integration tests for Cassandra.'
group = 'verification'
testClassesDirs = sourceSets.integrationTestCassandra.output.classesDirs
classpath = sourceSets.integrationTestCassandra.runtimeClasspath
outputs.upToDateWhen { false } // ensures integration tests are run every time when called
options {
systemProperties(System.getProperties())
systemProperties(System.getProperties().findAll{it.key.toString().startsWith("scalardb")})
}
}

Expand All @@ -145,7 +145,7 @@ task integrationTestCosmos(type: Test) {
classpath = sourceSets.integrationTestCosmos.runtimeClasspath
outputs.upToDateWhen { false } // ensures integration tests are run every time when called
options {
systemProperties(System.getProperties())
systemProperties(System.getProperties().findAll{it.key.toString().startsWith("scalardb")})
}
maxParallelForks = 3
jvmArgs '-XX:MaxDirectMemorySize=4g', '-Xmx4g'
Expand All @@ -158,7 +158,7 @@ task integrationTestDynamo(type: Test) {
classpath = sourceSets.integrationTestDynamo.runtimeClasspath
outputs.upToDateWhen { false } // ensures integration tests are run every time when called
options {
systemProperties(System.getProperties())
systemProperties(System.getProperties().findAll{it.key.toString().startsWith("scalardb")})
}
maxParallelForks = 10
}
Expand All @@ -170,7 +170,7 @@ task integrationTestJdbc(type: Test) {
classpath = sourceSets.integrationTestJdbc.runtimeClasspath
outputs.upToDateWhen { false } // ensures integration tests are run every time when called
options {
systemProperties(System.getProperties())
systemProperties(System.getProperties().findAll{it.key.toString().startsWith("scalardb")})
}
}

Expand All @@ -181,7 +181,7 @@ task integrationTestMultiStorage(type: Test) {
classpath = sourceSets.integrationTestMultiStorage.runtimeClasspath
outputs.upToDateWhen { false } // ensures integration tests are run every time when called
options {
systemProperties(System.getProperties())
systemProperties(System.getProperties().findAll{it.key.toString().startsWith("scalardb")})
}
}

Expand Down Expand Up @@ -227,7 +227,9 @@ check.dependsOn += spotbugsMain
check.dependsOn += spotbugsTest
check.dependsOn += spotbugsIntegrationTest

archivesBaseName = "scalardb"
base {
archivesName = "scalardb"
}

// for archiving and uploading to maven central
publishing {
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repositories {
mavenCentral()
}

mainClassName = "sample.ElectronicMoneyMain"
mainClass = "sample.ElectronicMoneyMain"

dependencies {
implementation 'com.scalar-labs:scalardb:3.12.2'
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 2 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
25 changes: 7 additions & 18 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

Expand All @@ -37,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand All @@ -51,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
Expand All @@ -61,28 +64,14 @@ echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
5 changes: 4 additions & 1 deletion integration-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'net.ltgt.errorprone' version "${errorpronePluginVersion}"
id 'maven-publish'
id 'signing'
id 'base'
}

dependencies {
Expand Down Expand Up @@ -52,7 +53,9 @@ spotbugsTest.reports {
}
spotbugsTest.excludeFilter = file("${project.rootDir}/gradle/spotbugs-exclude.xml")

archivesBaseName = "scalardb-integration-test"
base {
archivesName = "scalardb-integration-test"
}

// for archiving and uploading to maven central
publishing {
Expand Down
Loading

0 comments on commit d10c9d5

Please sign in to comment.