diff --git a/.gitignore b/.gitignore index eb2d5fe..f749ca3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,11 @@ bin/ # Gradle build directory build/ +# Maven build directory +target/ + +# IntelliJ IDEA +*.iml + # Do not ignore .gitignore !.gitignore diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..3d1f395 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,125 @@ +pipeline { + agent { + label 'gcloud-build--rocky-linux-8--x64' + } + + options { + buildDiscarder(logRotator(numToKeepStr: '10')) + timeout(time: 1, unit: 'HOURS') + timestamps() + disableConcurrentBuilds() + } + + environment { + JAVA_HOME = '/opt/corretto_java17' + PATH = "${JAVA_HOME}/bin:${env.PATH}" + VOLTDB_IMAGE = "${params.VOLTDB_IMAGE ?: 'voltdb/voltdb-enterprise:15.1.0'}" + } + + parameters { + string( + name: 'VOLTDB_IMAGE', + defaultValue: 'voltdb/voltdb-enterprise:15.1.0', + description: 'VoltDB Docker image to use for integration tests' + ) + booleanParam( + name: 'SKIP_INTEGRATION_TESTS', + defaultValue: false, + description: 'Skip integration tests' + ) + } + + stages { + stage('Checkout') { + steps { + checkout scm + } + } + + stage('Build') { + steps { + sh 'mvn clean compile test-compile -DskipTests' + } + } + + stage('Unit Tests') { + steps { + sh 'mvn test' + } + post { + always { + junit testResults: '**/target/surefire-reports/*.xml', allowEmptyResults: true + } + } + } + + stage('Package') { + steps { + sh 'mvn package -DskipTests' + } + post { + success { + archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true, allowEmptyArchive: true + } + } + } + + stage('Integration Tests') { + when { + expression { return !params.SKIP_INTEGRATION_TESTS } + } + steps { + withCredentials([ + usernamePassword(credentialsId: 'dockerhub', usernameVariable: 'DOCKER_CREDS_USR', passwordVariable: 'DOCKER_CREDS_PSW'), + string(credentialsId: 'VOLTDB_LICENSE1', variable: 'VOLTDB_LICENSE_CONTENT') + ]) { + sh ''' + # Login to Docker Hub + echo "${DOCKER_CREDS_PSW}" | docker login -u "${DOCKER_CREDS_USR}" --password-stdin + + # Ensure Docker is available + docker info + + # Pull VoltDB image + echo "Using VoltDB image: ${VOLTDB_IMAGE}" + docker pull ${VOLTDB_IMAGE} + + # Write license to file (decode base64) + echo "${VOLTDB_LICENSE_CONTENT}" | base64 -d > license.xml + ''' + + // Run integration tests with license + sh ''' + export PATH="${JAVA_HOME}/bin:${PATH}" + export VOLTDB_LICENSE="${WORKSPACE}/license.xml" + mvn verify -DskipUTs + ''' + } + } + post { + always { + junit testResults: '**/target/failsafe-reports/*.xml', allowEmptyResults: true + sh 'rm -f license.xml || true' + sh 'docker logout || true' + } + } + } + } + + post { + always { + // Clean up Docker containers + sh ''' + docker ps -q --filter "ancestor=${VOLTDB_IMAGE}" | xargs -r docker stop || true + docker container prune -f || true + ''' + cleanWs() + } + success { + echo 'Build completed successfully!' + } + failure { + echo 'Build failed!' + } + } +} diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 8cc529e..0000000 --- a/build.gradle +++ /dev/null @@ -1,80 +0,0 @@ -ext { - // lambda to generate the artifact name from a project instance - artifactName = { project -> "$rootProject.name-${project.name.replaceAll("\\p{Upper}") { "-${it.toLowerCase()}" }}" } -} - -subprojects { - apply plugin: 'java' - apply plugin: 'eclipse' - apply plugin: 'idea' - - repositories { - mavenCentral() - } - - dependencies { - if (project.hasProperty('voltdbJar')) { - implementation project.parent.files(voltdbJar) - } else { - print('In order to build against a local voltdb jar set the property: -PvoltdbJar=') - implementation 'org.voltdb:voltdb:9.3.2' - } - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' - testImplementation 'org.mockito:mockito-junit-jupiter:3.7.7' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' - } - - java { - withJavadocJar() - withSourcesJar() - } - - test { - useJUnitPlatform() - } - - archivesBaseName = artifactName(project) - - eclipse { - project { - name = archivesBaseName - } - } - - jar.manifest { - attributes('Implementation-Title': archivesBaseName, 'Implementation-Version': version) - } -} - -// Create "all" jars for classes, sources and javadoc -task jar(type: Jar, dependsOn: subprojects.tasks['classes']) { - archiveVersion = project.version - archiveBaseName = "$project.name-all" - destinationDirectory = file("$project.buildDir/libs") - - from subprojects.sourceSets.main.output -} - -task sourceJar(type: Jar) { - archiveVersion = project.version - archiveBaseName = "$project.name-all" - archiveClassifier = 'sources' - destinationDirectory = file("$project.buildDir/libs") - - from subprojects.sourceSets.main.java -} - -task javadocJar(type: Jar, dependsOn: subprojects.tasks['javadoc']) { - archiveVersion = project.version - archiveBaseName = "$project.name-all" - archiveClassifier = 'javadoc' - destinationDirectory = file("$project.buildDir/libs") - - from subprojects.tasks['javadoc'] -} - -task clean(type: Delete) { - delete project.buildDir -} - -task build(dependsOn: [jar, sourceJar, javadocJar]) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index e708b1c..0000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 28ff446..0000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew deleted file mode 100755 index 4f906e0..0000000 --- a/gradlew +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# 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 -# -# https://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. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -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 - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -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 - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index ac1b06f..0000000 --- a/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -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" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -: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 %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..67c412a --- /dev/null +++ b/pom.xml @@ -0,0 +1,124 @@ + + + 4.0.0 + + org.voltdb + voltdb-task-examples + 1.0.0-SNAPSHOT + pom + + VoltDB Task Examples + Example VoltDB task implementations + + + tasks/dr-producer-latency + tasks/growing-commandlog + + + + 17 + 17 + UTF-8 + 5.7.0 + 3.7.7 + 33.0.0-jre + 15.1.0 + 15.3.0-SNAPSHOT + 1.8.0 + 15.1.0 + + + + + + org.voltdb + voltdbclient + ${voltdb.client.version} + + + org.voltdb + volt-task-api + ${voltdb.task.api.version} + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.mockito + mockito-junit-jupiter + ${mockito.version} + test + + + org.voltdb + volt-testcontainer + ${volt.testcontainer.version} + test + + + com.google.guava + guava + ${guava.version} + test + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + ${maven.compiler.source} + ${maven.compiler.target} + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + org.apache.maven.plugins + maven-source-plugin + 3.3.0 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.1.2 + + + + integration-test + verify + + + + + + + + diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index b94d004..0000000 --- a/settings.gradle +++ /dev/null @@ -1,10 +0,0 @@ -rootProject.name = 'tasks' - -include 'drProducerLatency' -include 'growingCommandlog' - -rootProject.children.each {project -> - String projectName = project.name.replaceAll("\\p{Upper}") { "-${it.toLowerCase()}" } - project.projectDir = new File("tasks", projectName) - assert project.projectDir.isDirectory() -} diff --git a/tasks/dr-producer-latency/pom.xml b/tasks/dr-producer-latency/pom.xml new file mode 100644 index 0000000..ec4d93a --- /dev/null +++ b/tasks/dr-producer-latency/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + + + org.voltdb + voltdb-task-examples + 1.0.0-SNAPSHOT + ../../pom.xml + + + dr-producer-latency + DR Producer Latency Task + VoltDB task to monitor DR producer latency + + + + org.voltdb + voltdbclient + + + org.voltdb + volt-task-api + + + org.junit.jupiter + junit-jupiter-api + + + org.junit.jupiter + junit-jupiter-engine + + + org.mockito + mockito-junit-jupiter + + + org.voltdb + volt-testcontainer + test + + + com.google.guava + guava + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + diff --git a/tasks/dr-producer-latency/src/test/java/voltdb/tasks/DrProducerLatencyIT.java b/tasks/dr-producer-latency/src/test/java/voltdb/tasks/DrProducerLatencyIT.java new file mode 100644 index 0000000..eb09101 --- /dev/null +++ b/tasks/dr-producer-latency/src/test/java/voltdb/tasks/DrProducerLatencyIT.java @@ -0,0 +1,164 @@ +/* This file is part of VoltDB. + * Copyright (C) 2019-2024 VoltDB Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +package voltdb.tasks; + +import org.junit.jupiter.api.Test; +import org.voltdb.VoltTable; +import org.voltdb.client.Client2; +import org.voltdb.client.ClientResponse; +import org.voltdbtest.testcontainer.VoltDBCluster; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Integration test for DrProducerLatency task. + * Tests loading the task class and creating a task using CREATE TASK DDL. + */ +public class DrProducerLatencyIT extends IntegrationTestBase { + + private static final String TASK_NAME = "dr_latency_monitor"; + + @Test + public void testCreateAndValidateTask() { + VoltDBCluster db = null; + try { + // Start VoltDB and load task classes + Client2 client; + if (isTestContainerMode()) { + db = createTestContainer(); + startAndLoadClasses(db); + client = db.getClient2(); + } else { + client = createExternalClient(); + // For external mode, classes should already be loaded + } + + // Create the task using CREATE TASK DDL + // Parameters: warningTimestampDelta, warningBacklog, errorTimestampDelta, errorBacklog, rateLimitMs + String createTaskDDL = String.format( + "CREATE TASK %s ON SCHEDULE EVERY 1 MINUTES " + + "PROCEDURE FROM CLASS voltdb.tasks.DrProducerLatency WITH (500, 500, 1000, 1000, 60000) " + + "ON ERROR LOG", + TASK_NAME); + + System.out.println("Creating task: " + createTaskDDL); + ClientResponse response = client.callProcedureSync("@AdHoc", createTaskDDL); + assertEquals(ClientResponse.SUCCESS, response.getStatus(), + "CREATE TASK should succeed: " + response.getStatusString()); + + // Verify the task was created by checking @Statistics TASK + System.out.println("Verifying task exists..."); + response = client.callProcedureSync("@Statistics", "TASK", 0); + assertEquals(ClientResponse.SUCCESS, response.getStatus(), + "@Statistics TASK should succeed"); + + VoltTable taskStats = response.getResults()[0]; + assertNotNull(taskStats, "Task statistics should not be null"); + + boolean taskFound = false; + while (taskStats.advanceRow()) { + String taskName = taskStats.getString("TASK_NAME"); + if (TASK_NAME.equalsIgnoreCase(taskName)) { + taskFound = true; + String state = taskStats.getString("STATE"); + System.out.println("Found task: " + taskName + ", state: " + state); + // Task should be in RUNNING state + assertTrue("RUNNING".equalsIgnoreCase(state) || "IDLE".equalsIgnoreCase(state), + "Task should be RUNNING or IDLE, but was: " + state); + break; + } + } + assertTrue(taskFound, "Task '" + TASK_NAME + "' should exist in @Statistics TASK"); + + // Test parameter validation by trying to create a task with invalid parameters + String invalidTaskDDL = String.format( + "CREATE TASK invalid_task ON SCHEDULE EVERY 1 MINUTES " + + "PROCEDURE FROM CLASS voltdb.tasks.DrProducerLatency WITH (-1, 500, 1000, 1000, 60000) " + + "ON ERROR LOG"); + + System.out.println("Testing invalid parameters..."); + boolean validationFailed = false; + try { + response = client.callProcedureSync("@AdHoc", invalidTaskDDL); + // If we get here without exception, check status + validationFailed = (response.getStatus() != ClientResponse.SUCCESS); + } catch (Exception e) { + // VoltDB throws ProcCallException for validation failures + validationFailed = e.getMessage().contains("Warning time stamp delta"); + System.out.println("Parameter validation correctly rejected invalid task: " + e.getMessage()); + } + assertTrue(validationFailed, "Task with invalid parameters should fail validation"); + + // Drop the task + System.out.println("Dropping task..."); + String dropTaskDDL = "DROP TASK " + TASK_NAME; + response = client.callProcedureSync("@AdHoc", dropTaskDDL); + assertEquals(ClientResponse.SUCCESS, response.getStatus(), + "DROP TASK should succeed: " + response.getStatusString()); + + // Verify task was dropped + response = client.callProcedureSync("@Statistics", "TASK", 0); + taskStats = response.getResults()[0]; + taskFound = false; + while (taskStats.advanceRow()) { + if (TASK_NAME.equalsIgnoreCase(taskStats.getString("TASK_NAME"))) { + taskFound = true; + break; + } + } + assertTrue(!taskFound, "Task should no longer exist after DROP TASK"); + + System.out.println("\n*** DrProducerLatencyIT PASSED ***\n"); + + } catch (Exception e) { + throw new RuntimeException("Test failed", e); + } finally { + shutdownIfNeeded(db); + } + } + + @Test + public void testValidateParametersStatic() { + // Test the static validateParameters method directly + // Valid parameters should return null + String result = DrProducerLatency.validateParameters(null, 500, 500, 1000, 1000, 5000); + assertEquals(null, result, "Valid parameters should return null"); + + // Invalid warningTimestampDelta + result = DrProducerLatency.validateParameters(null, -1, 0, 0, 0, 0); + assertNotNull(result, "Negative warningTimestampDelta should fail"); + assertTrue(result.contains(DrProducerLatency.MSG_WARNING_TSD_POSITIVE), + "Error message should mention warning time stamp delta"); + + // Warning > Error threshold + result = DrProducerLatency.validateParameters(null, 200, 0, 100, 0, 0); + assertNotNull(result, "Warning > Error should fail"); + assertTrue(result.contains(DrProducerLatency.MSG_WARNING_TSD_GT_ERROR), + "Error message should mention warning > error"); + + System.out.println("*** Static validation tests PASSED ***"); + } +} diff --git a/tasks/dr-producer-latency/src/test/java/voltdb/tasks/DrProducerLatencyTest.java b/tasks/dr-producer-latency/src/test/java/voltdb/tasks/DrProducerLatencyTest.java index aae5779..f06806f 100644 --- a/tasks/dr-producer-latency/src/test/java/voltdb/tasks/DrProducerLatencyTest.java +++ b/tasks/dr-producer-latency/src/test/java/voltdb/tasks/DrProducerLatencyTest.java @@ -76,13 +76,13 @@ public void validateParameters() { assertNull(DrProducerLatency.validateParameters(null, 500, 500, 1000, 1000, 0)); // Test single invalid parameter - assertEquals(DrProducerLatency.validateParameters(null, -1, 0, 0, 0, 0), MSG_WARNING_TSD_POSITIVE); - assertEquals(DrProducerLatency.validateParameters(null, 0, -1, 0, 0, 0), MSG_WARNING_BACKLOG_POSITIVE); - assertEquals(DrProducerLatency.validateParameters(null, 0, 0, -1, 0, 0), MSG_ERROR_TSD_POSITIVE); - assertEquals(DrProducerLatency.validateParameters(null, 0, 0, 0, -1, 0), MSG_ERROR_BACKLOG_POSITIVE); - assertEquals(DrProducerLatency.validateParameters(null, 200, 0, 100, 0, 0), MSG_WARNING_TSD_GT_ERROR); - assertEquals(DrProducerLatency.validateParameters(null, 0, 200, 0, 100, 0), MSG_WARNING_BACKLOG_GT_ERROR); - assertEquals(DrProducerLatency.validateParameters(null, 0, 0, 0, 0, -1), MSG_RATE_LIMIT_POSITIVE); + assertEquals(MSG_WARNING_TSD_POSITIVE, DrProducerLatency.validateParameters(null, -1, 0, 0, 0, 0)); + assertEquals(MSG_WARNING_BACKLOG_POSITIVE, DrProducerLatency.validateParameters(null, 0, -1, 0, 0, 0)); + assertEquals(MSG_ERROR_TSD_POSITIVE, DrProducerLatency.validateParameters(null, 0, 0, -1, 0, 0)); + assertEquals(MSG_ERROR_BACKLOG_POSITIVE, DrProducerLatency.validateParameters(null, 0, 0, 0, -1, 0)); + assertEquals(MSG_WARNING_TSD_GT_ERROR, DrProducerLatency.validateParameters(null, 200, 0, 100, 0, 0)); + assertEquals(MSG_WARNING_BACKLOG_GT_ERROR, DrProducerLatency.validateParameters(null, 0, 200, 0, 100, 0)); + assertEquals(MSG_RATE_LIMIT_POSITIVE, DrProducerLatency.validateParameters(null, 0, 0, 0, 0, -1)); // Test multiple invalid parameters assertErrorMessageContains(DrProducerLatency.validateParameters(null, -1, 0, -1, 0, 0), diff --git a/tasks/dr-producer-latency/src/test/java/voltdb/tasks/IntegrationTestBase.java b/tasks/dr-producer-latency/src/test/java/voltdb/tasks/IntegrationTestBase.java new file mode 100644 index 0000000..934bfe6 --- /dev/null +++ b/tasks/dr-producer-latency/src/test/java/voltdb/tasks/IntegrationTestBase.java @@ -0,0 +1,178 @@ +/* This file is part of VoltDB. + * Copyright (C) 2019-2024 VoltDB Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +package voltdb.tasks; + +import org.voltdb.client.Client2; +import org.voltdb.client.Client2Config; +import org.voltdb.client.ClientFactory; +import org.voltdb.client.ClientResponse; +import org.voltdbtest.testcontainer.VoltDBCluster; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Paths; +import java.util.Properties; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Base class for VoltDB task integration tests using Testcontainers. + */ +public class IntegrationTestBase { + + private static final Properties props = new Properties(); + static { + try (InputStream input = IntegrationTestBase.class.getClassLoader() + .getResourceAsStream("test.properties")) { + if (input != null) { + props.load(input); + } + } catch (IOException e) { + // Use defaults + } + } + + public String getImageVersion() { + return props.getProperty("voltdb.image.version", "15.2.0"); + } + + public String getTestMode() { + return props.getProperty("voltdb.test.mode", "testcontainer"); + } + + public boolean isTestContainerMode() { + return "testcontainer".equalsIgnoreCase(getTestMode()); + } + + public boolean isShutdownOnCompletion() { + return Boolean.parseBoolean( + props.getProperty("voltdb.testcontainer.shutdown", "true")); + } + + public String getExternalHost() { + return props.getProperty("voltdb.external.host", "localhost"); + } + + public int getExternalPort() { + return Integer.parseInt( + props.getProperty("voltdb.external.port", "21211")); + } + + /** + * Creates a VoltDB testcontainer cluster. + */ + public VoltDBCluster createTestContainer() { + return new VoltDBCluster( + getLicensePath(), + "voltdb/voltdb-enterprise:" + getImageVersion(), + null // no extra lib directory needed + ); + } + + /** + * Starts the container and loads the task classes from the project JAR. + */ + public void startAndLoadClasses(VoltDBCluster db) { + try { + db.start(); + File jar = getProjectJar(); + if (jar != null && jar.exists()) { + System.out.println("Loading classes from: " + jar.getAbsolutePath()); + ClientResponse response = db.loadClasses(jar.getAbsolutePath()); + assertEquals(ClientResponse.SUCCESS, response.getStatus(), + "Load classes must succeed: " + response.getStatusString()); + } else { + throw new RuntimeException("Project JAR not found. Run 'mvn package -DskipTests' first."); + } + } catch (Exception e) { + throw new RuntimeException("Failed to start container and load classes", e); + } + } + + /** + * Creates a client connected to an external VoltDB instance. + */ + public Client2 createExternalClient() throws Exception { + Client2Config config = new Client2Config(); + Client2 client = ClientFactory.createClient(config); + String host = getExternalHost(); + int port = getExternalPort(); + System.out.println("Connecting to external VoltDB at " + host + ":" + port); + client.connectSync(host, port); + return client; + } + + /** + * Shuts down the testcontainer if configured to do so. + */ + public void shutdownIfNeeded(VoltDBCluster db) { + if (db != null && isShutdownOnCompletion()) { + System.out.println("Shutting down VoltDB testcontainer..."); + db.shutdown(); + } else if (db != null) { + System.out.println("Keeping VoltDB testcontainer running (shutdown disabled)."); + } + } + + /** + * Gets the project JAR path from test.properties or uses default naming. + */ + protected File getProjectJar() { + String jarPath = props.getProperty("project.jar.path"); + if (jarPath != null) { + File jar = new File(jarPath); + if (jar.exists()) { + return jar; + } + } + // Try default Maven target directory + File targetDir = new File("target"); + if (targetDir.exists()) { + File[] jars = targetDir.listFiles((dir, name) -> + name.endsWith(".jar") && !name.contains("-sources") && !name.contains("-javadoc")); + if (jars != null && jars.length > 0) { + return jars[0]; + } + } + return null; + } + + /** + * Gets the VoltDB license path from environment or default location. + */ + protected String getLicensePath() { + String envLicense = System.getenv("VOLTDB_LICENSE"); + if (envLicense != null) { + File file = Paths.get(envLicense).toAbsolutePath().toFile(); + if (file.exists()) { + System.out.println("Using license from VOLTDB_LICENSE: " + file.getAbsolutePath()); + return file.getAbsolutePath(); + } + } + String defaultPath = "/tmp/voltdb-license.xml"; + System.out.println("Using default license path: " + defaultPath); + return defaultPath; + } +} diff --git a/tasks/dr-producer-latency/src/test/resources/test.properties b/tasks/dr-producer-latency/src/test/resources/test.properties new file mode 100644 index 0000000..761816b --- /dev/null +++ b/tasks/dr-producer-latency/src/test/resources/test.properties @@ -0,0 +1,18 @@ +# VoltDB Testcontainer Configuration + +# VoltDB Enterprise image version +voltdb.image.version=15.1.0 + +# VoltDB test mode: "testcontainer" (default) or "external" +voltdb.test.mode=testcontainer + +# External VoltDB connection settings (used when voltdb.test.mode=external) +voltdb.external.host=localhost +voltdb.external.port=21211 + +# Testcontainer shutdown behavior (used when voltdb.test.mode=testcontainer) +# Set to "false" to keep the container running after tests for debugging +voltdb.testcontainer.shutdown=true + +# Project JAR path (relative to module directory) +project.jar.path=target/dr-producer-latency-1.0.0-SNAPSHOT.jar diff --git a/tasks/growing-commandlog/pom.xml b/tasks/growing-commandlog/pom.xml new file mode 100644 index 0000000..c68b344 --- /dev/null +++ b/tasks/growing-commandlog/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + + + org.voltdb + voltdb-task-examples + 1.0.0-SNAPSHOT + ../../pom.xml + + + growing-commandlog + Growing Command Log Task + VoltDB task to monitor growing command log segments + + + + org.voltdb + voltdbclient + + + org.voltdb + volt-task-api + + + org.junit.jupiter + junit-jupiter-api + + + org.junit.jupiter + junit-jupiter-engine + + + org.mockito + mockito-junit-jupiter + + + org.voltdb + volt-testcontainer + + + com.google.guava + guava + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + diff --git a/tasks/growing-commandlog/src/test/java/voltdb/tasks/GrowingCommandlogIT.java b/tasks/growing-commandlog/src/test/java/voltdb/tasks/GrowingCommandlogIT.java new file mode 100644 index 0000000..846d25b --- /dev/null +++ b/tasks/growing-commandlog/src/test/java/voltdb/tasks/GrowingCommandlogIT.java @@ -0,0 +1,167 @@ +/* This file is part of VoltDB. + * Copyright (C) 2021-2024 VoltDB Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +package voltdb.tasks; + +import org.junit.jupiter.api.Test; +import org.voltdb.VoltTable; +import org.voltdb.client.Client2; +import org.voltdb.client.ClientResponse; +import org.voltdbtest.testcontainer.VoltDBCluster; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Integration test for GrowingCommandlog task. + * Tests loading the task class and creating a task using CREATE TASK DDL. + */ +public class GrowingCommandlogIT extends IntegrationTestBase { + + private static final String TASK_NAME = "commandlog_monitor"; + + @Test + public void testCreateAndValidateTask() { + VoltDBCluster db = null; + try { + // Start VoltDB and load task classes + Client2 client; + if (isTestContainerMode()) { + db = createTestContainer(); + startAndLoadClasses(db); + client = db.getClient2(); + } else { + client = createExternalClient(); + // For external mode, classes should already be loaded + } + + // Create the task using CREATE TASK DDL + // Parameters: maxSegmentCount (warning threshold for in-use segments) + String createTaskDDL = String.format( + "CREATE TASK %s ON SCHEDULE EVERY 5 MINUTES " + + "PROCEDURE FROM CLASS voltdb.tasks.GrowingCommandlog WITH (20) " + + "ON ERROR LOG", + TASK_NAME); + + System.out.println("Creating task: " + createTaskDDL); + ClientResponse response = client.callProcedureSync("@AdHoc", createTaskDDL); + assertEquals(ClientResponse.SUCCESS, response.getStatus(), + "CREATE TASK should succeed: " + response.getStatusString()); + + // Verify the task was created by checking @Statistics TASK + System.out.println("Verifying task exists..."); + response = client.callProcedureSync("@Statistics", "TASK", 0); + assertEquals(ClientResponse.SUCCESS, response.getStatus(), + "@Statistics TASK should succeed"); + + VoltTable taskStats = response.getResults()[0]; + assertNotNull(taskStats, "Task statistics should not be null"); + + boolean taskFound = false; + while (taskStats.advanceRow()) { + String taskName = taskStats.getString("TASK_NAME"); + if (TASK_NAME.equalsIgnoreCase(taskName)) { + taskFound = true; + String state = taskStats.getString("STATE"); + System.out.println("Found task: " + taskName + ", state: " + state); + // Task should be in RUNNING state + assertTrue("RUNNING".equalsIgnoreCase(state) || "IDLE".equalsIgnoreCase(state), + "Task should be RUNNING or IDLE, but was: " + state); + break; + } + } + assertTrue(taskFound, "Task '" + TASK_NAME + "' should exist in @Statistics TASK"); + + // Test parameter validation by trying to create a task with invalid parameters + String invalidTaskDDL = String.format( + "CREATE TASK invalid_task ON SCHEDULE EVERY 1 MINUTES " + + "PROCEDURE FROM CLASS voltdb.tasks.GrowingCommandlog WITH (0) " + + "ON ERROR LOG"); + + System.out.println("Testing invalid parameters (maxSegmentCount=0)..."); + boolean validationFailed = false; + try { + response = client.callProcedureSync("@AdHoc", invalidTaskDDL); + // If we get here without exception, check status + validationFailed = (response.getStatus() != ClientResponse.SUCCESS); + } catch (Exception e) { + // VoltDB throws ProcCallException for validation failures + validationFailed = e.getMessage().contains("max in-use segment count"); + System.out.println("Parameter validation correctly rejected invalid task: " + e.getMessage()); + } + assertTrue(validationFailed, "Task with invalid parameters should fail validation"); + + // Drop the task + System.out.println("Dropping task..."); + String dropTaskDDL = "DROP TASK " + TASK_NAME; + response = client.callProcedureSync("@AdHoc", dropTaskDDL); + assertEquals(ClientResponse.SUCCESS, response.getStatus(), + "DROP TASK should succeed: " + response.getStatusString()); + + // Verify task was dropped + response = client.callProcedureSync("@Statistics", "TASK", 0); + taskStats = response.getResults()[0]; + taskFound = false; + while (taskStats.advanceRow()) { + if (TASK_NAME.equalsIgnoreCase(taskStats.getString("TASK_NAME"))) { + taskFound = true; + break; + } + } + assertTrue(!taskFound, "Task should no longer exist after DROP TASK"); + + System.out.println("\n*** GrowingCommandlogIT PASSED ***\n"); + + } catch (Exception e) { + throw new RuntimeException("Test failed", e); + } finally { + shutdownIfNeeded(db); + } + } + + @Test + public void testValidateParametersStatic() { + // Test the static validateParameters method directly + // Valid parameters should return null + String result = GrowingCommandlog.validateParameters(null, 20); + assertEquals(null, result, "Valid parameters should return null"); + + result = GrowingCommandlog.validateParameters(null, 1); + assertEquals(null, result, "maxSegmentCount=1 should be valid"); + + // Invalid maxSegmentCount (0) + result = GrowingCommandlog.validateParameters(null, 0); + assertNotNull(result, "maxSegmentCount=0 should fail"); + assertTrue(result.contains(GrowingCommandlog.MSG_ERROR_BAD_SEGMENT_CNT), + "Error message should mention bad segment count"); + + // Invalid maxSegmentCount (negative) + result = GrowingCommandlog.validateParameters(null, -1); + assertNotNull(result, "Negative maxSegmentCount should fail"); + assertTrue(result.contains(GrowingCommandlog.MSG_ERROR_BAD_SEGMENT_CNT), + "Error message should mention bad segment count"); + + System.out.println("*** Static validation tests PASSED ***"); + } +} diff --git a/tasks/growing-commandlog/src/test/java/voltdb/tasks/IntegrationTestBase.java b/tasks/growing-commandlog/src/test/java/voltdb/tasks/IntegrationTestBase.java new file mode 100644 index 0000000..573a4ac --- /dev/null +++ b/tasks/growing-commandlog/src/test/java/voltdb/tasks/IntegrationTestBase.java @@ -0,0 +1,178 @@ +/* This file is part of VoltDB. + * Copyright (C) 2021-2024 VoltDB Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +package voltdb.tasks; + +import org.voltdb.client.Client2; +import org.voltdb.client.Client2Config; +import org.voltdb.client.ClientFactory; +import org.voltdb.client.ClientResponse; +import org.voltdbtest.testcontainer.VoltDBCluster; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Paths; +import java.util.Properties; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Base class for VoltDB task integration tests using Testcontainers. + */ +public class IntegrationTestBase { + + private static final Properties props = new Properties(); + static { + try (InputStream input = IntegrationTestBase.class.getClassLoader() + .getResourceAsStream("test.properties")) { + if (input != null) { + props.load(input); + } + } catch (IOException e) { + // Use defaults + } + } + + public String getImageVersion() { + return props.getProperty("voltdb.image.version", "15.3.1"); + } + + public String getTestMode() { + return props.getProperty("voltdb.test.mode", "testcontainer"); + } + + public boolean isTestContainerMode() { + return "testcontainer".equalsIgnoreCase(getTestMode()); + } + + public boolean isShutdownOnCompletion() { + return Boolean.parseBoolean( + props.getProperty("voltdb.testcontainer.shutdown", "true")); + } + + public String getExternalHost() { + return props.getProperty("voltdb.external.host", "localhost"); + } + + public int getExternalPort() { + return Integer.parseInt( + props.getProperty("voltdb.external.port", "21211")); + } + + /** + * Creates a VoltDB testcontainer cluster. + */ + public VoltDBCluster createTestContainer() { + return new VoltDBCluster( + getLicensePath(), + "voltdb/voltdb-enterprise:" + getImageVersion(), + null // no extra lib directory needed + ); + } + + /** + * Starts the container and loads the task classes from the project JAR. + */ + public void startAndLoadClasses(VoltDBCluster db) { + try { + db.start(); + File jar = getProjectJar(); + if (jar != null && jar.exists()) { + System.out.println("Loading classes from: " + jar.getAbsolutePath()); + ClientResponse response = db.loadClasses(jar.getAbsolutePath()); + assertEquals(ClientResponse.SUCCESS, response.getStatus(), + "Load classes must succeed: " + response.getStatusString()); + } else { + throw new RuntimeException("Project JAR not found. Run 'mvn package -DskipTests' first."); + } + } catch (Exception e) { + throw new RuntimeException("Failed to start container and load classes", e); + } + } + + /** + * Creates a client connected to an external VoltDB instance. + */ + public Client2 createExternalClient() throws Exception { + Client2Config config = new Client2Config(); + Client2 client = ClientFactory.createClient(config); + String host = getExternalHost(); + int port = getExternalPort(); + System.out.println("Connecting to external VoltDB at " + host + ":" + port); + client.connectSync(host, port); + return client; + } + + /** + * Shuts down the testcontainer if configured to do so. + */ + public void shutdownIfNeeded(VoltDBCluster db) { + if (db != null && isShutdownOnCompletion()) { + System.out.println("Shutting down VoltDB testcontainer..."); + db.shutdown(); + } else if (db != null) { + System.out.println("Keeping VoltDB testcontainer running (shutdown disabled)."); + } + } + + /** + * Gets the project JAR path from test.properties or uses default naming. + */ + protected File getProjectJar() { + String jarPath = props.getProperty("project.jar.path"); + if (jarPath != null) { + File jar = new File(jarPath); + if (jar.exists()) { + return jar; + } + } + // Try default Maven target directory + File targetDir = new File("target"); + if (targetDir.exists()) { + File[] jars = targetDir.listFiles((dir, name) -> + name.endsWith(".jar") && !name.contains("-sources") && !name.contains("-javadoc")); + if (jars != null && jars.length > 0) { + return jars[0]; + } + } + return null; + } + + /** + * Gets the VoltDB license path from environment or default location. + */ + protected String getLicensePath() { + String envLicense = System.getenv("VOLTDB_LICENSE"); + if (envLicense != null) { + File file = Paths.get(envLicense).toAbsolutePath().toFile(); + if (file.exists()) { + System.out.println("Using license from VOLTDB_LICENSE: " + file.getAbsolutePath()); + return file.getAbsolutePath(); + } + } + String defaultPath = "/tmp/voltdb-license.xml"; + System.out.println("Using default license path: " + defaultPath); + return defaultPath; + } +} diff --git a/tasks/growing-commandlog/src/test/resources/test.properties b/tasks/growing-commandlog/src/test/resources/test.properties new file mode 100644 index 0000000..5633ec7 --- /dev/null +++ b/tasks/growing-commandlog/src/test/resources/test.properties @@ -0,0 +1,18 @@ +# VoltDB Testcontainer Configuration + +# VoltDB Enterprise image version +voltdb.image.version=15.1.0 + +# VoltDB test mode: "testcontainer" (default) or "external" +voltdb.test.mode=testcontainer + +# External VoltDB connection settings (used when voltdb.test.mode=external) +voltdb.external.host=localhost +voltdb.external.port=21211 + +# Testcontainer shutdown behavior (used when voltdb.test.mode=testcontainer) +# Set to "false" to keep the container running after tests for debugging +voltdb.testcontainer.shutdown=true + +# Project JAR path (relative to module directory) +project.jar.path=target/growing-commandlog-1.0.0-SNAPSHOT.jar