|
17 | 17 |
|
18 | 18 | package org.apache.flink.cdc.composer.flink; |
19 | 19 |
|
| 20 | +import org.apache.flink.cdc.common.configuration.ConfigOption; |
20 | 21 | import org.apache.flink.cdc.common.configuration.Configuration; |
21 | 22 | import org.apache.flink.cdc.common.factories.DataSinkFactory; |
| 23 | +import org.apache.flink.cdc.common.factories.DataSourceFactory; |
22 | 24 | import org.apache.flink.cdc.common.factories.FactoryHelper; |
23 | 25 | import org.apache.flink.cdc.common.pipeline.PipelineOptions; |
24 | 26 | import org.apache.flink.cdc.common.sink.DataSink; |
| 27 | +import org.apache.flink.cdc.common.sink.EventSinkProvider; |
| 28 | +import org.apache.flink.cdc.common.sink.MetadataApplier; |
| 29 | +import org.apache.flink.cdc.common.source.DataSource; |
25 | 30 | import org.apache.flink.cdc.composer.definition.PipelineDef; |
26 | 31 | import org.apache.flink.cdc.composer.definition.SinkDef; |
27 | 32 | import org.apache.flink.cdc.composer.definition.SourceDef; |
28 | 33 | import org.apache.flink.cdc.composer.utils.FactoryDiscoveryUtils; |
29 | 34 | import org.apache.flink.cdc.composer.utils.factory.DataSinkFactory1; |
30 | 35 | import org.apache.flink.cdc.connectors.values.factory.ValuesDataFactory; |
| 36 | +import org.apache.flink.cdc.connectors.values.source.ValuesDataSource; |
| 37 | +import org.apache.flink.cdc.connectors.values.source.ValuesDataSourceHelper; |
| 38 | +import org.apache.flink.configuration.DeploymentOptions; |
31 | 39 |
|
32 | 40 | import org.apache.flink.shaded.guava31.com.google.common.collect.ImmutableMap; |
33 | 41 |
|
|
38 | 46 | import org.junit.jupiter.params.provider.MethodSource; |
39 | 47 |
|
40 | 48 | import java.util.Collections; |
| 49 | +import java.util.HashSet; |
| 50 | +import java.util.Set; |
41 | 51 | import java.util.stream.Stream; |
42 | 52 |
|
| 53 | +import static org.assertj.core.api.Assertions.assertThatCode; |
43 | 54 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
44 | 55 |
|
45 | 56 | /** A test for the {@link FlinkPipelineComposer}. */ |
@@ -72,6 +83,96 @@ void testCreateDataSinkFromSinkDef() { |
72 | 83 | .isEqualTo("0.0.0.0"); |
73 | 84 | } |
74 | 85 |
|
| 86 | + @Test |
| 87 | + void testGettingFlinkConfiguration() { |
| 88 | + FlinkPipelineComposer composer = FlinkPipelineComposer.ofMiniCluster(); |
| 89 | + PipelineDef pipelineDef = |
| 90 | + new PipelineDef( |
| 91 | + new SourceDef(TestDataSourceFactory.IDENTIFIER, null, new Configuration()), |
| 92 | + new SinkDef(TestDataSinkFactory.IDENTIFIER, null, new Configuration()), |
| 93 | + Collections.emptyList(), |
| 94 | + Collections.emptyList(), |
| 95 | + Collections.emptyList(), |
| 96 | + new Configuration()); |
| 97 | + |
| 98 | + assertThatCode(() -> composer.compose(pipelineDef)).doesNotThrowAnyException(); |
| 99 | + } |
| 100 | + |
| 101 | + /** A dummy {@link DataSinkFactory} that validates the execution target. */ |
| 102 | + public static class TestDataSinkFactory implements DataSinkFactory { |
| 103 | + |
| 104 | + public static final String IDENTIFIER = "test-sink-factory"; |
| 105 | + |
| 106 | + @Override |
| 107 | + public DataSink createDataSink(Context context) { |
| 108 | + // This option has no default value. |
| 109 | + String target = context.getFlinkConf().get(DeploymentOptions.TARGET); |
| 110 | + if (!"local".equals(target)) { |
| 111 | + throw new IllegalArgumentException( |
| 112 | + "The flink configuration is invalid. Please check the pipeline configuration."); |
| 113 | + } |
| 114 | + return new DataSink() { |
| 115 | + @Override |
| 116 | + public EventSinkProvider getEventSinkProvider() { |
| 117 | + return null; |
| 118 | + } |
| 119 | + |
| 120 | + @Override |
| 121 | + public MetadataApplier getMetadataApplier() { |
| 122 | + return schemaChangeEvent -> {}; |
| 123 | + } |
| 124 | + }; |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public String identifier() { |
| 129 | + return IDENTIFIER; |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public Set<ConfigOption<?>> requiredOptions() { |
| 134 | + return new HashSet<>(); |
| 135 | + } |
| 136 | + |
| 137 | + @Override |
| 138 | + public Set<ConfigOption<?>> optionalOptions() { |
| 139 | + return new HashSet<>(); |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + /** A dummy {@link DataSourceFactory} that validates the execution target. */ |
| 144 | + public static class TestDataSourceFactory implements DataSourceFactory { |
| 145 | + |
| 146 | + public static final String IDENTIFIER = "test-source-factory"; |
| 147 | + |
| 148 | + @Override |
| 149 | + public DataSource createDataSource(Context context) { |
| 150 | + // This option has no default value. |
| 151 | + String target = context.getFlinkConf().get(DeploymentOptions.TARGET); |
| 152 | + if (!"local".equals(target)) { |
| 153 | + throw new IllegalArgumentException( |
| 154 | + "The flink configuration is invalid. Please check the pipeline configuration."); |
| 155 | + } |
| 156 | + return new ValuesDataSource( |
| 157 | + ValuesDataSourceHelper.EventSetId.SINGLE_SPLIT_SINGLE_TABLE, Integer.MAX_VALUE); |
| 158 | + } |
| 159 | + |
| 160 | + @Override |
| 161 | + public String identifier() { |
| 162 | + return IDENTIFIER; |
| 163 | + } |
| 164 | + |
| 165 | + @Override |
| 166 | + public Set<ConfigOption<?>> requiredOptions() { |
| 167 | + return new HashSet<>(); |
| 168 | + } |
| 169 | + |
| 170 | + @Override |
| 171 | + public Set<ConfigOption<?>> optionalOptions() { |
| 172 | + return new HashSet<>(); |
| 173 | + } |
| 174 | + } |
| 175 | + |
75 | 176 | @ParameterizedTest |
76 | 177 | @MethodSource |
77 | 178 | void testInvalidPipelineConfiguration(Configuration pipelineConfig) { |
|
0 commit comments