use of org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock in project flink by apache.
the class FactoryUtilTest method testFactoryHelperWithEnrichmentOptionsAndFormat.
@Test
public void testFactoryHelperWithEnrichmentOptionsAndFormat() {
String keyFormatPrefix = FactoryUtil.getFormatPrefix(TestDynamicTableFactory.KEY_FORMAT, TestFormatFactory.IDENTIFIER);
String valueFormatPrefix = FactoryUtil.getFormatPrefix(TestDynamicTableFactory.VALUE_FORMAT, TestFormatFactory.IDENTIFIER);
final Map<String, String> options = new HashMap<>();
options.put(TestDynamicTableFactory.TARGET.key(), "abc");
options.put(TestDynamicTableFactory.BUFFER_SIZE.key(), "1000");
options.put(TestDynamicTableFactory.KEY_FORMAT.key(), TestFormatFactory.IDENTIFIER);
options.put(keyFormatPrefix + TestFormatFactory.DELIMITER.key(), "|");
options.put(keyFormatPrefix + TestFormatFactory.FAIL_ON_MISSING.key(), "true");
options.put(TestDynamicTableFactory.VALUE_FORMAT.key(), TestFormatFactory.IDENTIFIER);
options.put(valueFormatPrefix + TestFormatFactory.DELIMITER.key(), "|");
options.put(valueFormatPrefix + TestFormatFactory.FAIL_ON_MISSING.key(), "true");
final Map<String, String> enrichment = new HashMap<>();
enrichment.put(TestDynamicTableFactory.TARGET.key(), "xyz");
enrichment.put(TestDynamicTableFactory.BUFFER_SIZE.key(), "2000");
enrichment.put(TestDynamicTableFactory.KEY_FORMAT.key(), TestFormatFactory.IDENTIFIER);
enrichment.put(keyFormatPrefix + TestFormatFactory.DELIMITER.key(), ",");
enrichment.put(keyFormatPrefix + TestFormatFactory.FAIL_ON_MISSING.key(), "true");
enrichment.put(TestDynamicTableFactory.VALUE_FORMAT.key(), TestFormatFactory.IDENTIFIER);
enrichment.put(valueFormatPrefix + TestFormatFactory.DELIMITER.key(), "|");
final FactoryUtil.TableFactoryHelper helper = FactoryUtil.createTableFactoryHelper(new TestDynamicTableFactory(), FactoryMocks.createTableContext(SCHEMA, options, enrichment));
// Get resulting format mocks from key and value
// Note: the only forwardable option for the test format is the delimiter
DecodingFormatMock keyDecodingFormatMock = (DecodingFormatMock) helper.discoverDecodingFormat(DeserializationFormatFactory.class, TestDynamicTableFactory.KEY_FORMAT);
DecodingFormatMock valueDecodingFormatMock = (DecodingFormatMock) helper.discoverDecodingFormat(DeserializationFormatFactory.class, TestDynamicTableFactory.VALUE_FORMAT);
helper.validate();
// Check table options
assertThat(helper.getOptions().get(TestDynamicTableFactory.TARGET)).isEqualTo("abc");
assertThat(helper.getOptions().get(TestDynamicTableFactory.BUFFER_SIZE)).isEqualTo(2000);
// Check format options
assertThat(keyDecodingFormatMock.delimiter).isEqualTo(",");
assertThat(keyDecodingFormatMock.failOnMissing).isTrue();
assertThat(valueDecodingFormatMock.delimiter).isEqualTo("|");
assertThat(valueDecodingFormatMock.failOnMissing).isTrue();
}
use of org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock in project flink by apache.
the class FactoryUtilTest method testDiscoveryForSeparateSourceSinkFactory.
@Test
public void testDiscoveryForSeparateSourceSinkFactory() {
final Map<String, String> options = createAllOptions();
// the "test" source and sink factory is not in one factory class
// see TestDynamicTableSinkFactory and TestDynamicTableSourceFactory
options.put("connector", "test");
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.factories.TestFormatFactory.DecodingFormatMock in project flink by apache.
the class FactoryUtilTest method testAlternativeValueFormat.
@Test
public void testAlternativeValueFormat() {
final Map<String, String> options = createAllOptions();
options.remove("value.format");
options.remove("value.test-format.delimiter");
options.remove("value.test-format.fail-on-missing");
options.put("format", "test-format");
options.put("test-format.delimiter", ";");
options.put("test-format.fail-on-missing", "true");
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.factories.TestFormatFactory.DecodingFormatMock in project flink by apache.
the class FactoryUtilTest method testOptionalFormat.
@Test
public void testOptionalFormat() {
final Map<String, String> options = createAllOptions();
options.remove("key.format");
options.remove("key.test-format.delimiter");
final DynamicTableSource actualSource = createTableSource(SCHEMA, options);
final DynamicTableSource expectedSource = new DynamicTableSourceMock("MyTarget", null, null, new DecodingFormatMock("|", true));
assertThat(actualSource).isEqualTo(expectedSource);
final DynamicTableSink actualSink = createTableSink(SCHEMA, options);
final DynamicTableSink expectedSink = new DynamicTableSinkMock("MyTarget", 1000L, null, new EncodingFormatMock("|"));
assertThat(actualSink).isEqualTo(expectedSink);
}
Aggregations