diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f60b3f1e..7bae620f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,3 +63,5 @@ jobs: export _JAVA_OPTIONS="--enable-native-access=ALL-UNNAMED" fi ./sbt test + - name: JAR Integration Test + run: ./script/test-jar-integration.sh diff --git a/script/test-jar-integration.sh b/script/test-jar-integration.sh new file mode 100755 index 00000000..af345ad7 --- /dev/null +++ b/script/test-jar-integration.sh @@ -0,0 +1,61 @@ +#!/bin/bash +set -e + +echo "==========================================" +echo "Snappy-Java Integration Test" +echo "==========================================" + +# Detect Java version +JAVA_VERSION=$(java -version 2>&1 | head -1 | cut -d'"' -f2 | sed 's/^1\.//' | cut -d'.' -f1) +echo "Java version: $JAVA_VERSION" + +# Build the JAR +echo "" +echo "Building JAR..." +./sbt package + +# Find the JAR +JAR_FILE=$(ls -t target/snappy-java-*.jar | grep -v sources | grep -v javadoc | head -1) +if [ -z "$JAR_FILE" ]; then + echo "ERROR: Could not find snappy-java JAR" + exit 1 +fi +echo "Using JAR: $JAR_FILE" + +# Create temp directory +TEMP_DIR=$(mktemp -d) +echo "" +echo "Using temp directory: $TEMP_DIR" + +# Copy test source +cp src/test/resources/integration/SnappyIntegrationTest.java "$TEMP_DIR/" + +# Compile test +echo "" +echo "Compiling test program..." +javac -cp "$JAR_FILE" -d "$TEMP_DIR" "$TEMP_DIR/SnappyIntegrationTest.java" + +# Run test WITHOUT --enable-native-access flag +echo "" +echo "==========================================" +echo "Running test (WITHOUT --enable-native-access flag)..." +echo "==========================================" + +cd "$TEMP_DIR" +java -cp ".:$OLDPWD/$JAR_FILE" SnappyIntegrationTest 2>&1 +EXIT_CODE=$? +cd - > /dev/null + +echo "" +echo "==========================================" +if [ $EXIT_CODE -eq 0 ]; then + echo "✓ Test PASSED (exit code: $EXIT_CODE)" +else + echo "✗ Test FAILED (exit code: $EXIT_CODE)" +fi +echo "==========================================" + +# Cleanup +rm -rf "$TEMP_DIR" + +exit $EXIT_CODE diff --git a/src/test/resources/integration/SnappyIntegrationTest.java b/src/test/resources/integration/SnappyIntegrationTest.java new file mode 100644 index 00000000..618c0bf5 --- /dev/null +++ b/src/test/resources/integration/SnappyIntegrationTest.java @@ -0,0 +1,32 @@ +import org.xerial.snappy.Snappy; + +/** + * Simple integration test to verify snappy-java works in a separate JVM. + * This is compiled and run as a standalone program to test the JAR manifest + * and native library loading on different JDK versions. + */ +public class SnappyIntegrationTest { + public static void main(String[] args) throws Exception { + String input = "Hello snappy-java! Snappy-java is a JNI-based wrapper of " + + "Snappy, a fast compresser/decompresser."; + + // Test compression + byte[] compressed = Snappy.compress(input.getBytes("UTF-8")); + System.out.println("Compressed " + input.length() + " bytes to " + compressed.length + " bytes"); + + // Test decompression + byte[] uncompressed = Snappy.uncompress(compressed); + String result = new String(uncompressed, "UTF-8"); + + // Verify result matches input + if (!result.equals(input)) { + System.err.println("ERROR: Decompressed data does not match input!"); + System.err.println("Expected: " + input); + System.err.println("Got: " + result); + System.exit(1); + } + + System.out.println("SUCCESS: " + result); + System.exit(0); + } +}