Skip to content

Commit 3cf5efb

Browse files
committed
convert to simple unit tests
1 parent 9200d51 commit 3cf5efb

File tree

1 file changed

+17
-97
lines changed

1 file changed

+17
-97
lines changed

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

Lines changed: 17 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,27 @@
1717

1818
package org.apache.fluss.client.utils;
1919

20-
import org.apache.fluss.client.admin.ClientToServerITCaseBase;
21-
import org.apache.fluss.client.table.Table;
22-
import org.apache.fluss.client.table.scanner.ScanRecord;
23-
import org.apache.fluss.client.table.scanner.log.LogScanner;
24-
import org.apache.fluss.client.table.scanner.log.ScanRecords;
25-
import org.apache.fluss.client.table.writer.AppendWriter;
26-
import org.apache.fluss.metadata.Schema;
27-
import org.apache.fluss.metadata.TableDescriptor;
28-
import org.apache.fluss.metadata.TablePath;
2920
import org.apache.fluss.row.GenericRow;
30-
import org.apache.fluss.row.InternalRow;
3121
import org.apache.fluss.types.DataTypes;
3222
import org.apache.fluss.types.RowType;
3323

3424
import org.junit.jupiter.api.Test;
3525

3626
import java.math.BigDecimal;
37-
import java.time.Duration;
3827
import java.time.Instant;
3928
import java.time.LocalDate;
4029
import java.time.LocalDateTime;
4130
import java.time.LocalTime;
4231
import java.time.OffsetDateTime;
4332
import java.time.ZoneOffset;
44-
import java.util.ArrayList;
4533
import java.util.Arrays;
46-
import java.util.List;
4734
import java.util.Objects;
4835

4936
import static org.assertj.core.api.Assertions.assertThat;
5037
import static org.assertj.core.api.Assertions.assertThatThrownBy;
5138

5239
/** Tests for {@link ConverterUtils}. */
53-
public class ConverterUtilsTest extends ClientToServerITCaseBase {
40+
public class ConverterUtilsTest {
5441

5542
private TestPojo createTestPojo() {
5643
return new TestPojo(
@@ -240,89 +227,12 @@ public void testFieldAccessFailureThrows() {
240227
}
241228

242229
@Test
243-
public void testWriteAndReadPojos() throws Exception {
244-
TablePath tablePath = new TablePath("test_db", "pojo_table");
245-
246-
// Create a schema for the table
247-
Schema schema =
248-
Schema.newBuilder()
249-
.column("booleanField", DataTypes.BOOLEAN())
250-
.column("byteField", DataTypes.TINYINT())
251-
.column("shortField", DataTypes.SMALLINT())
252-
.column("intField", DataTypes.INT())
253-
.column("longField", DataTypes.BIGINT())
254-
.column("floatField", DataTypes.FLOAT())
255-
.column("doubleField", DataTypes.DOUBLE())
256-
.column("stringField", DataTypes.STRING())
257-
.column("bytesField", DataTypes.BYTES())
258-
.column("decimalField", DataTypes.DECIMAL(10, 2))
259-
.column("dateField", DataTypes.DATE())
260-
.column("timeField", DataTypes.TIME())
261-
.column("timestampField", DataTypes.TIMESTAMP())
262-
.column("timestampLtzField", DataTypes.TIMESTAMP_LTZ())
263-
.column("offsetDateTimeField", DataTypes.TIMESTAMP_LTZ())
264-
.build();
265-
266-
// Create a table descriptor
267-
TableDescriptor tableDescriptor = TableDescriptor.builder().schema(schema).build();
268-
269-
// Create the table
270-
createTable(tablePath, tableDescriptor, false);
271-
272-
// Create a converter for TestPojo
273-
ConverterUtils<TestPojo> converter =
274-
ConverterUtils.getConverter(TestPojo.class, createTestPojoRowType());
275-
276-
List<TestPojo> originalPojos = new ArrayList<>();
277-
for (int i = 0; i < 5; i++) {
278-
originalPojos.add(createTestPojo());
279-
}
280-
281-
// Write the POJOs to the table
282-
try (Table table = conn.getTable(tablePath)) {
283-
AppendWriter appendWriter = table.newAppend().createWriter();
284-
for (TestPojo pojo : originalPojos) {
285-
GenericRow row = converter.toRow(pojo);
286-
appendWriter.append(row).get();
287-
}
288-
289-
// Create a log scanner
290-
LogScanner logScanner = createLogScanner(table);
291-
292-
// Subscribe to the log from the beginning
293-
subscribeFromBeginning(logScanner, table);
294-
295-
// Read the rows back
296-
List<TestPojo> readPojos = new ArrayList<>();
297-
while (readPojos.size() < originalPojos.size()) {
298-
ScanRecords scanRecords = logScanner.poll(Duration.ofSeconds(1));
299-
for (ScanRecord scanRecord : scanRecords) {
300-
InternalRow row = scanRecord.getRow();
301-
// Convert row back to POJO
302-
TestPojo pojo = converter.fromRow(row);
303-
readPojos.add(pojo);
304-
}
305-
}
306-
307-
assertThat(readPojos.size()).isEqualTo(originalPojos.size());
308-
309-
// Verify that the read POJOs match the original POJOs
310-
for (TestPojo originalPojo : originalPojos) {
311-
assertThat(originalPojo).isNotNull();
312-
// Find a matching POJO in the read list
313-
boolean found = false;
314-
for (TestPojo readPojo : readPojos) {
315-
if (originalPojo.equals(readPojo)) {
316-
found = true;
317-
break;
318-
}
319-
}
320-
assertThat(found)
321-
.withFailMessage(
322-
"Could not find matching POJO: " + originalPojo.stringField)
323-
.isTrue();
324-
}
325-
}
230+
public void testNoDefaultConstructorPojoThrows() {
231+
RowType rowType = RowType.builder().field("intField", DataTypes.INT()).build();
232+
assertThatThrownBy(
233+
() -> ConverterUtils.getConverter(NoDefaultConstructorPojo.class, rowType))
234+
.isInstanceOf(IllegalArgumentException.class)
235+
.hasMessageContaining("must have a default constructor");
326236
}
327237

328238
/** Test POJO class with various field types. */
@@ -490,4 +400,14 @@ public FinalFieldPojo() {
490400
this.intField = 0;
491401
}
492402
}
403+
404+
/** POJO without a default constructor (illegal for ConverterUtils). */
405+
public static class NoDefaultConstructorPojo {
406+
private int intField;
407+
408+
public NoDefaultConstructorPojo(int intField) {
409+
this.intField = intField;
410+
}
411+
}
412+
493413
}

0 commit comments

Comments
 (0)