Skip to content

Commit f2338fd

Browse files
authored
feat: graalvm support for nitrite-mvstore-adapter (#995)
* feat: graalvm support for mvstore * chore: add module with native tests * chore: add module with native tests * chore: add module with native tests * chore: add tests for transactions * chore: add test for migrations
1 parent c82795b commit f2338fd

File tree

14 files changed

+690
-1
lines changed

14 files changed

+690
-1
lines changed

.github/workflows/build.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: ubuntu-latest
2323
strategy:
2424
matrix:
25-
java: ['11', '17']
25+
java: [ '11', '17' ]
2626
env:
2727
JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
2828

@@ -94,3 +94,25 @@ jobs:
9494

9595
- name: Build with Maven
9696
run: mvn -B -ff -ntp clean install --% -Dgpg.skip=true
97+
98+
verify-native:
99+
name: Verify GraalVM ${{ matrix.java }} compatibility on ${{ matrix.os }}
100+
strategy:
101+
matrix:
102+
os: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ]
103+
java: [ '17', '21' ]
104+
runs-on: ${{ matrix.os }}
105+
steps:
106+
- uses: actions/checkout@v4
107+
108+
- uses: graalvm/setup-graalvm@v1.2.1
109+
with:
110+
java-version: ${{ matrix.java }}
111+
distribution: 'graalvm-community'
112+
113+
- name: Install nitrite
114+
run: mvn -B -ff -ntp clean install "-Dgpg.skip=true" -DskipTests
115+
116+
- name: Run native tests
117+
working-directory: ./nitrite-native-tests
118+
run: mvn -B -ff -ntp -PnativeTest verify
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[
2+
{
3+
"name": "java.lang.Integer"
4+
},
5+
{
6+
"name": "java.lang.Long"
7+
},
8+
{
9+
"name": "java.lang.Number"
10+
},
11+
{
12+
"name": "java.lang.String"
13+
},
14+
{
15+
"name": "java.util.ArrayList"
16+
},
17+
{
18+
"name": "java.util.concurrent.atomic.AtomicBoolean"
19+
},
20+
{
21+
"name": "java.util.concurrent.ConcurrentHashMap"
22+
},
23+
{
24+
"name": "java.util.concurrent.ConcurrentHashMap$Segment"
25+
},
26+
{
27+
"name": "java.util.concurrent.CopyOnWriteArrayList"
28+
},
29+
{
30+
"name": "java.util.concurrent.locks.AbstractOwnableSynchronizer"
31+
},
32+
{
33+
"name": "java.util.concurrent.locks.AbstractQueuedSynchronizer"
34+
},
35+
{
36+
"name": "java.util.concurrent.locks.ReentrantLock"
37+
},
38+
{
39+
"name": "java.util.concurrent.locks.ReentrantLock$NonfairSync"
40+
},
41+
{
42+
"name": "java.util.concurrent.locks.ReentrantLock$Sync"
43+
},
44+
{
45+
"name": "java.util.HashMap"
46+
},
47+
{
48+
"name": "java.util.HashSet"
49+
},
50+
{
51+
"name": "java.util.LinkedHashMap"
52+
},
53+
{
54+
"name": "org.dizitart.no2.collection.NitriteDocument"
55+
},
56+
{
57+
"name": "org.dizitart.no2.collection.NitriteId"
58+
},
59+
{
60+
"name": "org.dizitart.no2.common.DBValue"
61+
},
62+
{
63+
"name": "org.dizitart.no2.common.Fields"
64+
},
65+
{
66+
"name": "org.dizitart.no2.common.meta.Attributes"
67+
},
68+
{
69+
"name": "org.dizitart.no2.common.tuples.Pair"
70+
},
71+
{
72+
"name": "org.dizitart.no2.index.IndexDescriptor"
73+
},
74+
{
75+
"name": "org.dizitart.no2.index.IndexMeta"
76+
},
77+
{
78+
"name": "org.dizitart.no2.store.UserCredential"
79+
}
80+
]

