|
23 | 23 | import java.util.Arrays;
|
24 | 24 | import java.util.Collections;
|
25 | 25 | import java.util.HashMap;
|
| 26 | +import java.util.List; |
26 | 27 | import java.util.Map;
|
27 | 28 | import java.util.Properties;
|
28 | 29 | import java.util.concurrent.ExecutionException;
|
@@ -144,7 +145,7 @@ void setUp() throws ExecutionException, InterruptedException {
|
144 | 145 | final NewTopic newTopic = new NewTopic(TestSourceConnector.NEW_TOPIC, 1, (short) 1);
|
145 | 146 | final NewTopic originalTopicForExtractTopicFromValue =
|
146 | 147 | new NewTopic(TopicFromValueSchemaConnector.TOPIC, 1, (short) 1);
|
147 |
| - final NewTopic newTopicForExtractTopicFromValue = |
| 148 | + final NewTopic newTopicForExtractTopicFromValue = |
148 | 149 | new NewTopic(TopicFromValueSchemaConnector.NAME, 1, (short) 1);
|
149 | 150 | adminClient.createTopics(Arrays.asList(originalTopic, newTopic, originalTopicForExtractTopicFromValue,
|
150 | 151 | newTopicForExtractTopicFromValue)).all().get();
|
@@ -234,6 +235,40 @@ void testCaseTransform() throws ExecutionException, InterruptedException, IOExce
|
234 | 235 | );
|
235 | 236 | }
|
236 | 237 |
|
| 238 | + @Test |
| 239 | + @Timeout(10) |
| 240 | + void testKeyToValue() throws ExecutionException, InterruptedException, IOException { |
| 241 | + |
| 242 | + final String topicName = TestKeyToValueConnector.TARGET_TOPIC; |
| 243 | + adminClient.createTopics(List.of(new NewTopic(topicName, 1, (short) 1))).all().get(); |
| 244 | + |
| 245 | + final Map<String, String> connectorConfig = new HashMap<>(); |
| 246 | + connectorConfig.put("name", "test-source-connector"); |
| 247 | + connectorConfig.put("connector.class", TestKeyToValueConnector.class.getName()); |
| 248 | + connectorConfig.put("key.converter", "org.apache.kafka.connect.json.JsonConverter"); |
| 249 | + connectorConfig.put("value.converter", "org.apache.kafka.connect.json.JsonConverter"); |
| 250 | + connectorConfig.put("tasks.max", "1"); |
| 251 | + connectorConfig.put("transforms", "keyToValue"); |
| 252 | + connectorConfig.put("transforms.keyToValue.case", "upper"); |
| 253 | + connectorConfig.put("transforms.keyToValue.key.fields", "a1,a3"); |
| 254 | + connectorConfig.put("transforms.keyToValue.value.fields", "b1"); |
| 255 | + connectorConfig.put("transforms.keyToValue.type", "io.aiven.kafka.connect.transforms.KeyToValue"); |
| 256 | + |
| 257 | + connectRunner.createConnector(connectorConfig); |
| 258 | + |
| 259 | + waitForCondition( |
| 260 | + () -> consumer.endOffsets(Collections.singletonList(new TopicPartition(topicName, 0))) |
| 261 | + .values().stream().reduce(Long::sum).map(s -> s == TestKeyToValueConnector.MESSAGES_TO_PRODUCE) |
| 262 | + .orElse(false), 5000, "Messages appear in target topic" |
| 263 | + ); |
| 264 | + |
| 265 | + final String payload = "'payload':{'b1':'a1','b2':'b2','b3':'b3','a3':'a3'}".replace('\'', '"'); |
| 266 | + consumer.subscribe(Collections.singletonList(topicName)); |
| 267 | + for (final ConsumerRecord<byte[], byte[]> consumerRecord : consumer.poll(Duration.ofSeconds(1))) { |
| 268 | + assertThat(consumerRecord.value()).asString().contains(payload); |
| 269 | + } |
| 270 | + } |
| 271 | + |
237 | 272 | final void checkMessageTransformInTopic(final TopicPartition topicPartition, final long expectedNumberOfMessages)
|
238 | 273 | throws InterruptedException, IOException {
|
239 | 274 | waitForCondition(
|
|
0 commit comments