diff --git a/build/parents/build/pom.xml b/build/parents/build/pom.xml index e4f203259ae..195a11a1fbf 100644 --- a/build/parents/build/pom.xml +++ b/build/parents/build/pom.xml @@ -127,6 +127,7 @@ 3.0.0-beta-10 3.13.0 3.6.1 + 1.11.3 5.1.1.Final diff --git a/mapper/orm-outbox-polling/src/test/java/org/hibernate/search/mapper/orm/outboxpolling/avro/impl/EventPayloadSerializationUtilsTest.java b/mapper/orm-outbox-polling/src/test/java/org/hibernate/search/mapper/orm/outboxpolling/avro/impl/EventPayloadSerializationUtilsTest.java new file mode 100644 index 00000000000..762bd690d4c --- /dev/null +++ b/mapper/orm-outbox-polling/src/test/java/org/hibernate/search/mapper/orm/outboxpolling/avro/impl/EventPayloadSerializationUtilsTest.java @@ -0,0 +1,96 @@ +/* + * Hibernate Search, full-text search for your domain model + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.search.mapper.orm.outboxpolling.avro.impl; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Fail.fail; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.stream.Stream; + +import org.hibernate.search.mapper.pojo.route.DocumentRouteDescriptor; +import org.hibernate.search.mapper.pojo.route.DocumentRoutesDescriptor; +import org.hibernate.search.mapper.pojo.work.spi.DirtinessDescriptor; +import org.hibernate.search.mapper.pojo.work.spi.PojoIndexingQueueEventPayload; + +import org.junit.Ignore; +import org.junit.Test; + +import org.apache.avro.Protocol; + +public class EventPayloadSerializationUtilsTest { + + private static final Set DIRTY_PATHS = Set.of( "a", "b", "c" ); + private static final String ROUTING_KEY = "key1"; + + @Test + @Ignore("Enable this test, or just run it from an IDE once you need to create a new payload for a newer version of Avro.") + public void createNewAvroPayloadFile() throws IOException, URISyntaxException { + PojoIndexingQueueEventPayload payload = new PojoIndexingQueueEventPayload( + new DocumentRoutesDescriptor( + DocumentRouteDescriptor.of( ROUTING_KEY ), + new ArrayList<>( + List.of( DocumentRouteDescriptor.of( "key2" ), DocumentRouteDescriptor.of( "key3" ) ) ) + ), + new DirtinessDescriptor( + true, + true, + DIRTY_PATHS, + false + ) + ); + + byte[] serialized = EventPayloadSerializationUtils.serialize( payload ); + + Path testDataDirectory = payloadTestResourceLocation(); + + Files.createDirectories( testDataDirectory ); + try ( OutputStream out = Files.newOutputStream( + testDataDirectory.resolve( "payload-avro-" + Protocol.class.getPackage().getImplementationVersion() ) ) ) { + out.write( serialized ); + } + } + + @Test + public void canDeserializePreviousPayloads() throws IOException, URISyntaxException { + try ( Stream payloads = Files.list( payloadTestResourceLocation() ) ) { + payloads.forEach( payload -> { + try ( InputStream inputStream = Files.newInputStream( payload ) ) { + PojoIndexingQueueEventPayload deserialized = + EventPayloadSerializationUtils.deserialize( inputStream.readAllBytes() ); + assertThat( deserialized ) + .as( payload.toString() ) + .isNotNull(); + assertThat( deserialized.routes.currentRoute().routingKey() ) + .as( payload.toString() ) + .isEqualTo( ROUTING_KEY ); + assertThat( deserialized.dirtiness.dirtyPaths() ) + .as( payload.toString() ) + .containsAll( DIRTY_PATHS ); + } + catch (IOException e) { + fail( "Cannot read payload from " + payload + ". Reason: " + e ); + } + + } ); + } + } + + private static Path payloadTestResourceLocation() throws URISyntaxException { + return Path.of( + EventPayloadSerializationUtilsTest.class.getProtectionDomain().getCodeSource().getLocation().toURI() ) + .getParent().getParent().resolve( "src/test/resources/avro" ); + } +} diff --git a/mapper/orm-outbox-polling/src/test/resources/avro/payload-avro-1.10.2 b/mapper/orm-outbox-polling/src/test/resources/avro/payload-avro-1.10.2 new file mode 100644 index 00000000000..559d4fcfb0e Binary files /dev/null and b/mapper/orm-outbox-polling/src/test/resources/avro/payload-avro-1.10.2 differ diff --git a/mapper/orm-outbox-polling/src/test/resources/avro/payload-avro-1.11.2 b/mapper/orm-outbox-polling/src/test/resources/avro/payload-avro-1.11.2 new file mode 100644 index 00000000000..682006d12b5 Binary files /dev/null and b/mapper/orm-outbox-polling/src/test/resources/avro/payload-avro-1.11.2 differ diff --git a/mapper/orm-outbox-polling/src/test/resources/avro/payload-avro-1.11.3 b/mapper/orm-outbox-polling/src/test/resources/avro/payload-avro-1.11.3 new file mode 100644 index 00000000000..682006d12b5 Binary files /dev/null and b/mapper/orm-outbox-polling/src/test/resources/avro/payload-avro-1.11.3 differ