This is an automated email from the ASF dual-hosted git repository.
dmollitor pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/main by this push:
new 8c6771143 AVRO-4064: Move relavent unit tests from ipc package to avro
package (#3180)
8c6771143 is described below
commit 8c67711434ff82e769cfe7812424f1f0d6d9ba20
Author: belugabehr <[email protected]>
AuthorDate: Mon Oct 7 07:17:00 2024 -0400
AVRO-4064: Move relavent unit tests from ipc package to avro package (#3180)
---
.../src/test/java/org/apache/avro/TestCompare.java | 23 ----
.../src/test/java/org/apache/avro/TestCompare.java | 126 ---------------------
2 files changed, 149 deletions(-)
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestCompare.java
b/lang/java/avro/src/test/java/org/apache/avro/TestCompare.java
similarity index 89%
copy from lang/java/ipc/src/test/java/org/apache/avro/TestCompare.java
copy to lang/java/avro/src/test/java/org/apache/avro/TestCompare.java
index ccd207130..7e7b36217 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestCompare.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestCompare.java
@@ -28,18 +28,12 @@ import java.nio.ByteBuffer;
import org.apache.avro.generic.GenericArray;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericDatumWriter;
-import org.apache.avro.specific.SpecificData;
-import org.apache.avro.specific.SpecificDatumWriter;
import org.apache.avro.io.BinaryData;
import org.apache.avro.io.DatumWriter;
import org.apache.avro.io.Encoder;
import org.apache.avro.io.EncoderFactory;
import org.apache.avro.util.Utf8;
-import org.apache.avro.test.TestRecord;
-import org.apache.avro.test.Kind;
-import org.apache.avro.test.MD5;
-
public class TestCompare {
@Test
@@ -156,23 +150,6 @@ public class TestCompare {
check("[\"string\", \"long\"]", new Utf8("a"), 1L, false);
}
- @Test
- void specificRecord() throws Exception {
- TestRecord s1 = new TestRecord();
- TestRecord s2 = new TestRecord();
- s1.setName("foo");
- s1.setKind(Kind.BAZ);
- s1.setHash(new MD5(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3,
4, 5 }));
- s2.setName("bar");
- s2.setKind(Kind.BAR);
- s2.setHash(new MD5(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3,
4, 6 }));
- Schema schema = SpecificData.get().getSchema(TestRecord.class);
-
- check(schema, s1, s2, true, new SpecificDatumWriter<>(schema),
SpecificData.get());
- s2.setKind(Kind.BAZ);
- check(schema, s1, s2, true, new SpecificDatumWriter<>(schema),
SpecificData.get());
- }
-
private static <T> void check(String schemaJson, T o1, T o2) throws
Exception {
check(schemaJson, o1, o2, true);
}
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestCompare.java
b/lang/java/ipc/src/test/java/org/apache/avro/TestCompare.java
index ccd207130..26f1a07b1 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestCompare.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestCompare.java
@@ -23,18 +23,14 @@ import java.io.ByteArrayOutputStream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
-import java.nio.ByteBuffer;
-import org.apache.avro.generic.GenericArray;
import org.apache.avro.generic.GenericData;
-import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.specific.SpecificData;
import org.apache.avro.specific.SpecificDatumWriter;
import org.apache.avro.io.BinaryData;
import org.apache.avro.io.DatumWriter;
import org.apache.avro.io.Encoder;
import org.apache.avro.io.EncoderFactory;
-import org.apache.avro.util.Utf8;
import org.apache.avro.test.TestRecord;
import org.apache.avro.test.Kind;
@@ -42,120 +38,6 @@ import org.apache.avro.test.MD5;
public class TestCompare {
- @Test
- void testNull() throws Exception {
- Schema schema = new Schema.Parser().parse("\"null\"");
- byte[] b = render(null, schema, new GenericDatumWriter<>());
- assertEquals(0, BinaryData.compare(b, 0, b, 0, schema));
- }
-
- @Test
- void testBoolean() throws Exception {
- check("\"boolean\"", Boolean.FALSE, Boolean.TRUE);
- }
-
- @Test
- void string() throws Exception {
- check("\"string\"", new Utf8(""), new Utf8("a"));
- check("\"string\"", new Utf8("a"), new Utf8("b"));
- check("\"string\"", new Utf8("a"), new Utf8("ab"));
- check("\"string\"", new Utf8("ab"), new Utf8("b"));
- }
-
- @Test
- void bytes() throws Exception {
- check("\"bytes\"", ByteBuffer.wrap(new byte[] {}), ByteBuffer.wrap(new
byte[] { 1 }));
- check("\"bytes\"", ByteBuffer.wrap(new byte[] { 1 }), ByteBuffer.wrap(new
byte[] { 2 }));
- check("\"bytes\"", ByteBuffer.wrap(new byte[] { 1, 2 }),
ByteBuffer.wrap(new byte[] { 2 }));
- }
-
- @Test
- void testInt() throws Exception {
- check("\"int\"", -1, 0);
- check("\"int\"", 0, 1);
- }
-
- @Test
- void testLong() throws Exception {
- check("\"long\"", 11L, 12L);
- check("\"long\"", (long) -1, 1L);
- }
-
- @Test
- void testFloat() throws Exception {
- check("\"float\"", 1.1f, 1.2f);
- check("\"float\"", (float) -1.1, 1.0f);
- }
-
- @Test
- void testDouble() throws Exception {
- check("\"double\"", 1.2, 1.3);
- check("\"double\"", -1.2, 1.3);
- }
-
- @Test
- void array() throws Exception {
- String json = "{\"type\":\"array\", \"items\": \"long\"}";
- Schema schema = new Schema.Parser().parse(json);
- GenericArray<Long> a1 = new GenericData.Array<>(1, schema);
- a1.add(1L);
- GenericArray<Long> a2 = new GenericData.Array<>(1, schema);
- a2.add(1L);
- a2.add(0L);
- check(json, a1, a2);
- }
-
- @Test
- void record() throws Exception {
- String fields = " \"fields\":[" +
"{\"name\":\"f\",\"type\":\"int\",\"order\":\"ignore\"},"
- + "{\"name\":\"g\",\"type\":\"int\",\"order\":\"descending\"}," +
"{\"name\":\"h\",\"type\":\"int\"}]}";
- String recordJson = "{\"type\":\"record\", \"name\":\"Test\"," + fields;
- Schema schema = new Schema.Parser().parse(recordJson);
- GenericData.Record r1 = new GenericData.Record(schema);
- r1.put("f", 1);
- r1.put("g", 13);
- r1.put("h", 41);
- GenericData.Record r2 = new GenericData.Record(schema);
- r2.put("f", 0);
- r2.put("g", 12);
- r2.put("h", 41);
- check(recordJson, r1, r2);
- r2.put("f", 0);
- r2.put("g", 13);
- r2.put("h", 42);
- check(recordJson, r1, r2);
-
- String record2Json = "{\"type\":\"record\", \"name\":\"Test2\"," + fields;
- Schema schema2 = new Schema.Parser().parse(record2Json);
- GenericData.Record r3 = new GenericData.Record(schema2);
- r3.put("f", 1);
- r3.put("g", 13);
- r3.put("h", 41);
- assert (!r1.equals(r3)); // same fields, diff name
- }
-
- @Test
- void testEnum() throws Exception {
- String json = "{\"type\":\"enum\", \"name\":\"Test\",\"symbols\": [\"A\",
\"B\"]}";
- Schema schema = new Schema.Parser().parse(json);
- check(json, new GenericData.EnumSymbol(schema, "A"), new
GenericData.EnumSymbol(schema, "B"));
- }
-
- @Test
- void fixed() throws Exception {
- String json = "{\"type\": \"fixed\", \"name\":\"Test\", \"size\": 1}";
- Schema schema = new Schema.Parser().parse(json);
- check(json, new GenericData.Fixed(schema, new byte[] { (byte) 'a' }),
- new GenericData.Fixed(schema, new byte[] { (byte) 'b' }));
- }
-
- @Test
- void union() throws Exception {
- check("[\"string\", \"long\"]", new Utf8("a"), new Utf8("b"), false);
- check("[\"string\", \"long\"]", 1L, 2L, false);
- check("[\"string\", \"long\"]", new Utf8("a"), 1L, false);
- }
-
@Test
void specificRecord() throws Exception {
TestRecord s1 = new TestRecord();
@@ -173,14 +55,6 @@ public class TestCompare {
check(schema, s1, s2, true, new SpecificDatumWriter<>(schema),
SpecificData.get());
}
- private static <T> void check(String schemaJson, T o1, T o2) throws
Exception {
- check(schemaJson, o1, o2, true);
- }
-
- private static <T> void check(String schemaJson, T o1, T o2, boolean
comparable) throws Exception {
- check(new Schema.Parser().parse(schemaJson), o1, o2, comparable, new
GenericDatumWriter<>(), GenericData.get());
- }
-
private static <T> void check(Schema schema, T o1, T o2, boolean comparable,
DatumWriter<T> writer,
GenericData comparator) throws Exception {