Search in sources :

Example 1 with DecodingFormatMock

use of org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock in project flink by apache.

the class KafkaDynamicTableFactoryTest method testTableSource.

@Test
public void testTableSource() {
    final DynamicTableSource actualSource = createTableSource(SCHEMA, getBasicSourceOptions());
    final KafkaDynamicSource actualKafkaSource = (KafkaDynamicSource) actualSource;
    final Map<KafkaTopicPartition, Long> specificOffsets = new HashMap<>();
    specificOffsets.put(new KafkaTopicPartition(TOPIC, PARTITION_0), OFFSET_0);
    specificOffsets.put(new KafkaTopicPartition(TOPIC, PARTITION_1), OFFSET_1);
    final DecodingFormat<DeserializationSchema<RowData>> valueDecodingFormat = new DecodingFormatMock(",", true);
    // Test scan source equals
    final KafkaDynamicSource expectedKafkaSource = createExpectedScanSource(SCHEMA_DATA_TYPE, null, valueDecodingFormat, new int[0], new int[] { 0, 1, 2 }, null, Collections.singletonList(TOPIC), null, KAFKA_SOURCE_PROPERTIES, StartupMode.SPECIFIC_OFFSETS, specificOffsets, 0);
    assertThat(actualKafkaSource).isEqualTo(expectedKafkaSource);
    ScanTableSource.ScanRuntimeProvider provider = actualKafkaSource.getScanRuntimeProvider(ScanRuntimeProviderContext.INSTANCE);
    assertKafkaSource(provider);
}
Also used : ScanTableSource(org.apache.flink.table.connector.source.ScanTableSource) HashMap(java.util.HashMap) KafkaTopicPartition(org.apache.flink.streaming.connectors.kafka.internals.KafkaTopicPartition) DecodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock) DeserializationSchema(org.apache.flink.api.common.serialization.DeserializationSchema) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with DecodingFormatMock

use of org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock in project flink by apache.

the class KafkaDynamicTableFactoryTest method testTableSourceWithPattern.

@Test
public void testTableSourceWithPattern() {
    final Map<String, String> modifiedOptions = getModifiedOptions(getBasicSourceOptions(), options -> {
        options.remove("topic");
        options.put("topic-pattern", TOPIC_REGEX);
        options.put("scan.startup.mode", ScanStartupMode.EARLIEST_OFFSET.toString());
        options.remove("scan.startup.specific-offsets");
    });
    final DynamicTableSource actualSource = createTableSource(SCHEMA, modifiedOptions);
    final Map<KafkaTopicPartition, Long> specificOffsets = new HashMap<>();
    DecodingFormat<DeserializationSchema<RowData>> valueDecodingFormat = new DecodingFormatMock(",", true);
    // Test scan source equals
    final KafkaDynamicSource expectedKafkaSource = createExpectedScanSource(SCHEMA_DATA_TYPE, null, valueDecodingFormat, new int[0], new int[] { 0, 1, 2 }, null, null, Pattern.compile(TOPIC_REGEX), KAFKA_SOURCE_PROPERTIES, StartupMode.EARLIEST, specificOffsets, 0);
    final KafkaDynamicSource actualKafkaSource = (KafkaDynamicSource) actualSource;
    assertThat(actualKafkaSource).isEqualTo(expectedKafkaSource);
    ScanTableSource.ScanRuntimeProvider provider = actualKafkaSource.getScanRuntimeProvider(ScanRuntimeProviderContext.INSTANCE);
    assertKafkaSource(provider);
}
Also used : HashMap(java.util.HashMap) KafkaTopicPartition(org.apache.flink.streaming.connectors.kafka.internals.KafkaTopicPartition) DecodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock) DeserializationSchema(org.apache.flink.api.common.serialization.DeserializationSchema) ScanTableSource(org.apache.flink.table.connector.source.ScanTableSource) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with DecodingFormatMock

use of org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock in project flink by apache.

the class KafkaDynamicTableFactoryTest method testTableSourceWithKeyValueAndMetadata.

