mirror of https://github.com/apache/kafka.git
kafka-1571; MetadataTest hangs; patched by Jun Rao; reviewed by Guozhang Wang
This commit is contained in:
parent
f8d521a961
commit
1d2e776d8c
|
@ -17,6 +17,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.apache.kafka.clients.producer.internals.Metadata;
|
import org.apache.kafka.clients.producer.internals.Metadata;
|
||||||
import org.apache.kafka.common.Cluster;
|
import org.apache.kafka.common.Cluster;
|
||||||
|
import org.apache.kafka.common.errors.TimeoutException;
|
||||||
import org.apache.kafka.test.TestUtils;
|
import org.apache.kafka.test.TestUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -40,8 +41,6 @@ public class MetadataTest {
|
||||||
Thread t2 = asyncFetch(topic);
|
Thread t2 = asyncFetch(topic);
|
||||||
assertTrue("Awaiting update", t1.isAlive());
|
assertTrue("Awaiting update", t1.isAlive());
|
||||||
assertTrue("Awaiting update", t2.isAlive());
|
assertTrue("Awaiting update", t2.isAlive());
|
||||||
// keep updating the metadata until no need to
|
|
||||||
while (metadata.timeToNextUpdate(time) == 0)
|
|
||||||
metadata.update(TestUtils.singletonCluster(topic, 1), time);
|
metadata.update(TestUtils.singletonCluster(topic, 1), time);
|
||||||
t1.join();
|
t1.join();
|
||||||
t2.join();
|
t2.join();
|
||||||
|
@ -53,8 +52,13 @@ public class MetadataTest {
|
||||||
private Thread asyncFetch(final String topic) {
|
private Thread asyncFetch(final String topic) {
|
||||||
Thread thread = new Thread() {
|
Thread thread = new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
while (metadata.fetch().partitionsForTopic(topic) == null)
|
while (metadata.fetch().partitionsForTopic(topic) == null) {
|
||||||
metadata.awaitUpdate(metadata.requestUpdate(), Long.MAX_VALUE);
|
try {
|
||||||
|
metadata.awaitUpdate(metadata.requestUpdate(), refreshBackoffMs);
|
||||||
|
} catch(TimeoutException e) {
|
||||||
|
// let it go
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
thread.start();
|
thread.start();
|
||||||
|
|
Loading…
Reference in New Issue