congbobo184 commented on a change in pull request #11135:
URL: https://github.com/apache/pulsar/pull/11135#discussion_r660424152
##########
File path:
pulsar-broker/src/test/java/org/apache/pulsar/client/api/MessageDispatchThrottlingTest.java
##########
@@ -417,56 +418,45 @@ public void
testBytesRateLimitingReceiveAllMessagesAfterThrottling(SubscriptionT
final String namespace = "my-property/throttling_ns";
final String topicName = "persistent://" + namespace +
"/throttlingAll";
+ final String subscriptionName = "my-subscriber-name";
- final int byteRate = 100;
+ //
+ final int byteRate = 250;
DispatchRate dispatchRate = DispatchRate.builder()
.dispatchThrottlingRateInMsg(-1)
.dispatchThrottlingRateInByte(byteRate)
.ratePeriodInSecond(1)
.build();
admin.namespaces().createNamespace(namespace, Sets.newHashSet("test"));
admin.namespaces().setDispatchRate(namespace, dispatchRate);
+ admin.topics().createSubscription(topicName, subscriptionName,
MessageId.earliest);
// create producer and topic
- Producer<byte[]> producer =
pulsarClient.newProducer().topic(topicName).create();
+ Producer<byte[]> producer =
pulsarClient.newProducer().topic(topicName).enableBatching(false).create();
PersistentTopic topic = (PersistentTopic)
pulsar.getBrokerService().getOrCreateTopic(topicName).get();
- boolean isMessageRateUpdate = false;
- int retry = 5;
- for (int i = 0; i < retry; i++) {
- if (topic.getDispatchRateLimiter().get().getDispatchRateOnByte() >
0) {
- isMessageRateUpdate = true;
- break;
- } else {
- if (i != retry - 1) {
- Thread.sleep(100);
- }
- }
- }
- Assert.assertTrue(isMessageRateUpdate);
+ Awaitility.await().until(() ->
topic.getDispatchRateLimiter().get().getDispatchRateOnByte() > 0);
Assert.assertEquals(admin.namespaces().getDispatchRate(namespace),
dispatchRate);
final int numProducedMessages = 20;
- final CountDownLatch latch = new CountDownLatch(numProducedMessages);
final AtomicInteger totalReceived = new AtomicInteger(0);
- Consumer<byte[]> consumer =
pulsarClient.newConsumer().topic(topicName).subscriptionName("my-subscriber-name")
+ Consumer<byte[]> consumer =
pulsarClient.newConsumer().topic(topicName).subscriptionName(subscriptionName)
.subscriptionType(subscription).messageListener((c1, msg) -> {
Assert.assertNotNull(msg, "Message cannot be null");
String receivedMessage = new String(msg.getData());
log.debug("Received message [{}] in the listener",
receivedMessage);
totalReceived.incrementAndGet();
- latch.countDown();
}).subscribe();
+
// deactive cursors
deactiveCursors((ManagedLedgerImpl) topic.getManagedLedger());
- // Asynchronously produce messages
for (int i = 0; i < numProducedMessages; i++) {
- producer.send(new byte[byteRate / 10]);
+ producer.send(new byte[99]);
}
- latch.await();
- Assert.assertEquals(totalReceived.get(), numProducedMessages);
+ Awaitility.await().atLeast(3, TimeUnit.SECONDS)
Review comment:
we need to check when the time less than 3 second consumer con't receive
messages more than 6.
--
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]