From 0d406b96123ce023ce963395e6554fdc207dca8c Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Tue, 7 Jan 2025 16:07:56 +0100 Subject: [PATCH] Testing: add reproducer for testing bug with multi-module project and Avro --- .../extension/it/TestAvroMultimoduleIT.java | 31 ++++++++ .../avro-multimodule-project/module1/pom.xml | 20 +++++ .../module1/src/main/avro/movie.avsc | 11 +++ .../avro-multimodule-project/module2/pom.xml | 30 ++++++++ .../src/main/java/org/acme/MovieSerde.java | 37 +++++++++ .../test/java/org/acme/MovieSerdeTest.java | 25 ++++++ .../projects/avro-multimodule-project/pom.xml | 77 +++++++++++++++++++ 7 files changed, 231 insertions(+) create mode 100644 integration-tests/test-extension/tests/src/test/java/io/quarkus/it/extension/it/TestAvroMultimoduleIT.java create mode 100644 integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module1/pom.xml create mode 100644 integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module1/src/main/avro/movie.avsc create mode 100644 integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module2/pom.xml create mode 100644 integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module2/src/main/java/org/acme/MovieSerde.java create mode 100644 integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module2/src/test/java/org/acme/MovieSerdeTest.java create mode 100644 integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/pom.xml diff --git a/integration-tests/test-extension/tests/src/test/java/io/quarkus/it/extension/it/TestAvroMultimoduleIT.java b/integration-tests/test-extension/tests/src/test/java/io/quarkus/it/extension/it/TestAvroMultimoduleIT.java new file mode 100644 index 0000000000000..57645c83bc3fd --- /dev/null +++ b/integration-tests/test-extension/tests/src/test/java/io/quarkus/it/extension/it/TestAvroMultimoduleIT.java @@ -0,0 +1,31 @@ +package io.quarkus.it.extension.it; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.util.List; +import java.util.Map; + +import org.apache.maven.shared.invoker.MavenInvocationException; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIfSystemProperty; + +import io.quarkus.maven.it.MojoTestBase; +import io.quarkus.maven.it.verifier.MavenProcessInvocationResult; +import io.quarkus.maven.it.verifier.RunningInvoker; + +/** + * Be aware! This test will not run if the name does not start with 'Test'. + */ +@Disabled("https://github.com/quarkusio/quarkus/issues/27057") +@DisabledIfSystemProperty(named = "quarkus.test.native", matches = "true") +public class TestAvroMultimoduleIT extends MojoTestBase { + @Test + public void testThatTheTestsPassed() throws MavenInvocationException, InterruptedException { + File testDir = initProject("projects/avro-multimodule-project", "projects/avro-multimodule-project-build"); + RunningInvoker running = new RunningInvoker(testDir, false); + MavenProcessInvocationResult result = running.execute(List.of("clean", "test"), Map.of()); + assertThat(result.getProcess().waitFor()).isZero(); + } +} diff --git a/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module1/pom.xml b/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module1/pom.xml new file mode 100644 index 0000000000000..2b02702aeb876 --- /dev/null +++ b/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module1/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + + org.acme + avro-multimodule-project + 999-SNAPSHOT + + + module1 + + + + io.quarkus + quarkus-avro + + + diff --git a/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module1/src/main/avro/movie.avsc b/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module1/src/main/avro/movie.avsc new file mode 100644 index 0000000000000..bc5d617b4df0c --- /dev/null +++ b/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module1/src/main/avro/movie.avsc @@ -0,0 +1,11 @@ +{ + "namespace": "org.acme.quarkus", + "type": "record", + "name": "Movie", + "fields": [ + { + "name": "title", + "type": "string" + } + ] +} diff --git a/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module2/pom.xml b/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module2/pom.xml new file mode 100644 index 0000000000000..9f71a1b82259f --- /dev/null +++ b/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module2/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + + org.acme + avro-multimodule-project + 999-SNAPSHOT + + + module2 + + + + org.acme + module1 + 999-SNAPSHOT + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-junit5 + test + + + diff --git a/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module2/src/main/java/org/acme/MovieSerde.java b/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module2/src/main/java/org/acme/MovieSerde.java new file mode 100644 index 0000000000000..391a6a66674c7 --- /dev/null +++ b/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module2/src/main/java/org/acme/MovieSerde.java @@ -0,0 +1,37 @@ +package org.acme; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import jakarta.enterprise.context.ApplicationScoped; + +import org.acme.quarkus.Movie; +import org.apache.avro.file.DataFileStream; +import org.apache.avro.file.DataFileWriter; +import org.apache.avro.io.DatumReader; +import org.apache.avro.io.DatumWriter; +import org.apache.avro.specific.SpecificDatumReader; +import org.apache.avro.specific.SpecificDatumWriter; + +@ApplicationScoped +public class MovieSerde { + public byte[] serialize(Movie movie) throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + DatumWriter movieWriter = new SpecificDatumWriter<>(Movie.class); + try (DataFileWriter writer = new DataFileWriter<>(movieWriter)) { + writer.create(Movie.getClassSchema(), out); + writer.append(movie); + writer.flush(); + } + return out.toByteArray(); + } + + public Movie deserialize(byte[] bytes) throws IOException { + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + DatumReader movieReader = new SpecificDatumReader<>(Movie.class); + try (DataFileStream movieStream = new DataFileStream<>(in, movieReader)) { + return movieStream.next(); + } + } +} diff --git a/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module2/src/test/java/org/acme/MovieSerdeTest.java b/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module2/src/test/java/org/acme/MovieSerdeTest.java new file mode 100644 index 0000000000000..a0f9f3a6e58bf --- /dev/null +++ b/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/module2/src/test/java/org/acme/MovieSerdeTest.java @@ -0,0 +1,25 @@ +package org.acme; + +import jakarta.inject.Inject; +import org.acme.quarkus.Movie; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@QuarkusTest +public class MovieSerdeTest { + @Inject + MovieSerde serializer; + + @Test + void test() throws Exception { + Movie movie = new Movie("my-movie"); + + byte[] serializedMovie = serializer.serialize(movie); + Movie deserialized = serializer.deserialize(serializedMovie); + + assertEquals(deserialized, movie); + } +} diff --git a/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/pom.xml b/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/pom.xml new file mode 100644 index 0000000000000..657e9c22e276b --- /dev/null +++ b/integration-tests/test-extension/tests/src/test/resources-filtered/projects/avro-multimodule-project/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + + org.acme + avro-multimodule-project + 999-SNAPSHOT + pom + + + UTF-8 + UTF-8 + + 17 + + ${compiler-plugin.version} + 3.5.2 + @project.version@ + + + + + + io.quarkus + quarkus-bom + \${version.quarkus} + pom + import + + + + + + module1 + module2 + + + + + + io.quarkus + quarkus-maven-plugin + \${version.quarkus} + true + + + + build + generate-code + generate-code-tests + + + + + + org.apache.maven.plugins + maven-compiler-plugin + \${version.maven-compiler-plugin} + + true + + + + org.apache.maven.plugins + maven-surefire-plugin + \${version.maven-surefire-plugin} + + + org.jboss.logmanager.LogManager + \${maven.home} + + + + + +