Skip to content

Commit

Permalink
Testing: add reproducer for testing bug with multi-module project and…
Browse files Browse the repository at this point in the history
… Avro
  • Loading branch information
Ladicek committed Jan 7, 2025
1 parent 603b6d6 commit 0d406b9
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.acme</groupId>
<artifactId>avro-multimodule-project</artifactId>
<version>999-SNAPSHOT</version>
</parent>

<artifactId>module1</artifactId>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-avro</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"namespace": "org.acme.quarkus",
"type": "record",
"name": "Movie",
"fields": [
{
"name": "title",
"type": "string"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.acme</groupId>
<artifactId>avro-multimodule-project</artifactId>
<version>999-SNAPSHOT</version>
</parent>

<artifactId>module2</artifactId>

<dependencies>
<dependency>
<groupId>org.acme</groupId>
<artifactId>module1</artifactId>
<version>999-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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<Movie> movieWriter = new SpecificDatumWriter<>(Movie.class);
try (DataFileWriter<Movie> 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<Movie> movieReader = new SpecificDatumReader<>(Movie.class);
try (DataFileStream<Movie> movieStream = new DataFileStream<>(in, movieReader)) {
return movieStream.next();
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<groupId>org.acme</groupId>
<artifactId>avro-multimodule-project</artifactId>
<version>999-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<maven.compiler.release>17</maven.compiler.release>

<version.maven-compiler-plugin>${compiler-plugin.version}</version.maven-compiler-plugin>
<version.maven-surefire-plugin>3.5.2</version.maven-surefire-plugin>
<version.quarkus>@project.version@</version.quarkus>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>\${version.quarkus}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<modules>
<module>module1</module>
<module>module2</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>\${version.quarkus}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>\${version.maven-compiler-plugin}</version>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>\${version.maven-surefire-plugin}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>\${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit 0d406b9

Please sign in to comment.