use of org.apache.flink.connector.datagen.table.DataGenTableSource in project flink by apache.
the class DataGenTableSourceFactoryTest method testSequenceCheckpointRestore.
@Test
public void testSequenceCheckpointRestore() throws Exception {
DescriptorProperties descriptor = new DescriptorProperties();
descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
descriptor.putString(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.KIND, DataGenConnectorOptionsUtil.SEQUENCE);
descriptor.putLong(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.START, 0);
descriptor.putLong(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.END, 100);
DynamicTableSource dynamicTableSource = createTableSource(ResolvedSchema.of(Column.physical("f0", DataTypes.BIGINT())), descriptor.asMap());
DataGenTableSource dataGenTableSource = (DataGenTableSource) dynamicTableSource;
DataGeneratorSource<RowData> source = dataGenTableSource.createSource();
final int initElement = 0;
final int maxElement = 100;
final Set<RowData> expectedOutput = new HashSet<>();
for (long i = initElement; i <= maxElement; i++) {
expectedOutput.add(GenericRowData.of(i));
}
DataGeneratorSourceTest.innerTestDataGenCheckpointRestore(() -> {
try {
return InstantiationUtil.clone(source);
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}, expectedOutput);
}
use of org.apache.flink.connector.datagen.table.DataGenTableSource in project flink by apache.
the class DataGenTableSourceFactoryTest method runGenerator.
private List<RowData> runGenerator(ResolvedSchema schema, DescriptorProperties descriptor) throws Exception {
DynamicTableSource source = createTableSource(schema, descriptor.asMap());
assertTrue(source instanceof DataGenTableSource);
DataGenTableSource dataGenTableSource = (DataGenTableSource) source;
DataGeneratorSource<RowData> gen = dataGenTableSource.createSource();
// test java serialization.
gen = InstantiationUtil.clone(gen);
StreamSource<RowData, DataGeneratorSource<RowData>> src = new StreamSource<>(gen);
AbstractStreamOperatorTestHarness<RowData> testHarness = new AbstractStreamOperatorTestHarness<>(src, 1, 1, 0);
testHarness.open();
TestContext ctx = new TestContext();
gen.run(ctx);
return ctx.results;
}
Aggregations