Skip to content

Commit fe58468

Browse files
authored
SchemaTemplateSerDeTests: Replace ibm's Pair with our NonnullPair (#3248)
com.ibm.icu.impl.Pair does not have a toString implementation which does not make it conducive to parameterized test arguments. I did a search for other references to that Pair class, and did not find anything. This will help us understand what arguments are being provided for: #3247 that cause it to fail.
1 parent cfd095d commit fe58468

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

fdb-relational-core/src/test/java/com/apple/foundationdb/relational/recordlayer/metadata/SchemaTemplateSerDeTests.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
import com.apple.foundationdb.record.metadata.IndexTypes;
2525
import com.apple.foundationdb.record.metadata.Key;
2626
import com.apple.foundationdb.record.metadata.expressions.KeyExpression;
27-
import com.apple.foundationdb.relational.api.exceptions.UncheckedRelationalException;
27+
import com.apple.foundationdb.record.util.pair.NonnullPair;
2828
import com.apple.foundationdb.relational.api.exceptions.RelationalException;
29+
import com.apple.foundationdb.relational.api.exceptions.UncheckedRelationalException;
2930
import com.apple.foundationdb.relational.api.metadata.DataType;
30-
3131
import com.google.protobuf.DescriptorProtos;
32-
import com.ibm.icu.impl.Pair;
3332
import org.junit.jupiter.api.Assertions;
3433
import org.junit.jupiter.api.Test;
3534
import org.junit.jupiter.params.ParameterizedTest;
@@ -96,7 +95,7 @@ private static RecordLayerSchemaTemplate basicTestTemplate() {
9695
.build();
9796
}
9897