nitrite-native-tests/pom.xml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.dizitart</groupId>
9+
<artifactId>nitrite-java</artifactId>
10+
<version>4.3.1-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>nitrite-native-tests</artifactId>
14+
15+
<name>Nitrite Native Tests</name>
16+
<description>Test module to ensures GraalVM compatibility of nitrite</description>
17+
18+
<properties>
19+
<maven.compiler.source>17</maven.compiler.source>
20+
<maven.compiler.target>17</maven.compiler.target>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
23+
<assertj.version>3.25.3</assertj.version>
24+
<junit.version>5.10.3</junit.version>
25+
<native-build-tools-plugin.version>0.10.2</native-build-tools-plugin.version>
26+
</properties>
27+
28+
<dependencyManagement>
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.junit</groupId>
32+
<artifactId>junit-bom</artifactId>
33+
<version>${junit.version}</version>
34+
<type>pom</type>
35+
<scope>import</scope>
36+
</dependency>
37+
</dependencies>
38+
</dependencyManagement>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>org.dizitart</groupId>
43+
<artifactId>nitrite</artifactId>
44+
<version>${project.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.dizitart</groupId>
48+
<artifactId>nitrite-mvstore-adapter</artifactId>
49+
<version>${project.version}</version>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>org.assertj</groupId>
54+
<artifactId>assertj-core</artifactId>
55+
<version>${assertj.version}</version>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.junit.jupiter</groupId>
60+
<artifactId>junit-jupiter-api</artifactId>
61+
<scope>test</scope>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.junit.jupiter</groupId>
65+
<artifactId>junit-jupiter-engine</artifactId>
66+
<scope>test</scope>
67+
</dependency>
68+
</dependencies>
69+
70+
<build>
71+
<plugins>
72+
<!-- skip installing this test module in the local mvn repository -->
73+
<plugin>
74+
<groupId>org.apache.maven.plugins</groupId>
75+
<artifactId>maven-install-plugin</artifactId>
76+
<configuration>
77+
<skip>true</skip>
78+
</configuration>
79+
</plugin>
80+
<!-- skip deploying this test module -->
81+
<plugin>
82+
<groupId>org.apache.maven.plugins</groupId>
83+
<artifactId>maven-deploy-plugin</artifactId>
84+
<configuration>
85+
<skip>true</skip>
86+
</configuration>
87+
</plugin>
88+
<!-- skip generating javadoc for this test module -->
89+
<plugin>
90+
<groupId>org.apache.maven.plugins</groupId>
91+
<artifactId>maven-javadoc-plugin</artifactId>
92+
<configuration>
93+
<skip>true</skip>
94+
</configuration>
95+
</plugin>
96+
<!-- skip attaching sources for this test module -->
97+
<plugin>
98+
<groupId>org.apache.maven.plugins</groupId>
99+
<artifactId>maven-source-plugin</artifactId>
100+
<configuration>
101+
<skipSource>true</skipSource>
102+
</configuration>
103+
</plugin>
104+
<!-- skip signing this test module -->
105+
<plugin>
106+
<groupId>org.apache.maven.plugins</groupId>
107+
<artifactId>maven-gpg-plugin</artifactId>
108+
<configuration>
109+
<skip>true</skip>
110+
</configuration>
111+
</plugin>
112+
</plugins>
113+
</build>
114+
115+
<profiles>
116+
<profile>
117+
<id>nativeTest</id>
118+
<dependencies>
119+
<dependency>
120+
<groupId>org.junit.platform</groupId>
121+
<artifactId>junit-platform-launcher</artifactId>
122+
<scope>test</scope>
123+
</dependency>
124+
</dependencies>
125+
<build>
126+
<plugins>
127+
<plugin>
128+
<groupId>org.graalvm.buildtools</groupId>
129+
<artifactId>native-maven-plugin</artifactId>
130+
<version>${native-build-tools-plugin.version}</version>
131+
<extensions>true</extensions>
132+
<configuration>
133+
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
134+
</configuration>
135+
<executions>
136+
<execution>
137+
<id>native-test</id>
138+
<goals>
139+
<goal>test</goal>
140+
</goals>
141+
</execution>
142+
</executions>
143+
</plugin>
144+
</plugins>
145+
</build>
146+
</profile>
147+
</profiles>
148+
</project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.dizitart.nitrite.test;
2+
3+
import java.io.IOException;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.nio.file.StandardCopyOption;
7+
import java.util.logging.Logger;
8+
9+
import org.dizitart.nitrite.test.repository.PersonEntityConverter;
10+
import org.dizitart.no2.Nitrite;
11+
import org.dizitart.no2.mvstore.MVStoreModule;
12+
13+
public class DatabaseTestUtils {
14+
15+
private static final Logger logger = Logger.getLogger(DatabaseTestUtils.class.getSimpleName());
16+
17+
public static Path getRandomDatabasePath() throws IOException {
18+
final Path databasePath = Files.createTempFile("nitrite-native", ".db");
19+
logger.finest("Test Db location: " + databasePath.toAbsolutePath());
20+
return databasePath;
21+
}
22+
23+
public static Nitrite setupDatabase() throws IOException {
24+
return setupDatabase(null);
25+
}
26+
27+
public static Nitrite setupDatabase(final Path template) throws IOException {
28+
29+
final Path databasePath = getRandomDatabasePath();
30+
31+
if (template != null) {
32+
logger.finest("Loading template from '" + template.toAbsolutePath() + "'.");
33+
Files.copy(template, databasePath, StandardCopyOption.REPLACE_EXISTING);
34+
}
35+
36+
final MVStoreModule mvStoreModule = MVStoreModule.withConfig()
37+
.filePath(databasePath.toFile())
38+
.build();
39+
40+
return Nitrite.builder()
41+
.loadModule(mvStoreModule)
42+
.disableRepositoryTypeValidation()
43+
.registerEntityConverter(new PersonEntityConverter())
44+
.openOrCreate("test", "test");
45+
}
46+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.dizitart.nitrite.test.collection;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import org.dizitart.nitrite.test.DatabaseTestUtils;
5+
import org.dizitart.no2.Nitrite;
6+
import org.dizitart.no2.collection.Document;
7+
import org.dizitart.no2.collection.NitriteId;
8+
import org.junit.jupiter.api.Test;
9+
10+
import java.io.IOException;
11+
import java.math.BigDecimal;
12+
13+
public class CollectionTest {
14+
15+
@Test
16+
void readAndWriteOperationsShouldSucceed() throws IOException {
17+
18+
try (final Nitrite database = DatabaseTestUtils.setupDatabase()) {
19+
20+
final var testCollection = database.getCollection("test");
21+
22+
final Document expectedDocument = Document.createDocument()
23+
.put("test", "test")
24+
// requires additional serialization hints for BigDecimal and BigInteger
25+
// this also applies to other Serializable classes
26+
// see: src/test/resources/META-INF/native-image/org.dizitart/nitrite-native-tests/serialization-config.json
27+
.put("price", new BigDecimal("9.99"));
28+
29+
final NitriteId id = testCollection.insert(expectedDocument).iterator().next();
30+
31+
final Document actualDocument = testCollection.getById(id);
32+
33+
assertThat(actualDocument).isNotNull();
34+
assertThat(actualDocument.getId()).isEqualTo(id);
35+
assertThat(actualDocument.get("test", String.class)).isEqualTo("test");
36+
assertThat(actualDocument.get("price", BigDecimal.class)).isEqualTo("9.99");
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)