Skip to content

Commit bbf2ca2

Browse files
committed
fix broken tests
1 parent fa7c047 commit bbf2ca2

File tree

2 files changed

+31
-52
lines changed

2 files changed

+31
-52
lines changed

fluss-client/src/main/java/org/apache/fluss/client/utils/PojoConverterUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private FieldToRowConverter[] createFieldToRowConverters() {
197197

198198
// Check if the field type is supported
199199
if (!SUPPORTED_TYPES.containsKey(fieldType.getTypeRoot())) {
200-
throw new IllegalArgumentException(
200+
throw new UnsupportedOperationException(
201201
"Unsupported field type "
202202
+ fieldType.getTypeRoot()
203203
+ " for field "
@@ -400,7 +400,7 @@ private FieldToRowConverter createFieldToRowConverter(DataType fieldType, Field
400400
}
401401
});
402402
default:
403-
throw new IllegalArgumentException(
403+
throw new UnsupportedOperationException(
404404
String.format(
405405
"Unsupported type %s for field %s.",
406406
fieldType.getTypeRoot(), field.getName()));
@@ -521,13 +521,13 @@ private RowToFieldConverter createRowToFieldConverter(DataType fieldType, Field
521521
} else {
522522
throw new IllegalArgumentException(
523523
String.format(
524-
"Field %s is not an Instant or OffsetDateTime. Cannot convert from TimestampLtz.",
524+
"Field %s is not an Instant or OffsetDateTime. Cannot convert from TimestampData.",
525525
field.getName()));
526526
}
527527
});
528528
}
529529
default:
530-
throw new IllegalArgumentException(
530+
throw new UnsupportedOperationException(
531531
String.format(
532532
"Unsupported type %s for field %s.",
533533
fieldType.getTypeRoot(), field.getName()));

fluss-client/src/test/java/org/apache/fluss/client/utils/PojoConverterUtilsTest.java

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -212,22 +212,6 @@ public void testRowWithMissingFields() {
212212
assertThat(convertedPojo.offsetDateTimeField).isNull();
213213
}
214214

215-
@Test
216-
public void testFieldAccessFailureThrows() {
217-
RowType rowType = RowType.builder().field("intField", DataTypes.INT()).build();
218-
219-
PojoConverterUtils<FinalFieldPojo> converter =
220-
PojoConverterUtils.getConverter(FinalFieldPojo.class, rowType);
221-
222-
GenericRow row = new GenericRow(1);
223-
row.setField(0, 42);
224-
225-
assertThatThrownBy(() -> converter.fromRow(row))
226-
.isInstanceOf(IllegalStateException.class)
227-
.hasMessageContaining("Failed to set field")
228-
.hasMessageContaining("intField");
229-
}
230-
231215
@Test
232216
public void testNoDefaultConstructorPojoThrows() {
233217
RowType rowType = RowType.builder().field("intField", DataTypes.INT()).build();
@@ -257,61 +241,53 @@ public void testFromRowThrowsWhenDefaultConstructorThrows() {
257241
@Test
258242
public void testToRowThrowsForNonBigDecimal() {
259243
RowType rowType = RowType.builder().field("decimalField", DataTypes.DECIMAL(10, 2)).build();
260-
PojoConverterUtils<DecimalWrongTypePojo> converter =
261-
PojoConverterUtils.getConverter(DecimalWrongTypePojo.class, rowType);
262-
DecimalWrongTypePojo pojo = new DecimalWrongTypePojo("not-a-decimal");
263-
assertThatThrownBy(() -> converter.toRow(pojo))
244+
assertThatThrownBy(
245+
() -> PojoConverterUtils.getConverter(DecimalWrongTypePojo.class, rowType))
264246
.isInstanceOf(IllegalArgumentException.class)
265-
.hasMessageContaining("not a BigDecimal")
247+
.hasMessageContaining("incompatible with Fluss type")
266248
.hasMessageContaining("decimalField");
267249
}
268250

269251
@Test
270252
public void testToRowThrowsForNonLocalDate() {
271253
RowType rowType = RowType.builder().field("dateField", DataTypes.DATE()).build();
272-
PojoConverterUtils<DateWrongTypePojo> converter =
273-
PojoConverterUtils.getConverter(DateWrongTypePojo.class, rowType);
274-
DateWrongTypePojo pojo = new DateWrongTypePojo("2025-01-01");
275-
assertThatThrownBy(() -> converter.toRow(pojo))
254+
assertThatThrownBy(() -> PojoConverterUtils.getConverter(DateWrongTypePojo.class, rowType))
276255
.isInstanceOf(IllegalArgumentException.class)
277-
.hasMessageContaining("not a LocalDate")
256+
.hasMessageContaining("incompatible with Fluss type")
278257
.hasMessageContaining("dateField");
279258
}
280259

281260
@Test
282261
public void testToRowThrowsForNonLocalTime() {
283262
RowType rowType = RowType.builder().field("timeField", DataTypes.TIME()).build();
284-
PojoConverterUtils<TimeWrongTypePojo> converter =
285-
PojoConverterUtils.getConverter(TimeWrongTypePojo.class, rowType);
286-
TimeWrongTypePojo pojo = new TimeWrongTypePojo("15:00:00");
287-
assertThatThrownBy(() -> converter.toRow(pojo))
263+
assertThatThrownBy(() -> PojoConverterUtils.getConverter(TimeWrongTypePojo.class, rowType))
288264
.isInstanceOf(IllegalArgumentException.class)
289-
.hasMessageContaining("not a LocalTime")
265+
.hasMessageContaining("incompatible with Fluss type")
290266
.hasMessageContaining("timeField");
291267
}
292268

293269
@Test
294270
public void testToRowThrowsForNonLocalDateTime() {
295271
RowType rowType = RowType.builder().field("timestampField", DataTypes.TIMESTAMP()).build();
296-
PojoConverterUtils<TimestampWrongTypePojo> converter =
297-
PojoConverterUtils.getConverter(TimestampWrongTypePojo.class, rowType);
298-
TimestampWrongTypePojo pojo = new TimestampWrongTypePojo("2025-01-01T12:00:00");
299-
assertThatThrownBy(() -> converter.toRow(pojo))
272+
assertThatThrownBy(
273+
() ->
274+
PojoConverterUtils.getConverter(
275+
TimestampWrongTypePojo.class, rowType))
300276
.isInstanceOf(IllegalArgumentException.class)
301-
.hasMessageContaining("not a LocalDateTime")
277+
.hasMessageContaining("incompatible with Fluss type")
302278
.hasMessageContaining("timestampField");
303279
}
304280

305281
@Test
306282
public void testToRowThrowsForNonInstantOrOffsetDateTime() {
307283
RowType rowType =
308284
RowType.builder().field("timestampLtzField", DataTypes.TIMESTAMP_LTZ()).build();
309-
PojoConverterUtils<TimestampLtzWrongTypePojo> converter =
310-
PojoConverterUtils.getConverter(TimestampLtzWrongTypePojo.class, rowType);
311-
TimestampLtzWrongTypePojo pojo = new TimestampLtzWrongTypePojo("2025-01-01T12:00:00Z");
312-
assertThatThrownBy(() -> converter.toRow(pojo))
285+
assertThatThrownBy(
286+
() ->
287+
PojoConverterUtils.getConverter(
288+
TimestampLtzWrongTypePojo.class, rowType))
313289
.isInstanceOf(IllegalArgumentException.class)
314-
.hasMessageContaining("not an Instant or OffsetDateTime")
290+
.hasMessageContaining("incompatible with Fluss type")
315291
.hasMessageContaining("timestampLtzField");
316292
}
317293

@@ -320,20 +296,21 @@ public void testFromRowThrowsForTimestampLtzUnsupportedTargetType() {
320296
RowType rowType =
321297
RowType.builder().field("timestampLtzField", DataTypes.TIMESTAMP_LTZ()).build();
322298

323-
// Create a valid row using a POJO with Instant
299+
// Create a valid row using a POJO with Instant (ensure default constructor exists)
324300
ValidTimestampLtzInstantPojo valid =
325301
new ValidTimestampLtzInstantPojo(Instant.parse("2025-07-23T15:01:30Z"));
326302
PojoConverterUtils<ValidTimestampLtzInstantPojo> validConverter =
327303
PojoConverterUtils.getConverter(ValidTimestampLtzInstantPojo.class, rowType);
328304
GenericRow row = validConverter.toRow(valid);
305+
assertThat(row).isNotNull();
329306

330-
// Try to read with a POJO that uses unsupported LocalDateTime for TIMESTAMP_LTZ
331-
PojoConverterUtils<TimestampLtzLocalDateTimePojo> invalidConverter =
332-
PojoConverterUtils.getConverter(TimestampLtzLocalDateTimePojo.class, rowType);
333-
334-
assertThatThrownBy(() -> invalidConverter.fromRow(row))
307+
// Creating a converter for a POJO that uses unsupported LocalDateTime should fail fast
308+
assertThatThrownBy(
309+
() ->
310+
PojoConverterUtils.getConverter(
311+
TimestampLtzLocalDateTimePojo.class, rowType))
335312
.isInstanceOf(IllegalArgumentException.class)
336-
.hasMessageContaining("Cannot convert from TimestampData")
313+
.hasMessageContaining("incompatible with Fluss type")
337314
.hasMessageContaining("timestampLtzField");
338315
}
339316

@@ -446,6 +423,8 @@ public TimestampLtzWrongTypePojo(String timestampLtzField) {
446423
public static class ValidTimestampLtzInstantPojo {
447424
private Instant timestampLtzField;
448425

426+
public ValidTimestampLtzInstantPojo() {}
427+
449428
public ValidTimestampLtzInstantPojo(Instant timestampLtzField) {
450429
this.timestampLtzField = timestampLtzField;
451430
}

0 commit comments

Comments
 (0)