Skip to content

Commit 432bde0

Browse files
committed
adding new module to write tests that require java 17 features
1 parent 574cf48 commit 432bde0

File tree

4 files changed

+211
-0
lines changed

4 files changed

+211
-0
lines changed

.github/workflows/test-lang-java.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,42 @@ jobs:
149149
- name: Run Interop Tests
150150
working-directory: lang/java/ipc
151151
run: mvn -B test -P interop-data-test
152+
153+
testJava17:
154+
name: Java ${{ matrix.java }} Test
155+
runs-on: ubuntu-latest
156+
strategy:
157+
matrix:
158+
java:
159+
- '17'
160+
- '18'
161+
- '19'
162+
steps:
163+
- uses: actions/checkout@v2
164+
165+
- name: Cache Local Maven Repository
166+
uses: actions/cache@v2
167+
with:
168+
path: ~/.m2/repository
169+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
170+
restore-keys: |
171+
${{ runner.os }}-maven-
172+
173+
- name: Setup Temurin JDK
174+
if: matrix.java == '17'
175+
uses: actions/setup-java@v2
176+
with:
177+
distribution: 'temurin'
178+
java-version: ${{ matrix.java }}
179+
180+
- name: Setup Oracle JDK
181+
if: matrix.java == '18' || matrix.java == '19'
182+
uses: oracle-actions/setup-java@v1
183+
with:
184+
website: jdk.java.net
185+
release: ${{ matrix.java }}
186+
version: latest
187+
188+
- name: Run Interop Tests
189+
working-directory: lang/java
190+
run: mvn -B test -P java17

lang/java/java17-test/pom.xml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
https://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
20+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<parent>
24+
<artifactId>avro-parent</artifactId>
25+
<groupId>org.apache.avro</groupId>
26+
<version>1.12.0-SNAPSHOT</version>
27+
<relativePath>../</relativePath>
28+
</parent>
29+
30+
<artifactId>java17-test</artifactId>
31+
<name>Avro Java 17 Tests</name>
32+
<description>Unit tests that require java 17 language support.</description>
33+
<url>https://avro.apache.org/</url>
34+
35+
<properties>
36+
<maven.compiler.target>17</maven.compiler.target>
37+
<maven.compiler.source>17</maven.compiler.source>
38+
</properties>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>org.apache.avro</groupId>
43+
<artifactId>avro</artifactId>
44+
<version>${project.version}</version>
45+
</dependency>
46+
</dependencies>
47+
48+
<build>
49+
<pluginManagement>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-compiler-plugin</artifactId>
54+
</plugin>
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-checkstyle-plugin</artifactId>
58+
<configuration>
59+
<consoleOutput>true</consoleOutput>
60+
<configLocation>checkstyle.xml</configLocation>
61+
</configuration>
62+
<executions>
63+
<execution>
64+
<id>checkstyle-check</id>
65+
<phase>test</phase>
66+
<goals>
67+
<goal>check</goal>
68+
</goals>
69+
</execution>
70+
</executions>
71+
</plugin>
72+
<plugin>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-deploy-plugin</artifactId>
75+
<configuration>
76+
<skip>true</skip>
77+
</configuration>
78+
</plugin>
79+
</plugins>
80+
</pluginManagement>
81+
</build>
82+
83+
</project>
84+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.avro.reflect;
20+
21+
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assert.assertNotNull;
23+
24+
import java.io.ByteArrayInputStream;
25+
import java.io.ByteArrayOutputStream;
26+
import java.io.IOException;
27+
import java.io.UncheckedIOException;
28+
29+
import org.apache.avro.Schema;
30+
import org.apache.avro.file.DataFileStream;
31+
import org.apache.avro.file.DataFileWriter;
32+
import org.apache.avro.io.DatumReader;
33+
import org.junit.Test;
34+
35+
/**
36+
* Simulates a record in behavior only. This way it can run on all supported
37+
* version of java To simulate has a class with final variables and a single
38+
* constructor matching variables This class has the RecordEncoding annotation
39+
* attached
40+
*
41+
*/
42+
public class TestJavaRecordEncoder {
43+
44+
@Test
45+
public void testEncoderOnTopLevelField() throws IOException {
46+
Custom in = new Custom("hello world");
47+
byte[] encoded = write(in);
48+
Custom decoded = read(encoded);
49+
50+
assertNotNull(decoded);
51+
assertEquals("hello world", decoded.field());
52+
}
53+
54+
private <T> T read(byte[] toDecode) throws IOException {
55+
DatumReader<T> datumReader = new ReflectDatumReader<>();
56+
try (DataFileStream<T> dataFileReader = new DataFileStream<>(new ByteArrayInputStream(toDecode, 0, toDecode.length),
57+
datumReader);) {
58+
dataFileReader.hasNext();
59+
return dataFileReader.next();
60+
}
61+
}
62+
63+
private <T> byte[] write(T custom) {
64+
Schema schema = ReflectData.get().getSchema(custom.getClass());
65+
ReflectDatumWriter<T> datumWriter = new ReflectDatumWriter<>();
66+
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
67+
DataFileWriter<T> writer = new DataFileWriter<>(datumWriter)) {
68+
writer.create(schema, baos);
69+
writer.append(custom);
70+
writer.flush();
71+
return baos.toByteArray();
72+
} catch (IOException e) {
73+
throw new UncheckedIOException(e);
74+
}
75+
}
76+
77+
@AvroEncode(using = ReflectRecordEncoding.class)
78+
public static record Custom(String field) {}
79+
80+
81+
}

lang/java/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,13 @@
471471
<hadoop.version>2.10.1</hadoop.version>
472472
</properties>
473473
</profile>
474+
<profile>
475+
<id>java17</id>
476+
<modules>
477+
<module>avro</module>
478+
<module>java17-test</module>
479+
</modules>
480+
</profile>
474481
</profiles>
475482

476483
<!-- dependencyManagement can be used to define dependency versions, scopes, and

0 commit comments

Comments
 (0)