Skip to content

Commit

Permalink
feat: Update for Avro 1.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanSkraba committed Oct 4, 2024
1 parent 37d2987 commit e27c526
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,61 +336,57 @@ object AvroTestResources {
Base
.resolve("plugin/src/test/avro/com/skraba/avro/enchiridion/simple")
.createDirectory()
.resolve("SimpleEnum.avsc")
.resolve("DateLogicalTypeOptionalRecord.avsc")
.toFile
.writeAll(Json.prettyPrint(Json.parse(SimpleEnum)))
.writeAll(Json.prettyPrint(DateLogicalTypeOptionalRecord))
Base
.resolve("plugin/src/test/avro/com/skraba/avro/enchiridion/simple")
.createDirectory()
.resolve("SimpleFixed.avsc")
.resolve("DateLogicalTypeRecord.avsc")
.toFile
.writeAll(Json.prettyPrint(Json.parse(SimpleFixed)))
.writeAll(Json.prettyPrint(DateLogicalTypeRecord))
Base
.resolve("plugin/src/test/avro/com/skraba/avro/enchiridion/simple")
.createDirectory()
.resolve("SimpleEnum.avsc")
.resolve("DecimalLogicalTypeRecord.avsc")
.toFile
.writeAll(Json.prettyPrint(Json.parse(SimpleRecord)))

.writeAll(Json.prettyPrint(DecimalLogicalTypeRecord))
Base
.resolve("plugin/src/main/avro/com/skraba/avro/enchiridion/recipe")
.createDirectory()
.resolve("Recipe.avsc")
.toFile
.writeAll(Json.prettyPrint(Json.parse(Recipe)))

Base
.resolve("plugin/src/test/avro/com/skraba/avro/enchiridion/simple")
.createDirectory()
.resolve("DateLogicalTypeRecord.avsc")
.resolve("SimpleEnum.avsc")
.toFile
.writeAll(Json.prettyPrint(DateLogicalTypeRecord))

.writeAll(Json.prettyPrint(Json.parse(SimpleEnum)))
Base
.resolve("plugin/src/test/avro/com/skraba/avro/enchiridion/simple")
.createDirectory()
.resolve("DateLogicalTypeOptionalRecord.avsc")
.resolve("SimpleFixed.avsc")
.toFile
.writeAll(Json.prettyPrint(DateLogicalTypeOptionalRecord))

.writeAll(Json.prettyPrint(Json.parse(SimpleFixed)))
Base
.resolve("plugin/src/test/avro/com/skraba/avro/enchiridion/simple")
.createDirectory()
.resolve("DecimalLogicalTypeRecord.avsc")
.resolve("SimpleRecord.avsc")
.toFile
.writeAll(Json.prettyPrint(DecimalLogicalTypeRecord))
.writeAll(Json.prettyPrint(Json.parse(SimpleRecord)))

// Rewrite this source itself with prettified JSON.
val schemasToPrettify: Map[String, String] = Map(
"Avro1965" -> Avro1965,
"Avro2299CanonicalMisplacedSize" -> Avro2299CanonicalMisplacedSize,
"Recursive" -> Recursive,
"RecursiveIndirect" -> RecursiveIndirect,
"SimpleArray" -> SimpleArray,
"SimpleEnum" -> SimpleEnum,
"SimpleFixed" -> SimpleFixed,
"SimpleMap" -> SimpleMap,
"SimpleRecord" -> SimpleRecord,
"Recursive" -> Recursive,
"RecursiveIndirect" -> RecursiveIndirect,
"Avro1965" -> Avro1965,
"Avro2299CanonicalMisplacedSize" -> Avro2299CanonicalMisplacedSize
"SimpleRecord" -> SimpleRecord
)
ThisFile.writeAll(
{
Expand Down
2 changes: 1 addition & 1 deletion core-master-snapshot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<properties>
<maven.deploy.skip>false</maven.deploy.skip>
<avro.major.version>1.11</avro.major.version>
<avro.version>1.12.0-SNAPSHOT</avro.version>
<avro.version>1.13.0-SNAPSHOT</avro.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class AggregatedSnapshotTest extends Aggregated {
@Test
public void testAvroVersion() {
assertThat(AvroVersion.avro_infinity.before("Next major version"), is(true));
assertThat(AvroVersion.avro_1_12.orAfter("This major version"), is(true));
assertThat(AvroVersion.getInstalledAvro(), is(AvroVersion.avro_1_12));
assertThat(AvroVersion.avro_1_13.orAfter("This major version"), is(true));
assertThat(AvroVersion.getInstalledAvro(), is(AvroVersion.avro_1_13));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.nio.ByteBuffer;
import java.util.*;
import java.util.function.Function;
import org.apache.avro.AvroTypeException;
import org.apache.avro.Schema;
import org.apache.avro.SchemaBuilder;
import org.apache.avro.generic.*;
Expand Down Expand Up @@ -637,13 +638,18 @@ public void testRoundTripEnum() {
assertThat((GenericEnumSymbol<?>) fromBytes(GenericData.get(), schema, value))
.hasToString("W"));

// TODO: The error message here doesn't seem quite right! Raise an AVRO JIRA?
assertThatThrownBy(() -> toBytes(schema, new GenericData.EnumSymbol(schema, "A")))
.isInstanceOf(NullPointerException.class)
.hasMessageContaining(
AvroVersion.avro_1_11.before("Changed exception message in 1.11.1")
? "null of E1"
: "null value for (non-nullable) E1");
if (AvroVersion.avro_1_12.orAfter("Changed exception type in 1.12.0")) {
assertThatThrownBy(() -> toBytes(schema, new GenericData.EnumSymbol(schema, "A")))
.isInstanceOf(AvroTypeException.class)
.hasMessageContaining("enum value 'A' is not in the enum symbol set: [Z, Y, X, W]");
} else {
assertThatThrownBy(() -> toBytes(schema, new GenericData.EnumSymbol(schema, "A")))
.isInstanceOf(NullPointerException.class)
.hasMessageContaining(
AvroVersion.avro_1_11.before("Changed exception message in 1.11.1")
? "null of E1"
: "null value for (non-nullable) E1");
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.skraba.avro.enchiridion.testkit.AvroVersion;
import org.apache.avro.Schema;
import org.apache.avro.SchemaParseException;
import org.apache.avro.generic.GenericData;
Expand All @@ -36,6 +37,8 @@ public void testBasicString() {

@Test
public void testNotCaseInsensitive() {
assertThrows(SchemaParseException.class, () -> api().parse(qqify("'String'")));
if (AvroVersion.avro_1_12.before("TODO: Is this an error in 1.12.0?"))
assertThrows(SchemaParseException.class, () -> api().parse(qqify("'String'")));
else assertThrows(NullPointerException.class, () -> api().parse(qqify("'String'")));
}
}
45 changes: 45 additions & 0 deletions core111x/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.skraba.avro.enchiridion</groupId>
<artifactId>avro-enchiridion</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>avro-enchiridion-core111x</artifactId>
<packaging>jar</packaging>

<name>Avro Enchiridion :: Core 1.11.x</name>
<description>Avro core examples with the latest 1.11.x version.</description>

<properties>
<maven.deploy.skip>false</maven.deploy.skip>
<avro.major.version>1.11</avro.major.version>
<avro.version>1.11.4</avro.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
</dependency>

<!-- Tests -->
<dependency>
<groupId>com.skraba.avro.enchiridion</groupId>
<artifactId>avro-enchiridion-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.skraba.avro.enchiridion</groupId>
<artifactId>avro-enchiridion-testkit</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
4 changes: 4 additions & 0 deletions core111x/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Core 1.11.x Tests
==============================================================================

Runs some or all of the [Avro core](../core/readme.md) tests using Avro 1.11.x libraries.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.skraba.avro.enchiridion.core111x;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

import com.skraba.avro.enchiridion.core.Aggregated;
import com.skraba.avro.enchiridion.testkit.AvroVersion;
import org.junit.jupiter.api.Test;

public class Aggregated111Test extends Aggregated {

@Test
public void testAvroVersion() {
assertThat(AvroVersion.avro_1_11.before("This major version"), is(false));
assertThat(AvroVersion.avro_1_11.orAfter("This major version"), is(true));
assertThat(AvroVersion.avro_1_12.before("Next major version"), is(true));
assertThat(AvroVersion.avro_1_12.orAfter("Next major version"), is(false));
assertThat(AvroVersion.getInstalledAvro(), is(AvroVersion.avro_1_11));
}
}
6 changes: 6 additions & 0 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<artifactId>avro-enchiridion-resources</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.skraba.avro.enchiridion</groupId>
<artifactId>avro-enchiridion-testkit</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
{
"type" : "record",
"name" : "SimpleRecord",
"type" : "enum",
"name" : "SimpleEnum",
"namespace" : "com.skraba.avro.enchiridion.simple",
"doc" : "Simple two column record",
"fields" : [ {
"name" : "id",
"type" : "long"
}, {
"name" : "name",
"type" : "string"
} ]
"symbols" : [ "e1", "e2", "e3" ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import static com.skraba.avro.enchiridion.plugin.SimpleRecordTest.fromBytes;
import static com.skraba.avro.enchiridion.plugin.SimpleRecordTest.toBytes;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.skraba.avro.enchiridion.iddl.goto$.case$;
import com.skraba.avro.enchiridion.idl.Avro2956ReservedKeywordWrapper;
import com.skraba.avro.enchiridion.idl.break$.static$;
import com.skraba.avro.enchiridion.testkit.AvroVersion;
import com.skraba.avro.enchiridion.testkit.EnabledForAvroVersion;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.specific.SpecificData;
Expand All @@ -20,6 +20,7 @@
public class Avro2956ReservedKeywordTest {

@Test
@EnabledForAvroVersion(until = AvroVersion.avro_1_12, reason = "Fixed in Avro 1.12.0")
public void testBasic() {

// Start with a simple serialized long.
Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<module>avro-resources</module>
<module>core</module>
<module>core-master-snapshot</module>
<module>core111x</module>
<module>core110x</module>
<module>core19x</module>
<module>core18x</module>
Expand All @@ -37,7 +38,7 @@

<!-- Dependencies -->
<assertj.version>3.23.1</assertj.version>
<avro.version>1.11.3</avro.version>
<avro.version>1.12.0</avro.version>
<docopt.version>0.6.0.20150202</docopt.version>
<hamcrest.version>2.2</hamcrest.version>
<joda.version>2.11.1</joda.version>
Expand Down Expand Up @@ -204,6 +205,11 @@
</dependency>

<!-- Scala -->
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum AvroVersion {
avro_1_10,
avro_1_11,
avro_1_12,
avro_1_13,
/** An avro version far, far off in the future. */
avro_infinity;

Expand Down

0 comments on commit e27c526

Please sign in to comment.