Attempting to fix the KafkaItemReaderTests#testReadFromMultiplePartitionsAfterRestart

This commit is contained in:
Michael Minella
2019-08-02 17:06:54 -05:00
parent 683340e23f
commit a140a9f5a1

View File

@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.ExecutionException;
import org.apache.kafka.clients.admin.NewTopic; import org.apache.kafka.clients.admin.NewTopic;
import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.clients.consumer.ConsumerConfig;
@@ -38,6 +39,7 @@ import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory; import org.springframework.kafka.core.ProducerFactory;
import org.springframework.kafka.test.rule.EmbeddedKafkaRule; import org.springframework.kafka.test.rule.EmbeddedKafkaRule;
import org.springframework.kafka.test.utils.KafkaTestUtils; import org.springframework.kafka.test.utils.KafkaTestUtils;
import org.springframework.util.concurrent.ListenableFuture;
import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
@@ -269,15 +271,20 @@ public class KafkaItemReaderTests {
} }
@Test @Test
public void testReadFromMultiplePartitionsAfterRestart() { public void testReadFromMultiplePartitionsAfterRestart() throws ExecutionException, InterruptedException {
this.template.send("topic4", 0, null, "val0"); List<ListenableFuture> futures = new ArrayList<>();
this.template.send("topic4", 0, null, "val2"); futures.add(this.template.send("topic4", 0, null, "val0"));
this.template.send("topic4", 0, null, "val4"); futures.add(this.template.send("topic4", 0, null, "val2"));
this.template.send("topic4", 0, null, "val6"); futures.add(this.template.send("topic4", 0, null, "val4"));
this.template.send("topic4", 1, null, "val1"); futures.add(this.template.send("topic4", 0, null, "val6"));
this.template.send("topic4", 1, null, "val3"); futures.add(this.template.send("topic4", 1, null, "val1"));
this.template.send("topic4", 1, null, "val5"); futures.add(this.template.send("topic4", 1, null, "val3"));
this.template.send("topic4", 1, null, "val7"); futures.add(this.template.send("topic4", 1, null, "val5"));
futures.add(this.template.send("topic4", 1, null, "val7"));
for (ListenableFuture future : futures) {
future.get();
}
ExecutionContext executionContext = new ExecutionContext(); ExecutionContext executionContext = new ExecutionContext();
Map<TopicPartition, Long> offsets = new HashMap<>(); Map<TopicPartition, Long> offsets = new HashMap<>();