use of org.apache.flink.table.connector.sink.DynamicTableSink in project flink by apache.
the class KafkaDynamicTableFactoryTest method testTableSinkWithKeyValue.
@Test
public void testTableSinkWithKeyValue() {
final Map<String, String> modifiedOptions = getModifiedOptions(getKeyValueOptions(), options -> {
options.put("sink.delivery-guarantee", "exactly-once");
options.put("sink.transactional-id-prefix", "kafka-sink");
});
final DynamicTableSink actualSink = createTableSink(SCHEMA, modifiedOptions);
final KafkaDynamicSink actualKafkaSink = (KafkaDynamicSink) actualSink;
// initialize stateful testing formats
actualKafkaSink.getSinkRuntimeProvider(new SinkRuntimeProviderContext(false));
final EncodingFormatMock keyEncodingFormat = new EncodingFormatMock("#");
keyEncodingFormat.consumedDataType = DataTypes.ROW(DataTypes.FIELD(NAME, DataTypes.STRING().notNull())).notNull();
final EncodingFormatMock valueEncodingFormat = new EncodingFormatMock("|");
valueEncodingFormat.consumedDataType = DataTypes.ROW(DataTypes.FIELD(COUNT, DataTypes.DECIMAL(38, 18)), DataTypes.FIELD(TIME, DataTypes.TIMESTAMP(3))).notNull();
final DynamicTableSink expectedSink = createExpectedSink(SCHEMA_DATA_TYPE, keyEncodingFormat, valueEncodingFormat, new int[] { 0 }, new int[] { 1, 2 }, null, TOPIC, KAFKA_FINAL_SINK_PROPERTIES, new FlinkFixedPartitioner<>(), DeliveryGuarantee.EXACTLY_ONCE, null, "kafka-sink");
assertThat(actualSink).isEqualTo(expectedSink);
}
use of org.apache.flink.table.connector.sink.DynamicTableSink in project flink by apache.
the class KafkaDynamicTableFactoryTest method testTableSinkSemanticTranslation.
@Test
public void testTableSinkSemanticTranslation() {
final List<String> semantics = ImmutableList.of("exactly-once", "at-least-once", "none");
final EncodingFormat<SerializationSchema<RowData>> valueEncodingFormat = new EncodingFormatMock(",");
for (final String semantic : semantics) {
final Map<String, String> modifiedOptions = getModifiedOptions(getBasicSinkOptions(), options -> {
options.put("sink.semantic", semantic);
options.put("sink.transactional-id-prefix", "kafka-sink");
});
final DynamicTableSink actualSink = createTableSink(SCHEMA, modifiedOptions);
final DynamicTableSink expectedSink = createExpectedSink(SCHEMA_DATA_TYPE, null, valueEncodingFormat, new int[0], new int[] { 0, 1, 2 }, null, TOPIC, KAFKA_SINK_PROPERTIES, new FlinkFixedPartitioner<>(), DeliveryGuarantee.valueOf(semantic.toUpperCase().replace("-", "_")), null, "kafka-sink");
assertThat(actualSink).isEqualTo(expectedSink);
}
}
use of org.apache.flink.table.connector.sink.DynamicTableSink in project flink by apache.
the class JsonFormatFactoryTest method createTableSink.
private TestDynamicTableFactory.DynamicTableSinkMock createTableSink(Map<String, String> options) {
final DynamicTableSink actualSink = FactoryMocks.createTableSink(SCHEMA, options);
assertThat(actualSink).isInstanceOf(TestDynamicTableFactory.DynamicTableSinkMock.class);
return (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
}
use of org.apache.flink.table.connector.sink.DynamicTableSink in project flink by apache.
the class FactoryUtilTest method testAllOptions.
@Test
public void testAllOptions() {
final Map<String, String> options = createAllOptions();
final DynamicTableSource actualSource = createTableSource(SCHEMA, options);
final DynamicTableSource expectedSource = new DynamicTableSourceMock("MyTarget", null, new DecodingFormatMock(",", false), new DecodingFormatMock("|", true));
assertThat(actualSource).isEqualTo(expectedSource);
final DynamicTableSink actualSink = createTableSink(SCHEMA, options);
final DynamicTableSink expectedSink = new DynamicTableSinkMock("MyTarget", 1000L, new EncodingFormatMock(","), new EncodingFormatMock("|"));
assertThat(actualSink).isEqualTo(expectedSink);
}
use of org.apache.flink.table.connector.sink.DynamicTableSink in project flink by apache.
the class RawFormatFactoryTest method createSerializationSchema.
private static SerializationSchema<RowData> createSerializationSchema(ResolvedSchema schema, Map<String, String> options) {
final DynamicTableSink actualSink = createTableSink(schema, options);
assertThat(actualSink, instanceOf(TestDynamicTableFactory.DynamicTableSinkMock.class));
TestDynamicTableFactory.DynamicTableSinkMock sinkMock = (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
return sinkMock.valueFormat.createRuntimeEncoder(new SinkRuntimeProviderContext(false), schema.toPhysicalRowDataType());
}
Aggregations