@Test
public void testTableSourceWithKeyValueAndMetadata() {
    final Map<String, String> options = getKeyValueOptions();
    options.put("value.test-format.readable-metadata", "metadata_1:INT, metadata_2:STRING");
    final DynamicTableSource actualSource = createTableSource(SCHEMA_WITH_METADATA, options);
    final KafkaDynamicSource actualKafkaSource = (KafkaDynamicSource) actualSource;
    // initialize stateful testing formats
    actualKafkaSource.applyReadableMetadata(Arrays.asList("timestamp", "value.metadata_2"), SCHEMA_WITH_METADATA.toSourceRowDataType());
    actualKafkaSource.getScanRuntimeProvider(ScanRuntimeProviderContext.INSTANCE);
    final DecodingFormatMock expectedKeyFormat = new DecodingFormatMock("#", false, ChangelogMode.insertOnly(), Collections.emptyMap());
    expectedKeyFormat.producedDataType = DataTypes.ROW(DataTypes.FIELD(NAME, DataTypes.STRING())).notNull();
    final Map<String, DataType> expectedReadableMetadata = new HashMap<>();
    expectedReadableMetadata.put("metadata_1", DataTypes.INT());
    expectedReadableMetadata.put("metadata_2", DataTypes.STRING());
    final DecodingFormatMock expectedValueFormat = new DecodingFormatMock("|", false, ChangelogMode.insertOnly(), expectedReadableMetadata);
    expectedValueFormat.producedDataType = DataTypes.ROW(DataTypes.FIELD(COUNT, DataTypes.DECIMAL(38, 18)), DataTypes.FIELD("metadata_2", DataTypes.STRING())).notNull();
    expectedValueFormat.metadataKeys = Collections.singletonList("metadata_2");
    final KafkaDynamicSource expectedKafkaSource = createExpectedScanSource(SCHEMA_WITH_METADATA.toPhysicalRowDataType(), expectedKeyFormat, expectedValueFormat, new int[] { 0 }, new int[] { 1 }, null, Collections.singletonList(TOPIC), null, KAFKA_FINAL_SOURCE_PROPERTIES, StartupMode.GROUP_OFFSETS, Collections.emptyMap(), 0);
    expectedKafkaSource.producedDataType = SCHEMA_WITH_METADATA.toSourceRowDataType();
    expectedKafkaSource.metadataKeys = Collections.singletonList("timestamp");
    assertThat(actualSource).isEqualTo(expectedKafkaSource);
}
Also used : HashMap(java.util.HashMap) DecodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock) DataType(org.apache.flink.table.types.DataType) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with DecodingFormatMock

use of org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock in project flink by apache.

the class KafkaDynamicTableFactoryTest method testTableSourceWithKeyValue.

@Test
public void testTableSourceWithKeyValue() {
    final DynamicTableSource actualSource = createTableSource(SCHEMA, getKeyValueOptions());
    final KafkaDynamicSource actualKafkaSource = (KafkaDynamicSource) actualSource;
    // initialize stateful testing formats
    actualKafkaSource.getScanRuntimeProvider(ScanRuntimeProviderContext.INSTANCE);
    final DecodingFormatMock keyDecodingFormat = new DecodingFormatMock("#", false);
    keyDecodingFormat.producedDataType = DataTypes.ROW(DataTypes.FIELD(NAME, DataTypes.STRING().notNull())).notNull();
    final DecodingFormatMock valueDecodingFormat = new DecodingFormatMock("|", false);
    valueDecodingFormat.producedDataType = DataTypes.ROW(DataTypes.FIELD(COUNT, DataTypes.DECIMAL(38, 18)), DataTypes.FIELD(TIME, DataTypes.TIMESTAMP(3))).notNull();
    final KafkaDynamicSource expectedKafkaSource = createExpectedScanSource(SCHEMA_DATA_TYPE, keyDecodingFormat, valueDecodingFormat, new int[] { 0 }, new int[] { 1, 2 }, null, Collections.singletonList(TOPIC), null, KAFKA_FINAL_SOURCE_PROPERTIES, StartupMode.GROUP_OFFSETS, Collections.emptyMap(), 0);
    assertThat(actualSource).isEqualTo(expectedKafkaSource);
}
Also used : DecodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with DecodingFormatMock

use of org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock 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);
}
Also used : EncodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.EncodingFormatMock) DecodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) DynamicTableSourceMock(org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSourceMock) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) DynamicTableSinkMock(org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSinkMock) Test(org.junit.jupiter.api.Test)

Aggregations

DecodingFormatMock (org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock)9 Test (org.junit.jupiter.api.Test)9 DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)8 HashMap (java.util.HashMap)4 DynamicTableSink (org.apache.flink.table.connector.sink.DynamicTableSink)4 DynamicTableSinkMock (org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSinkMock)4 DynamicTableSourceMock (org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSourceMock)4 EncodingFormatMock (org.apache.flink.table.factories.TestFormatFactory.EncodingFormatMock)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 DeserializationSchema (org.apache.flink.api.common.serialization.DeserializationSchema)2 KafkaTopicPartition (org.apache.flink.streaming.connectors.kafka.internals.KafkaTopicPartition)2 ScanTableSource (org.apache.flink.table.connector.source.ScanTableSource)2 DataType (org.apache.flink.table.types.DataType)1