Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
61 changes: 61 additions & 0 deletions script/test-jar-integration.sh
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions src/test/resources/integration/SnappyIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading