Skip to content

Commit 1bc561a

Browse files
authored
Fix SpecificRecordClassGenerator methods overloaded for int/long (#587)
1 parent 5a2c36b commit 1bc561a

File tree

13 files changed

+215
-67
lines changed

13 files changed

+215
-67
lines changed

avro-builder/tests/codegen-110/src/main/avro/vs110/IntsAndLongs.avsc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
"name": "boxedIntField",
2121
"type": ["null", "int"],
2222
"default": null
23+
},
24+
{
25+
"name": "strField",
26+
"type": "string",
27+
"default": "defaultStr"
2328
}
2429
]
2530
}

avro-builder/tests/codegen-111/src/main/avro/vs111/IntsAndLongs.avsc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
"name": "boxedIntField",
2121
"type": ["null", "int"],
2222
"default": null
23+
},
24+
{
25+
"name": "strField",
26+
"type": "string",
27+
"default": "defaultStr"
2328
}
2429
]
2530
}

avro-builder/tests/codegen-14/src/main/avro/vs14/IntsAndLongs.avsc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
"name": "boxedIntField",
2121
"type": ["null", "int"],
2222
"default": null
23+
},
24+
{
25+
"name": "strField",
26+
"type": "string",
27+
"default": "defaultStr"
2328
}
2429
]
2530
}

avro-builder/tests/codegen-15/src/main/avro/vs15/IntsAndLongs.avsc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
"name": "boxedIntField",
2121
"type": ["null", "int"],
2222
"default": null
23+
},
24+
{
25+
"name": "strField",
26+
"type": "string",
27+
"default": "defaultStr"
2328
}
2429
]
2530
}

avro-builder/tests/codegen-16/src/main/avro/vs16/IntsAndLongs.avsc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
"name": "boxedIntField",
2121
"type": ["null", "int"],
2222
"default": null
23+
},
24+
{
25+
"name": "strField",
26+
"type": "string",
27+
"default": "defaultStr"
2328
}
2429
]
2530
}

avro-builder/tests/codegen-17/src/main/avro/vs17/IntsAndLongs.avsc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
"name": "boxedIntField",
2121
"type": ["null", "int"],
2222
"default": null
23+
},
24+
{
25+
"name": "strField",
26+
"type": "string",
27+
"default": "defaultStr"
2328
}
2429
]
2530
}

avro-builder/tests/codegen-18/src/main/avro/vs18/IntsAndLongs.avsc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
"name": "boxedIntField",
2121
"type": ["null", "int"],
2222
"default": null
23+
},
24+
{
25+
"name": "strField",
26+
"type": "string",
27+
"default": "defaultStr"
2328
}
2429
]
2530
}

avro-builder/tests/codegen-19/src/main/avro/vs19/IntsAndLongs.avsc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
"name": "boxedIntField",
2121
"type": ["null", "int"],
2222
"default": null
23+
},
24+
{
25+
"name": "strField",
26+
"type": "string",
27+
"default": "defaultStr"
2328
}
2429
]
2530
}

avro-builder/tests/codegen-no-utf8-encoding/src/main/avro/noUtf8Encoding/TestCollections.avsc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
"values": "int"
9090
}
9191
]
92+
},
93+
{
94+
"name": "intField",
95+
"type": "int"
9296
}
9397
],
9498
"type": "record"

avro-builder/tests/tests-allavro/src/test/java/com/linkedin/avroutil1/builder/SpecificRecordTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,35 +1999,41 @@ public void testIntLongRecords(Class<?> clazz) throws Exception {
19991999
Method setIntFieldLongMethod = builder.getClass().getMethod("setIntField", long.class);
20002000
Method setLongFieldMethod = builder.getClass().getMethod("setLongField", long.class);
20012001
Method setLongFieldIntMethod = builder.getClass().getMethod("setLongField", int.class);
2002+
Method setStrFieldIntMethod = builder.getClass().getMethod("setStrField", String.class);
20022003
Method buildMethod = builder.getClass().getMethod("build");
20032004

20042005
// Case 1: Set int and long with matching int/long types (primitive)
20052006
Object builder1 = newBuilderMethod.invoke(null);
20062007
setIntFieldMethod.invoke(builder1, 123);
20072008
setLongFieldMethod.invoke(builder1, 456L);
2009+
setStrFieldIntMethod.invoke(builder1, "testStr");
20082010
Object record1 = buildMethod.invoke(builder1);
20092011

20102012
// Case 2: Set int field with long type, and long field with int type (primitive)
20112013
Object builder2 = newBuilderMethod.invoke(null);
20122014
setIntFieldLongMethod.invoke(builder2, 123L);
20132015
setLongFieldIntMethod.invoke(builder2, 456);
2016+
setStrFieldIntMethod.invoke(builder2, "testStr");
20142017
Object record2 = buildMethod.invoke(builder2);
20152018

20162019
// Case 3: Using the put method with primitive types
20172020
Object record3 = clazz.newInstance();
20182021
Method putMethod = clazz.getMethod("put", int.class, Object.class);
20192022
putMethod.invoke(record3, 0, 456L); // longField with long
20202023
putMethod.invoke(record3, 1, 123); // intField with int
2024+
putMethod.invoke(record3, 4, "testStr");
20212025

20222026
// Case 4: Using the put method with cross types
20232027
Object record4 = clazz.newInstance();
20242028
putMethod.invoke(record4, 0, 456); // longField with int
20252029
putMethod.invoke(record4, 1, 123L); // intField with long
2030+
putMethod.invoke(record4, 4, "testStr");
20262031

20272032
// Case 5: Using the put method with Integer/Long wrapper classes
20282033
Object record5 = clazz.newInstance();
20292034
putMethod.invoke(record5, 0, Integer.valueOf(456)); // longField with Integer
20302035
putMethod.invoke(record5, 1, Long.valueOf(123L)); // intField with Long
2036+
putMethod.invoke(record5, 4, "testStr");
20312037

20322038
// Verify all records are equal
20332039
Assert.assertEquals(record1, record2);
@@ -2038,11 +2044,13 @@ public void testIntLongRecords(Class<?> clazz) throws Exception {
20382044
// Verify field values directly
20392045
Method getIntFieldMethod = clazz.getMethod("getIntField");
20402046
Method getLongFieldMethod = clazz.getMethod("getLongField");
2047+
Method getStrFieldMethod = clazz.getMethod("getStrField");
20412048

20422049
Assert.assertEquals(123, getIntFieldMethod.invoke(record1));
20432050
Assert.assertEquals(456L, getLongFieldMethod.invoke(record1));
20442051
Assert.assertEquals(123, getIntFieldMethod.invoke(record5));
20452052
Assert.assertEquals(456L, getLongFieldMethod.invoke(record5));
2053+
Assert.assertEquals("testStr", getStrFieldMethod.invoke(record1));
20462054
}
20472055

20482056
@Test(dataProvider = "intsAndLongsDataProvider")

0 commit comments

Comments
 (0)