99-
private static RecordLayerSchemaTemplate getTestRecordLayerSchemaTemplate(@Nonnull Map<String, List<Pair<Integer, DescriptorProtos.FieldOptions>>> template) {
98+
private static RecordLayerSchemaTemplate getTestRecordLayerSchemaTemplate(@Nonnull Map<String, List<NonnullPair<Integer, DescriptorProtos.FieldOptions>>> template) {
10099
final var builder = RecordLayerSchemaTemplate.newBuilder().setName("TestSchemaTemplate");
101100
for (var entry : template.entrySet()) {
102101
final var tableBuilder = RecordLayerTable.newBuilder(false)
@@ -106,7 +105,7 @@ private static RecordLayerSchemaTemplate getTestRecordLayerSchemaTemplate(@Nonnu
106105
.setDataType(DataType.Primitives.STRING.type())
107106
.build());
108107
for (var generation : entry.getValue()) {
109-
tableBuilder.addGeneration(generation.first, generation.second);
108+
tableBuilder.addGeneration(generation.getLeft(), generation.getRight());
110109
}
111110
builder.addTable(tableBuilder.build());
112111
}
@@ -115,7 +114,7 @@ private static RecordLayerSchemaTemplate getTestRecordLayerSchemaTemplate(@Nonnu
115114

116115
@Test
117116
public void testGoodSchemaTemplate() {
118-
var testcase = new HashMap<String, List<Pair<Integer, DescriptorProtos.FieldOptions>>>();
117+
var testcase = new HashMap<String, List<NonnullPair<Integer, DescriptorProtos.FieldOptions>>>();
119118
testcase.put("T1", List.of());
120119
testcase.put("T2", List.of());
121120

@@ -183,9 +182,9 @@ public void testStoreRowVersions(boolean storeRowVersions) {
183182
public void testGoodSchemaTemplateWithGenerations() {
184183
final var fieldOptions1 = DescriptorProtos.FieldOptions.newBuilder().setDeprecated(true).build();
185184
final var fieldOptions2 = DescriptorProtos.FieldOptions.newBuilder().setDeprecated(false).build();
186-
var testcase = new HashMap<String, List<Pair<Integer, DescriptorProtos.FieldOptions>>>();
187-
testcase.put("T1", List.of(Pair.of(1, fieldOptions1), Pair.of(2, fieldOptions2)));
188-
testcase.put("T2", List.of(Pair.of(3, fieldOptions2), Pair.of(4, fieldOptions1)));
185+
var testcase = new HashMap<String, List<NonnullPair<Integer, DescriptorProtos.FieldOptions>>>();
186+
testcase.put("T1", List.of(NonnullPair.of(1, fieldOptions1), NonnullPair.of(2, fieldOptions2)));
187+
testcase.put("T2", List.of(NonnullPair.of(3, fieldOptions2), NonnullPair.of(4, fieldOptions1)));
189188

190189
var template = getTestRecordLayerSchemaTemplate(testcase);
191190
var recordMetadataProto = template.toRecordMetadata().toProto();
@@ -205,7 +204,7 @@ public void testGoodSchemaTemplateWithGenerations() {
205204
final var typeName = unionField.getTypeName();
206205
Assertions.assertTrue(testcase.containsKey(typeName));
207206
final var expectedGenerations = testcase.get(typeName);
208-
Assertions.assertTrue(expectedGenerations.contains(Pair.of(unionField.getNumber(), unionField.getOptions())));
207+
Assertions.assertTrue(expectedGenerations.contains(NonnullPair.of(unionField.getNumber(), unionField.getOptions())));
209208
}
210209
}
211210

@@ -232,18 +231,18 @@ public static Stream<Arguments> badSchemaTemplateGenerationsTestcaseProvider() {
232231
final var fieldOptions2 = DescriptorProtos.FieldOptions.newBuilder().setDeprecated(false).build();
233232

234233
// SchemaTemplate with field number 0
235-
var testcase1 = new TreeMap<String, List<Pair<Integer, DescriptorProtos.FieldOptions>>>();
236-
testcase1.put("T1", List.of(Pair.of(0, fieldOptions1), Pair.of(2, fieldOptions2)));
234+
var testcase1 = new TreeMap<String, List<NonnullPair<Integer, DescriptorProtos.FieldOptions>>>();
235+
testcase1.put("T1", List.of(NonnullPair.of(0, fieldOptions1), NonnullPair.of(2, fieldOptions2)));
237236
// SchemaTemplate with duplicated field number
238-
var testcase2 = new TreeMap<String, List<Pair<Integer, DescriptorProtos.FieldOptions>>>();
239-
testcase2.put("T1", List.of(Pair.of(1, fieldOptions1), Pair.of(1, fieldOptions2)));
237+
var testcase2 = new TreeMap<String, List<NonnullPair<Integer, DescriptorProtos.FieldOptions>>>();
238+
testcase2.put("T1", List.of(NonnullPair.of(1, fieldOptions1), NonnullPair.of(1, fieldOptions2)));
240239
// SchemaTemplate with duplicated fieldOptions
241-
var testcase3 = new TreeMap<String, List<Pair<Integer, DescriptorProtos.FieldOptions>>>();
242-
testcase3.put("T1", List.of(Pair.of(1, fieldOptions2), Pair.of(2, fieldOptions2)));
240+
var testcase3 = new TreeMap<String, List<NonnullPair<Integer, DescriptorProtos.FieldOptions>>>();
241+
testcase3.put("T1", List.of(NonnullPair.of(1, fieldOptions2), NonnullPair.of(2, fieldOptions2)));
243242
// SchemaTemplate with duplicated field numbers across tables
244-
var testcase4 = new TreeMap<String, List<Pair<Integer, DescriptorProtos.FieldOptions>>>();
245-
testcase4.put("T1", List.of(Pair.of(1, fieldOptions2), Pair.of(2, fieldOptions1)));
246-
testcase4.put("T2", List.of(Pair.of(2, fieldOptions2), Pair.of(3, fieldOptions1)));
243+
var testcase4 = new TreeMap<String, List<NonnullPair<Integer, DescriptorProtos.FieldOptions>>>();
244+
testcase4.put("T1", List.of(NonnullPair.of(1, fieldOptions2), NonnullPair.of(2, fieldOptions1)));
245+
testcase4.put("T2", List.of(NonnullPair.of(2, fieldOptions2), NonnullPair.of(3, fieldOptions1)));
247246

248247
return Stream.of(
249248
Arguments.of(testcase1, UncheckedRelationalException.class, "Field numbers must be positive integers"),
@@ -255,7 +254,7 @@ public static Stream<Arguments> badSchemaTemplateGenerationsTestcaseProvider() {
255254

256255
@ParameterizedTest
257256
@MethodSource("badSchemaTemplateGenerationsTestcaseProvider")
258-
public void testBadSchemaTemplateGenerations(Map<String, List<Pair<Integer, DescriptorProtos.FieldOptions>>> testcase,
257+
public void testBadSchemaTemplateGenerations(Map<String, List<NonnullPair<Integer, DescriptorProtos.FieldOptions>>> testcase,
259258
Class<? extends Exception> exceptionClass, String message) {
260259
final var thrown = Assertions.assertThrows(exceptionClass, () -> {
261260
final var schemaTemplate = getTestRecordLayerSchemaTemplate(testcase);
@@ -265,7 +264,7 @@ public void testBadSchemaTemplateGenerations(Map<String, List<Pair<Integer, Desc
265264
}
266265

267266
@Test
268-
public void deserializationNestedTypesPreservesNamesCorrectly() throws Exception {
267+
public void deserializationNestedTypesPreservesNamesCorrectly() {
269268
final var sampleRecordSchemaTemplate = RecordLayerSchemaTemplate.newBuilder()
270269
.setName("TestSchemaTemplate")
271270
.setVersion(42)
@@ -292,7 +291,7 @@ public void deserializationNestedTypesPreservesNamesCorrectly() throws Exception
292291
final var column = deserializedTableType.get().getColumns().stream().findFirst();
293292
Assertions.assertTrue(column.isPresent());
294293
final var type = column.get().getDatatype();
295-
Assertions.assertTrue(type instanceof DataType.StructType);
294+
Assertions.assertInstanceOf(DataType.StructType.class, type);
296295
final var typeName = ((DataType.StructType) type).getName();
297296
Assertions.assertEquals("Subtype", typeName);
298297
}

0 commit comments

Comments
 (0)