You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by rs...@apache.org on 2022/09/14 18:32:58 UTC

[avro] branch branch-1.11 updated (12edf207e -> d75abd591)

This is an automated email from the ASF dual-hosted git repository.

rskraba pushed a change to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


    from 12edf207e Bump wasm-bindgen-test from 0.3.32 to 0.3.33 in /lang/rust (#1864)
     new 7464920d0 AVRO-2831: add ResolverTest (#1858)
     new d75abd591 AVRO-3628: [Java] JUnit 4.x tests are not executed (#1863)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../avro-service-archetype/src/main/pom/pom.xml    |   8 +-
 .../SimpleOrderServiceIntegrationTest.java         |  18 +--
 .../src/main/java/org/apache/avro/Resolver.java    |  10 +-
 .../test/java/org/apache/avro/TestResolver.java    | 122 +++++++++++++++++++++
 lang/java/maven-plugin/pom.xml                     |   3 +-
 lang/java/pom.xml                                  |  10 +-
 6 files changed, 143 insertions(+), 28 deletions(-)
 create mode 100644 lang/java/avro/src/test/java/org/apache/avro/TestResolver.java


[avro] 02/02: AVRO-3628: [Java] JUnit 4.x tests are not executed (#1863)

Posted by rs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rskraba pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git

commit d75abd591540ef34a334a3d73314f2748c8d868d
Author: Martin Grigorov <ma...@users.noreply.github.com>
AuthorDate: Wed Sep 14 21:29:10 2022 +0300

    AVRO-3628: [Java] JUnit 4.x tests are not executed (#1863)
    
    * AVRO-3628: [Java] JUnit 4.x tests are not executed
    
    Use JUnit 5.x Vintage engine instead of JUnit 4.x
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    
    * AVRO-3628: Migrate avro-service-archetype tests to JUnit 5.x
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
---
 .../avro-service-archetype/src/main/pom/pom.xml        |  8 ++++----
 .../integration/SimpleOrderServiceIntegrationTest.java | 18 +++++++++---------
 lang/java/maven-plugin/pom.xml                         |  3 ++-
 lang/java/pom.xml                                      | 10 +++++-----
 4 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/lang/java/archetypes/avro-service-archetype/src/main/pom/pom.xml b/lang/java/archetypes/avro-service-archetype/src/main/pom/pom.xml
index 20455fa77..d8d6d7685 100644
--- a/lang/java/archetypes/avro-service-archetype/src/main/pom/pom.xml
+++ b/lang/java/archetypes/avro-service-archetype/src/main/pom/pom.xml
@@ -35,7 +35,7 @@
   <properties>
     <avro.version>${project.version}</avro.version>
     <jackson-bom.version>${jackson-bom.version}</jackson-bom.version>
-    <junit.version>${junit.version}</junit.version>
+    <junit5.version>${junit5.version}</junit5.version>
     <logback.version>1.2.3</logback.version>
     <slf4j.version>${slf4j.version}</slf4j.version>
   </properties>
@@ -79,9 +79,9 @@
       <version>\${logback.version}</version>
     </dependency>
     <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>\${junit.version}</version>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter</artifactId>
+      <version>\${junit5.version}</version>
       <scope>test</scope>
     </dependency>
   </dependencies>
diff --git a/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/test/java/integration/SimpleOrderServiceIntegrationTest.java b/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/test/java/integration/SimpleOrderServiceIntegrationTest.java
index e5d6ad7e5..0796826e0 100644
--- a/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/test/java/integration/SimpleOrderServiceIntegrationTest.java
+++ b/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/test/java/integration/SimpleOrderServiceIntegrationTest.java
@@ -21,8 +21,8 @@
 
 package ${package}.integration;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
@@ -30,9 +30,9 @@ import java.util.List;
 
 import ${package}.transport.SimpleOrderServiceEndpoint;
 import ${package}.transport.SimpleOrderServiceClient;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
 import ${package}.service.Confirmation;
 import ${package}.service.Item;
@@ -42,13 +42,13 @@ import ${package}.service.Order;
  * <code>SimpleOrderServiceIntegrationTest</code> runs as part of the Integration phase of the build and is
  * meant for end to end service testing.
  */
-public class SimpleOrderServiceIntegrationTest {
+class SimpleOrderServiceIntegrationTest {
 
   private static SimpleOrderServiceEndpoint service;
   private static SimpleOrderServiceClient client;
 
   @Test
-  public void simpleRoundTripTest() throws Exception {
+  void simpleRoundTripTest() throws Exception {
     Order simpleOrder = createOrder();
     Confirmation c = client.submitOrder(simpleOrder);
 
@@ -57,7 +57,7 @@ public class SimpleOrderServiceIntegrationTest {
     assertTrue(c.getEstimatedCompletion() > 0);
   }
 
-  @BeforeClass
+  @BeforeAll
   public static void setupTransport() throws Exception {
     InetSocketAddress endpointAddress = new InetSocketAddress("0.0.0.0", 12345);
     service = new SimpleOrderServiceEndpoint(endpointAddress);
@@ -67,7 +67,7 @@ public class SimpleOrderServiceIntegrationTest {
     client.start();
   }
 
-  @AfterClass
+  @AfterAll
   public static void shutdownTransport() throws Exception {
     client.stop();
     service.stop();
diff --git a/lang/java/maven-plugin/pom.xml b/lang/java/maven-plugin/pom.xml
index e128ec707..65b280145 100644
--- a/lang/java/maven-plugin/pom.xml
+++ b/lang/java/maven-plugin/pom.xml
@@ -24,7 +24,7 @@
     <artifactId>avro-parent</artifactId>
     <groupId>org.apache.avro</groupId>
     <version>1.11.2-SNAPSHOT</version>
-    <relativePath>../</relativePath>
+    <relativePath>../pom.xml</relativePath>
   </parent>
 
   <artifactId>avro-maven-plugin</artifactId>
@@ -60,6 +60,7 @@
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-core</artifactId>
       <version>${maven-core.version}</version>
+      <scope>provided</scope>
       <exclusions>
         <exclusion>
           <groupId>com.google.code.findbugs</groupId>
diff --git a/lang/java/pom.xml b/lang/java/pom.xml
index a3bfeac29..a8ed0bdfd 100644
--- a/lang/java/pom.xml
+++ b/lang/java/pom.xml
@@ -42,7 +42,6 @@
     <servlet-api.version>4.0.1</servlet-api.version>
     <jetty.version>9.4.48.v20220622</jetty.version>
     <jopt-simple.version>5.0.4</jopt-simple.version>
-    <junit.version>4.13.2</junit.version>
     <junit5.version>5.9.0</junit5.version>
     <netty.version>4.1.81.Final</netty.version>
     <protobuf.version>3.21.5</protobuf.version>
@@ -157,13 +156,14 @@
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-surefire-plugin</artifactId>
+          <version>3.0.0-M7</version>
           <configuration>
             <includes>
               <!-- Avro naming convention for JUnit tests -->
               <include>**/Test**</include>
             </includes>
             <excludes>
-              <!-- A few innner classes are not to be tested -->
+              <!-- A few inner classes are not to be tested -->
               <exclude>**/*$*</exclude>
               <!-- exclude the generated classes under apache.avro.test, some of
                 these match **/Test** and are not JUnit tests -->
@@ -592,9 +592,9 @@
     will inherit these dependencies directly, and can opt out if necessary with <excludes> -->
   <dependencies>
     <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>${junit.version}</version>
+      <groupId>org.junit.vintage</groupId>
+      <artifactId>junit-vintage-engine</artifactId>
+      <version>${junit5.version}</version>
       <scope>test</scope>
     </dependency>
     <dependency>


[avro] 01/02: AVRO-2831: add ResolverTest (#1858)

Posted by rs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rskraba pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git

commit 7464920d0577c8466f3cd6165538fc0bfb05d089
Author: clesaec <51...@users.noreply.github.com>
AuthorDate: Fri Sep 9 18:54:06 2022 +0200

    AVRO-2831: add ResolverTest (#1858)
    
    * AVRO-2831: add unit test on Avro
    
    * AVRO-2831: add unit test on Avro
    
    * AVRO-2831: Add license to TestResolver.java
---
 .../src/main/java/org/apache/avro/Resolver.java    |  10 +-
 .../test/java/org/apache/avro/TestResolver.java    | 122 +++++++++++++++++++++
 2 files changed, 123 insertions(+), 9 deletions(-)

diff --git a/lang/java/avro/src/main/java/org/apache/avro/Resolver.java b/lang/java/avro/src/main/java/org/apache/avro/Resolver.java
index 9db847c2c..117c9e391 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/Resolver.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/Resolver.java
@@ -286,16 +286,10 @@ public class Resolver {
         throw new IllegalArgumentException("Only use when reader and writer are different.");
       Schema.Type wt = w.getType();
       switch (r.getType()) {
-      case INT:
-        switch (wt) {
-        case INT:
-          return true;
-        }
-        break;
+
       case LONG:
         switch (wt) {
         case INT:
-        case LONG:
           return true;
         }
         break;
@@ -303,7 +297,6 @@ public class Resolver {
         switch (wt) {
         case INT:
         case LONG:
-        case FLOAT:
           return true;
         }
         break;
@@ -312,7 +305,6 @@ public class Resolver {
         case INT:
         case LONG:
         case FLOAT:
-        case DOUBLE:
           return true;
         }
         break;
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestResolver.java b/lang/java/avro/src/test/java/org/apache/avro/TestResolver.java
new file mode 100644
index 000000000..1d3919319
--- /dev/null
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestResolver.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.avro.data.TimeConversions;
+import org.apache.avro.generic.IndexedRecord;
+import org.apache.avro.io.DatumReader;
+import org.apache.avro.io.DecoderFactory;
+import org.apache.avro.io.FastReaderBuilder;
+import org.apache.avro.io.JsonDecoder;
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class TestResolver {
+
+  /**
+   * Test promote action INT -> LONG, with logical type for LONG.
+   */
+  @Test
+  void resolveTime() {
+    final Schema writeSchema = Schema.create(Schema.Type.INT);
+    final Schema readSchema = new TimeConversions.TimeMicrosConversion().getRecommendedSchema(); // LONG
+
+    Resolver.Action action = Resolver.resolve(writeSchema, readSchema);
+    Assertions.assertNotNull(action);
+    MatcherAssert.assertThat("Wrong class for action", action, Matchers.instanceOf(Resolver.Promote.class));
+    Assertions.assertEquals(action.type, Resolver.Action.Type.PROMOTE);
+    Assertions.assertNotNull(action.logicalType);
+  }
+
+  /**
+   * Test union type with promote action INT -> LONG, with logical type for LONG.
+   */
+  @Test
+  void resolveUnion() {
+    final Schema schema = new TimeConversions.TimeMicrosConversion().getRecommendedSchema();
+
+    final Schema writeSchema = Schema.createUnion(Schema.create(Schema.Type.INT));
+    final Schema readSchema = Schema.createUnion(schema);
+
+    Resolver.Action action = Resolver.resolve(writeSchema, readSchema);
+    Assertions.assertNotNull(action);
+    Assertions.assertEquals(action.type, Resolver.Action.Type.WRITER_UNION);
+    MatcherAssert.assertThat("Wrong class for action", action, Matchers.instanceOf(Resolver.WriterUnion.class));
+
+    Assertions.assertEquals(1, ((Resolver.WriterUnion) action).actions.length);
+    Resolver.Action innerAction = ((Resolver.WriterUnion) action).actions[0];
+
+    MatcherAssert.assertThat("Wrong class for action", innerAction, Matchers.instanceOf(Resolver.ReaderUnion.class));
+    Resolver.ReaderUnion innerUnionAction = (Resolver.ReaderUnion) innerAction;
+    Resolver.Action promoteAction = innerUnionAction.actualAction;
+    Assertions.assertEquals(promoteAction.type, Resolver.Action.Type.PROMOTE);
+    Assertions.assertNotNull(promoteAction.logicalType);
+  }
+
+  @Test
+  void resolveEnum() throws IOException {
+    final Schema writeSchema = Schema.createEnum("myEnum", "", "n1", Arrays.asList("e1", "e3", "e4"));
+    final Schema readSchema = Schema.createEnum("myEnum", "", "n1", Arrays.asList("e1", "e2", "e3"), "e2");
+
+    Resolver.Action action = Resolver.resolve(writeSchema, readSchema);
+    Assertions.assertNotNull(action);
+    Assertions.assertEquals(action.type, Resolver.Action.Type.ENUM);
+    MatcherAssert.assertThat("Wrong class for action", action, Matchers.instanceOf(Resolver.EnumAdjust.class));
+    Resolver.EnumAdjust adjust = (Resolver.EnumAdjust) action;
+
+    Assertions.assertArrayEquals(new int[] { 0, 2, 1 }, adjust.adjustments);
+    Assertions.assertEquals("e1", adjust.values[0].toString());
+    Assertions.assertEquals("e3", adjust.values[1].toString());
+    Assertions.assertEquals("e2", adjust.values[2].toString());
+
+    FastReaderBuilder reader = FastReaderBuilder.get();
+    Schema writeRecord = Schema.createRecord("rec1", "", "", false,
+        Arrays.asList(new Schema.Field("f1", writeSchema, "")));
+    Schema readRecord = Schema.createRecord("rec1", "", "", false,
+        Arrays.asList(new Schema.Field("f1", readSchema, "")));
+    DatumReader<Object> datumReader = reader.createDatumReader(writeRecord, readRecord);
+    JsonDecoder e2 = DecoderFactory.get().jsonDecoder(readRecord, "{ \"f1\" : \"e2\" }");
+    Object read = datumReader.read(null, e2);
+    Assertions.assertNotNull(read);
+    MatcherAssert.assertThat("", read, Matchers.instanceOf(IndexedRecord.class));
+    IndexedRecord result = (IndexedRecord) read;
+    Assertions.assertEquals("e3", result.get(0).toString());
+  }
+
+  @Test
+  void promoteIsValid() {
+    Assertions.assertThrows(IllegalArgumentException.class,
+        () -> Resolver.Promote.isValid(Schema.create(Schema.Type.INT), Schema.create(Schema.Type.INT)));
+
+    Assertions.assertTrue(Resolver.Promote.isValid(Schema.create(Schema.Type.INT), Schema.create(Schema.Type.LONG)));
+    Assertions.assertFalse(Resolver.Promote.isValid(Schema.create(Schema.Type.LONG), Schema.create(Schema.Type.INT)));
+
+    Assertions.assertTrue(Resolver.Promote.isValid(Schema.create(Schema.Type.INT), Schema.create(Schema.Type.FLOAT)));
+    Assertions.assertFalse(Resolver.Promote.isValid(Schema.create(Schema.Type.FLOAT), Schema.create(Schema.Type.INT)));
+
+    Assertions
+        .assertTrue(Resolver.Promote.isValid(Schema.create(Schema.Type.FLOAT), Schema.create(Schema.Type.DOUBLE)));
+    Assertions
+        .assertFalse(Resolver.Promote.isValid(Schema.create(Schema.Type.DOUBLE), Schema.create(Schema.Type.FLOAT)));
+  }
+}