Github user mbalassi commented on a diff in the pull request: https://github.com/apache/flink/pull/589#discussion_r28227590 --- Diff: flink-staging/flink-streaming/flink-streaming-connectors/src/test/java/org/apache/flink/streaming/connectors/kafka/KafkaITCase.java --- @@ -524,13 +537,149 @@ public void cancel() { } } + private static boolean leaderHasShutDown = false; + + @Test + public void brokerFailureTest() throws Exception { + String topic = "brokerFailureTestTopic"; + + createTestTopic(topic, 2, 2); - private void createTestTopic(String topic, int numberOfPartitions) { KafkaTopicUtils kafkaTopicUtils = new KafkaTopicUtils(zookeeperConnectionString); - kafkaTopicUtils.createTopic(topic, numberOfPartitions, 1); + final String leaderToShutDown = + kafkaTopicUtils.waitAndGetPartitionMetadata(topic, 0).leader().get().connectionString(); + + final Thread brokerShutdown = new Thread(new Runnable() { + @Override + public void run() { + shutdownKafkaBroker = false; + while (!shutdownKafkaBroker) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + LOG.warn("Interruption", e); + } + } + + for (KafkaServer kafkaServer : brokers) { + if (leaderToShutDown.equals( + kafkaServer.config().advertisedHostName() + + ":" + + kafkaServer.config().advertisedPort() + )) { + LOG.info("Killing Kafka Server {}", leaderToShutDown); + kafkaServer.shutdown(); + leaderHasShutDown = true; + break; + } + } + } + }); + brokerShutdown.start(); + + final StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment(1); + --- End diff -- I would use `TestSreamEnvironment` instead.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---