forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Reopen][Issue 5597] Retry when getPartitionedTopicMetadata failed (a…
…pache#5844) Motivation Fixes apache#5597 Add backoff retries when getting partitioned metadata from brokers. The change in apache#5734 (copy from apache#5603) used the wrong time unit when inited Backoff which failed to trigger the retry logic as expected. Modifications Correct the time unit and add some useful log.
- Loading branch information
Showing
14 changed files
with
221 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
pulsar-broker/src/test/java/org/apache/pulsar/client/impl/PulsarMultiHostClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.client.impl; | ||
|
||
import org.apache.pulsar.client.api.Consumer; | ||
import org.apache.pulsar.client.api.Message; | ||
import org.apache.pulsar.client.api.Producer; | ||
import org.apache.pulsar.client.api.ProducerConsumerBase; | ||
import org.apache.pulsar.client.api.PulsarClient; | ||
import org.apache.pulsar.client.api.PulsarClientException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.testng.Assert.fail; | ||
|
||
public class PulsarMultiHostClientTest extends ProducerConsumerBase { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(PulsarMultiHostClientTest.class); | ||
|
||
@BeforeMethod | ||
@Override | ||
protected void setup() throws Exception { | ||
super.internalSetup(); | ||
super.producerBaseSetup(); | ||
} | ||
|
||
@AfterMethod | ||
@Override | ||
protected void cleanup() throws Exception { | ||
super.internalCleanup(); | ||
} | ||
|
||
@Test | ||
public void testGetPartitionedTopicMetaData() throws Exception { | ||
log.info("-- Starting {} test --", methodName); | ||
|
||
final String topicName = "persistent://my-property/my-ns/my-topic1"; | ||
final String subscriptionName = "my-subscriber-name"; | ||
|
||
try { | ||
String url = "http://localhost:" + BROKER_WEBSERVICE_PORT; | ||
if (isTcpLookup) { | ||
url = "pulsar://localhost:" + BROKER_PORT; | ||
} | ||
PulsarClient client = newPulsarClient(url, 0); | ||
|
||
Consumer<byte[]> consumer = client.newConsumer().topic(topicName).subscriptionName(subscriptionName) | ||
.acknowledgmentGroupTime(0, TimeUnit.SECONDS).subscribe(); | ||
Producer<byte[]> producer = client.newProducer().topic(topicName).create(); | ||
|
||
consumer.close(); | ||
producer.close(); | ||
client.close(); | ||
} catch (PulsarClientException pce) { | ||
log.error("create producer or consumer error: ", pce); | ||
fail(); | ||
} | ||
|
||
log.info("-- Exiting {} test --", methodName); | ||
} | ||
|
||
@Test (timeOut = 4000) | ||
public void testGetPartitionedTopicDataTimeout() { | ||
log.info("-- Starting {} test --", methodName); | ||
|
||
final String topicName = "persistent://my-property/my-ns/my-topic1"; | ||
|
||
String url = "http://localhost:51000,localhost:51001"; | ||
if (isTcpLookup) { | ||
url = "pulsar://localhost:51000,localhost:51001"; | ||
} | ||
|
||
PulsarClient client; | ||
try { | ||
client = PulsarClient.builder() | ||
.serviceUrl(url) | ||
.statsInterval(0, TimeUnit.SECONDS) | ||
.operationTimeout(3, TimeUnit.SECONDS) | ||
.build(); | ||
|
||
Producer<byte[]> producer = client.newProducer().topic(topicName).create(); | ||
|
||
fail(); | ||
} catch (PulsarClientException pce) { | ||
log.error("create producer error: ", pce); | ||
} | ||
|
||
log.info("-- Exiting {} test --", methodName); | ||
} | ||
|
||
@Test | ||
public void testMultiHostUrlRetrySuccess() throws Exception { | ||
log.info("-- Starting {} test --", methodName); | ||
|
||
final String topicName = "persistent://my-property/my-ns/my-topic1"; | ||
final String subscriptionName = "my-subscriber-name"; | ||
|
||
// Multi hosts included an unreached port and the actual port for verify retry logic | ||
String urlsWithUnreached = "http://localhost:51000,localhost:" + BROKER_WEBSERVICE_PORT; | ||
if (isTcpLookup) { | ||
urlsWithUnreached = "pulsar://localhost:51000,localhost:" + BROKER_PORT; | ||
} | ||
PulsarClient client = newPulsarClient(urlsWithUnreached, 0); | ||
|
||
Consumer<byte[]> consumer = client.newConsumer().topic(topicName).subscriptionName(subscriptionName) | ||
.acknowledgmentGroupTime(0, TimeUnit.SECONDS).subscribe(); | ||
Producer<byte[]> producer = client.newProducer().topic(topicName).create(); | ||
|
||
for (int i = 0; i < 5; i++) { | ||
String message = "my-message-" + i; | ||
producer.send(message.getBytes()); | ||
log.info("Produced message: [{}]", message); | ||
} | ||
|
||
Message<byte[]> msg = null; | ||
Set<String> messageSet = new HashSet(); | ||
for (int i = 0; i < 5; i++) { | ||
msg = consumer.receive(5, TimeUnit.SECONDS); | ||
String receivedMessage = new String(msg.getData()); | ||
log.info("Received message: [{}]", receivedMessage); | ||
String expectedMessage = "my-message-" + i; | ||
testMessageOrderAndDuplicates(messageSet, receivedMessage, expectedMessage); | ||
} | ||
|
||
// Acknowledge the consumption of all messages at once | ||
consumer.acknowledgeCumulative(msg); | ||
consumer.close(); | ||
|
||
producer.close(); | ||
client.close(); | ||
|
||
log.info("-- Exiting {} test --", methodName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.