Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: graalvm support for nitrite-mvstore-adapter #995

Merged
merged 6 commits into from
Jul 9, 2024
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
24 changes: 23 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['11', '17']
java: [ '11', '17' ]
env:
JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"

Expand Down Expand Up @@ -94,3 +94,25 @@ jobs:

- name: Build with Maven
run: mvn -B -ff -ntp clean install --% -Dgpg.skip=true

verify-native:
name: Verify GraalVM ${{ matrix.java }} compatibility on ${{ matrix.os }}
strategy:
matrix:
os: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ]
java: [ '17', '21' ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- uses: graalvm/[email protected]
with:
java-version: ${{ matrix.java }}
distribution: 'graalvm-community'

- name: Install nitrite
run: mvn -B -ff -ntp clean install "-Dgpg.skip=true" -DskipTests

- name: Run native tests
working-directory: ./nitrite-native-tests
run: mvn -B -ff -ntp -PnativeTest verify
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[
{
"name": "java.lang.Integer"
},
{
"name": "java.lang.Long"
},
{
"name": "java.lang.Number"
},
{
"name": "java.lang.String"
},
{
"name": "java.util.ArrayList"
},
{
"name": "java.util.concurrent.atomic.AtomicBoolean"
},
{
"name": "java.util.concurrent.ConcurrentHashMap"
},
{
"name": "java.util.concurrent.ConcurrentHashMap$Segment"
},
{
"name": "java.util.concurrent.CopyOnWriteArrayList"
},
{
"name": "java.util.concurrent.locks.AbstractOwnableSynchronizer"
},
{
"name": "java.util.concurrent.locks.AbstractQueuedSynchronizer"
},
{
"name": "java.util.concurrent.locks.ReentrantLock"
},
{
"name": "java.util.concurrent.locks.ReentrantLock$NonfairSync"
},
{
"name": "java.util.concurrent.locks.ReentrantLock$Sync"
},
{
"name": "java.util.HashMap"
},
{
"name": "java.util.HashSet"
},
{
"name": "java.util.LinkedHashMap"
},
{
"name": "org.dizitart.no2.collection.NitriteDocument"
},
{
"name": "org.dizitart.no2.collection.NitriteId"
},
{
"name": "org.dizitart.no2.common.DBValue"
},
{
"name": "org.dizitart.no2.common.Fields"
},
{
"name": "org.dizitart.no2.common.meta.Attributes"
},
{
"name": "org.dizitart.no2.common.tuples.Pair"
},
{
"name": "org.dizitart.no2.index.IndexDescriptor"
},
{
"name": "org.dizitart.no2.index.IndexMeta"
},
{
"name": "org.dizitart.no2.store.UserCredential"
}
]
148 changes: 148 additions & 0 deletions nitrite-native-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.dizitart</groupId>
<artifactId>nitrite-java</artifactId>
<version>4.3.1-SNAPSHOT</version>
</parent>

<artifactId>nitrite-native-tests</artifactId>

<name>Nitrite Native Tests</name>
<description>Test module to ensures GraalVM compatibility of nitrite</description>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<assertj.version>3.25.3</assertj.version>
<junit.version>5.10.3</junit.version>
<native-build-tools-plugin.version>0.10.2</native-build-tools-plugin.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.dizitart</groupId>
<artifactId>nitrite</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.dizitart</groupId>
<artifactId>nitrite-mvstore-adapter</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- skip installing this test module in the local mvn repository -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<!-- skip deploying this test module -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<!-- skip generating javadoc for this test module -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<!-- skip attaching sources for this test module -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<configuration>
<skipSource>true</skipSource>
</configuration>
</plugin>
<!-- skip signing this test module -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>nativeTest</id>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native-build-tools-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
</configuration>
<executions>
<execution>
<id>native-test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.dizitart.nitrite.test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.logging.Logger;

import org.dizitart.nitrite.test.repository.PersonEntityConverter;
import org.dizitart.no2.Nitrite;
import org.dizitart.no2.mvstore.MVStoreModule;

public class DatabaseTestUtils {

private static final Logger logger = Logger.getLogger(DatabaseTestUtils.class.getSimpleName());

public static Path getRandomDatabasePath() throws IOException {
final Path databasePath = Files.createTempFile("nitrite-native", ".db");
logger.finest("Test Db location: " + databasePath.toAbsolutePath());
return databasePath;
}

public static Nitrite setupDatabase() throws IOException {
return setupDatabase(null);
}

public static Nitrite setupDatabase(final Path template) throws IOException {

final Path databasePath = getRandomDatabasePath();

if (template != null) {
logger.finest("Loading template from '" + template.toAbsolutePath() + "'.");
Files.copy(template, databasePath, StandardCopyOption.REPLACE_EXISTING);
}

final MVStoreModule mvStoreModule = MVStoreModule.withConfig()
.filePath(databasePath.toFile())
.build();

return Nitrite.builder()
.loadModule(mvStoreModule)
.disableRepositoryTypeValidation()
.registerEntityConverter(new PersonEntityConverter())
.openOrCreate("test", "test");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.dizitart.nitrite.test.collection;

import static org.assertj.core.api.Assertions.assertThat;
import org.dizitart.nitrite.test.DatabaseTestUtils;
import org.dizitart.no2.Nitrite;
import org.dizitart.no2.collection.Document;
import org.dizitart.no2.collection.NitriteId;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.math.BigDecimal;

public class CollectionTest {

@Test
void readAndWriteOperationsShouldSucceed() throws IOException {

try (final Nitrite database = DatabaseTestUtils.setupDatabase()) {

final var testCollection = database.getCollection("test");

final Document expectedDocument = Document.createDocument()
.put("test", "test")
// requires additional serialization hints for BigDecimal and BigInteger
// this also applies to other Serializable classes
// see: src/test/resources/META-INF/native-image/org.dizitart/nitrite-native-tests/serialization-config.json
.put("price", new BigDecimal("9.99"));

final NitriteId id = testCollection.insert(expectedDocument).iterator().next();

final Document actualDocument = testCollection.getById(id);

assertThat(actualDocument).isNotNull();
assertThat(actualDocument.getId()).isEqualTo(id);
assertThat(actualDocument.get("test", String.class)).isEqualTo("test");
assertThat(actualDocument.get("price", BigDecimal.class)).isEqualTo("9.99");
}
}
}
Loading