johnjcasey commented on code in PR #21752:
URL: https://github.com/apache/beam/pull/21752#discussion_r903988026
##########
sdks/java/io/kafka/src/test/java/org/apache/beam/sdk/io/kafka/KafkaIOIT.java:
##########
@@ -259,8 +272,131 @@ public void processElement(
return null;
});
+ PipelineResult writeResult = writePipeline.run();
+ writeResult.waitUntilFinish();
+
PipelineResult readResult = readPipeline.run();
- readResult.waitUntilFinish();
+ PipelineResult.State readState =
+
readResult.waitUntilFinish(Duration.standardSeconds(options.getReadTimeout()));
+
+ cancelIfTimeouted(readResult, readState);
+ }
+
+ @Test
+ public void testKafkaWithDynamicPartitions() throws IOException {
+ AdminClient client =
+ AdminClient.create(
+ ImmutableMap.of("bootstrap.servers",
options.getKafkaBootstrapServerAddresses()));
+ String topicName = "DynamicTopicPartition-" + UUID.randomUUID();
+ Map<Integer, String> records = new HashMap<>();
+ for (int i = 0; i < 100; i++) {
+ records.put(i, String.valueOf(i));
+ }
+ Map<Integer, String> moreRecords = new HashMap<>();
+ for (int i = 100; i < 200; i++) {
+ moreRecords.put(i, String.valueOf(i));
+ }
+ try {
+ client.createTopics(ImmutableSet.of(new NewTopic(topicName, 1, (short)
1)));
+ client.createPartitions(ImmutableMap.of(topicName,
NewPartitions.increaseTo(1)));
+
+ writePipeline
+ .apply("Generate Write Elements", Create.of(records))
+ .apply(
+ "Write to Kafka",
+ KafkaIO.<Integer, String>write()
+
.withBootstrapServers(options.getKafkaBootstrapServerAddresses())
+ .withTopic(topicName)
+ .withKeySerializer(IntegerSerializer.class)
+ .withValueSerializer(StringSerializer.class));
+
+ writePipeline.run().waitUntilFinish(Duration.standardSeconds(15));
+
+ System.out.println("after write 1");
+
+ Thread delayedWriteThread =
+ new Thread(
+ () -> {
+ try {
+ Thread.sleep(20 * 1000); // wait 20 seconds before changing
kafka
Review Comment:
the goal of this is to wait some amount of time before repartitioning kafka,
and then publishing more data to kafka. Thus far it has not been flaky.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]