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

Run CI with GraalVM #2476

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
28 changes: 28 additions & 0 deletions .github/workflows/graal-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: CI Build in GraalVM native-image with tests

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
ci:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: graalvm/setup-graalvm@v1
with:
java-version: 21
cache: maven

- name: build
env:
MAVEN_CONFIG: "-Dbasepom.check.skip-enforcer=false -B -Djdbi.native=true"
run: |
make install
Empty file added .skip-native
Empty file.
Empty file added bom/.skip-native
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
*/
package org.jdbi.v3.core.statement;

import java.text.ParseException;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import de.softwareforge.testing.postgres.junit5.EmbeddedPgExtension;
Expand All @@ -36,7 +39,7 @@ public class TestPreparedBatchGenerateKeysPostgres {

@RegisterExtension
public PgDatabaseExtension pgExtension = PgDatabaseExtension.instance(pg).withInitializer(
handle -> handle.execute("create table something (id serial, name varchar(50), create_time timestamp default now())")
handle -> handle.execute("create table something (id serial, name varchar(50), create_time timestamptz default now())")
);

@Test
Expand Down Expand Up @@ -65,7 +68,7 @@ public void testBatchInsertWithKeyGenerationAndExplicitSeveralColumnNames() {
batch.add("Thom");

List<IdCreateTime> ids = batch.executeAndReturnGeneratedKeys("id", "create_time")
.map((r, ctx) -> new IdCreateTime(r.getInt("id"), r.getDate("create_time")))
.map((r, ctx) -> new IdCreateTime(r.getInt("id"), r.getObject("create_time", OffsetDateTime.class)))
.list();

assertThat(ids).hasSize(2);
Expand All @@ -74,7 +77,7 @@ public void testBatchInsertWithKeyGenerationAndExplicitSeveralColumnNames() {
}

@Test
public void testBatchResultBearing() {
public void testBatchResultBearing() throws ParseException {
try (Handle h = pgExtension.getSharedHandle()) {

PreparedBatch batch1 = h.prepareBatch("insert into something (name) values (?) ");
Expand All @@ -85,29 +88,34 @@ public void testBatchResultBearing() {
List<IdCreateTime> ids = batch1.executeAndReturnGeneratedKeys("id", "create_time")
.map((r, ctx) -> new IdCreateTime(
r.getInt("id"),
r.getTimestamp("create_time")))
r.getObject("create_time", OffsetDateTime.class)))
.list();

PreparedBatch batch2 = h.prepareBatch("update something set create_time = now() where name like :name returning id, name, create_time");
var now = OffsetDateTime.ofInstant(Instant.ofEpochSecond(1234567), ZoneOffset.UTC);

PreparedBatch batch2 = h.prepareBatch("update something set create_time = :now where name like :name returning id, name, create_time");

batch2.bind("name", "Brian%")
.bind("now", now)
.add()
.bind("now", now)
.bind("name", "Thom%")
.add()
.bind("now", now)
.bind("name", "Nothing%")
.add();

List<List<IdCreateTime>> choppedList = batch2.executePreparedBatch("id", "create_time")
.map((r, ctx) -> new IdCreateTime(r.getInt("id"), r.getTimestamp("create_time")))
.map((r, ctx) -> new IdCreateTime(r.getInt("id"), r.getObject("create_time", OffsetDateTime.class)))
.listPerBatch();

assertThat(choppedList).hasSize(3);
assertThat(choppedList.get(0)).extracting(ic -> ic.id).containsExactly(1, 2);
assertThat(choppedList.get(0)).extracting(ic -> ic.createTime)
.allMatch(date -> ids.stream().map(idCreateTime -> idCreateTime.createTime).allMatch(date1 -> date1.before(date)));
.containsExactly(now, now);
assertThat(choppedList.get(1)).extracting(ic -> ic.id).containsExactly(3, 4);
assertThat(choppedList.get(1)).extracting(ic -> ic.createTime)
.allMatch(date -> ids.stream().map(idCreateTime -> idCreateTime.createTime).allMatch(date1 -> date1.before(date)));
.containsExactly(now, now);
assertThat(choppedList.get(2)).extracting(ic -> ic.id).isEmpty();
assertThat(choppedList.get(2)).extracting(ic -> ic.createTime).isEmpty();
}
Expand Down Expand Up @@ -157,9 +165,9 @@ public void testListModCount() {
private static class IdCreateTime {

final Integer id;
final Date createTime;
final OffsetDateTime createTime;

IdCreateTime(Integer id, Date createTime) {
IdCreateTime(Integer id, OffsetDateTime createTime) {
this.id = id;
this.createTime = createTime;
}
Expand Down
Empty file added internal/.skip-native
Empty file.
Empty file added internal/build/.skip-native
Empty file.
56 changes: 54 additions & 2 deletions internal/build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
<dep.plugin.javadoc.version>3.6.0</dep.plugin.javadoc.version>
<dep.plugin.kotlin.version>1.9.22</dep.plugin.kotlin.version>
<dep.plugin.ktlint.version>2.0.0</dep.plugin.ktlint.version>
<dep.plugin.native.version>0.9.28</dep.plugin.native.version>
<dep.plugin.sortpom.version>3.3.0</dep.plugin.sortpom.version>
<dep.postgresql.version>42.7.1</dep.postgresql.version>
<dep.slf4j.version>1.7.36</dep.slf4j.version>
Expand Down Expand Up @@ -551,7 +552,8 @@
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>${dep.jakarta-annotation-api.version}</version>
<scope>provided</scope>
<!-- XXX https://github.com/graalvm/native-build-tools/issues/562 -->
<!-- <scope>provided</scope> -->
<optional>true</optional>
</dependency>

Expand Down Expand Up @@ -1198,7 +1200,57 @@
</plugins>
</build>
</profile>

<profile>
<id>native</id>
<activation>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of the modules where this needs to be activated are packaging jars. can't we just use

<property>
        <name>packaging</name>
        <value>!pom</value>
</property>

and avoid more dotfiles?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually does not work because maven only supports a single property for activation. sigh. maven is terrible.

<property>
<name>jdbi.native</name>
</property>
<file>
<missing>.skip-native</missing>
</file>
</activation>
<build>
<pluginManagement>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should move outside the profile, into the pluginManagement section above.

<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${dep.plugin.native.version}</version>
<extensions>true</extensions>
<configuration>
<metadataRepository>
<enabled>true</enabled>
</metadataRepository>
<agent>
<enabled>true</enabled>
<!-- XXX Temporary -->
<options>
<enableExperimentalPredefinedClasses>true</enableExperimentalPredefinedClasses>
</options>
</agent>
</configuration>
<executions>
Copy link
Contributor

@hgschmie hgschmie Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those should stay here, move into the <plugin> below.

<execution>
<id>test-native</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- Profile to skip time-consuming steps. -->
<id>fast</id>
Expand Down