Skip to content

Commit

Permalink
Merge pull request #1 from meletis/develop
Browse files Browse the repository at this point in the history
Reproducing the issue with the failure during test AOT processing
  • Loading branch information
meletis committed Dec 8, 2023
2 parents 80caac1 + 3eaa128 commit bedc493
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 48 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
workflow_dispatch:
push:
branches:
- main
- develop

jobs:
build:
name: Build app
runs-on: ubuntu-latest

permissions:
id-token: write
contents: read

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: 'liberica'
java-version: '17'

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
cache-disabled: true

- name: Build the server
run: ./gradlew --info clean build
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# native-build-tools-bug-report

This repo is created to help troubleshooting the bug report at https://github.com/graalvm/native-build-tools/issues/537
This repo is created to help troubleshooting the bug reports at the following issues:

* https://github.com/graalvm/native-build-tools/issues/537

* https://github.com/spring-projects/spring-boot/issues/36997
78 changes: 48 additions & 30 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
plugins {
id("java")
id("application")
id("org.springframework.boot") version "3.2.0"
id("io.spring.dependency-management") version "1.1.4"
id("org.hibernate.orm") version "6.3.1.Final" // Upgrade hibernate plugin version when upgrading spring boot
id("io.freefair.lombok") version "8.4"
id("org.graalvm.buildtools.native") version "0.9.28"
}

group = "org.example"
version = "1.0-SNAPSHOT"
version = "1.0.0-SNAPSHOT"

java {
sourceCompatibility = JavaVersion.VERSION_17
Expand All @@ -15,43 +19,57 @@ repositories {
mavenCentral()
}

val springCloudVersion = "2023.0.0"
val testContainersVersion = "1.19.3"
val mysqlConnectorVersion = "8.2.0"

dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion")
}
}

dependencies {
// Test containers dependencies
testImplementation(platform("org.testcontainers:testcontainers-bom:1.19.1"))
testImplementation("org.testcontainers:mysql:1.19.1")
testImplementation("org.testcontainers:junit-jupiter:1.19.1")
implementation("org.springframework.cloud:spring-cloud-starter-openfeign")
implementation("org.springframework.boot:spring-boot-starter-actuator")

// Test dependencies
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-testcontainers")

testImplementation("org.junit.jupiter:junit-jupiter:5.9.3")
testImplementation(platform("org.testcontainers:testcontainers-bom:$testContainersVersion"))
testImplementation("org.testcontainers:mysql:$testContainersVersion")
testImplementation("org.testcontainers:junit-jupiter:$testContainersVersion")

testRuntimeOnly("com.mysql:mysql-connector-j:8.0.33")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testRuntimeOnly("com.mysql:mysql-connector-j:$mysqlConnectorVersion")
}

tasks.test {
useJUnitPlatform()
}

// Conditionally apply the GraalVM native image plugin
gradle.taskGraph.whenReady {
if (gradle.taskGraph.hasTask(":nativeCompile") or gradle.taskGraph.hasTask(":nativeTest")) {
apply(plugin = "org.graalvm.buildtools.native")

application {
mainClass.set("com.example.TestApp")
}

// Configure the GraalVM native image plugin settings
graalvmNative {
binaries.all {
resources.autodetect()
}

// We need this, otherwise testcontainers suffer from this:
// https://github.com/oracle/graalvm-reachability-metadata/pull/301
metadataRepository {
enabled.set(true)
}

toolchainDetection.set(false)
}
application {
mainClass.set("org.example.MyApplication")
}

// Configure the GraalVM native image plugin settings
graalvmNative {
binaries.all {
resources.autodetect()
}

// We need this, otherwise testcontainers suffer from this:
// https://github.com/oracle/graalvm-reachability-metadata/pull/301
metadataRepository {
enabled.set(true)
}

toolchainDetection.set(false)
}

hibernate {
enhancement {
enableAssociationManagement.set(true)
}
}
8 changes: 0 additions & 8 deletions src/main/java/org/example/MyApp.java

This file was deleted.

11 changes: 11 additions & 0 deletions src/main/java/org/example/MyAppProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.example;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "app")
@Data
public class MyAppProperties {

String stackName;
}
30 changes: 30 additions & 0 deletions src/main/java/org/example/MyApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2012-23 Dobility, Inc.
*
* All rights reserved.
*/

package org.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

import java.util.Locale;
import java.util.TimeZone;

@SpringBootApplication
@EnableConfigurationProperties({MyAppProperties.class})
public class MyApplication {

public static void main(String[] args) {
// Set the JVM timezone to UTC
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

// Set the default locale to be US.
Locale.setDefault(Locale.US);

// Start the app
SpringApplication.run(MyApplication.class, args);
}
}
8 changes: 8 additions & 0 deletions src/main/java/org/example/service/MyService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.example.service;

import org.springframework.stereotype.Service;

@Service
public class MyService {

}
3 changes: 3 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spring.application.name=Demo

app.stack-name=dev
28 changes: 28 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
~ Copyright (C) 2012-23 Dobility, Inc.
~
~ All rights reserved.
-->

<configuration>
<!-- Appender configurations (console, file, etc.) -->
<!-- ... -->

<!-- Root logger -->
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>

<springProperty scope="context" name="appName" source="spring.application.name" defaultValue="no app name"/>
<springProperty scope="context" name="stackName" source="app.stack-name" defaultValue="no stack name"/>

<!-- Custom log pattern -->
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX} [${appName}] [${stackName}] %5p --- [%15.15t] %-40.40logger{39} : %m%n"/>

<!-- Console appender -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
</configuration>
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package org.example;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterAll;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.test.annotation.DirtiesContext;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class MyAppTest {
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
@Testcontainers
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class BaseTest {

@ServiceConnection
private static final MySQLContainer<?> mySQLContainer;

static {
mySQLContainer = new MySQLContainer<>(DockerImageName.parse("mysql:5.7"))
mySQLContainer = new MySQLContainer<>(DockerImageName.parse("mysql:8.0"))
.withUsername("admin")
.withPassword("admin_pass")
.withReuse(false)
Expand All @@ -21,11 +30,6 @@ public class MyAppTest {
mySQLContainer.start();
}

@AfterAll
public static void tearDown() {
mySQLContainer.stop();
}

@Test
public void testMySQLContainerIsRunning() {
assertTrue(mySQLContainer.isRunning());
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/example/FirstTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.example;

import org.example.service.MyService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

public class FirstTest extends BaseTest {

@Autowired
MyService myService;

@Test
void foo() {

}
}
18 changes: 18 additions & 0 deletions src/test/java/org/example/SecondTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.example;

import org.example.service.MyService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.aot.DisabledInAotMode;

@DisabledInAotMode
public class SecondTest extends BaseTest {

@MockBean
MyService myService;

@Test
void foo() {

}
}
1 change: 1 addition & 0 deletions src/test/resources/application-default.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app.stack-name=test
23 changes: 23 additions & 0 deletions src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
~ Copyright (C) 2012-23 Dobility, Inc.
~
~ All rights reserved.
-->

<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT"/>
</root>

<logger name="org.testcontainers" level="INFO"/>
<!-- The following logger can be used for containers logs since 1.18.0 -->
<logger name="tc" level="INFO"/>
<logger name="com.github.dockerjava" level="WARN"/>
<logger name="com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.wire" level="OFF"/>
</configuration>

0 comments on commit bedc493

Please sign in to comment.