diff --git a/.github/workflows/ci-unit.yaml b/.github/workflows/ci-unit.yaml index c793d8fe8790e..31d3a923a93ea 100644 --- a/.github/workflows/ci-unit.yaml +++ b/.github/workflows/ci-unit.yaml @@ -64,7 +64,7 @@ jobs: run: mvn install -DfailIfNoTests=false '-Dtest=!KafkaProducerSimpleConsumerTest,!PrimitiveSchemaTest,!BlobStoreManagedLedgerOffloaderTest' -pl '!pulsar-broker,!pulsar-proxy,!pulsar-broker-auth-sasl,!pulsar-io/kafka-connect-adaptor,!tests/pulsar-storm-test' - name: package surefire artifacts - if: failure() + if: always() run: | rm -rf artifacts mkdir artifacts @@ -73,7 +73,7 @@ jobs: - uses: actions/upload-artifact@master name: upload surefire-artifacts - if: failure() + if: always() with: name: surefire-artifacts path: artifacts.zip diff --git a/pom.xml b/pom.xml index 9bdeba5a5f802..fd5023b041e74 100644 --- a/pom.xml +++ b/pom.xml @@ -214,6 +214,7 @@ flexible messaging model and an intuitive client API. 3.25.0-GA 2.3.1 1.5.0 + 4.0.2 0.6.1 @@ -251,6 +252,13 @@ flexible messaging model and an intuitive client API. ${testng.version} + + org.awaitility + awaitility + ${awaitility.version} + test + + org.mockito mockito-core diff --git a/pulsar-broker/pom.xml b/pulsar-broker/pom.xml index dece2f82ee2fe..317d2f87029f0 100644 --- a/pulsar-broker/pom.xml +++ b/pulsar-broker/pom.xml @@ -34,6 +34,11 @@ Pulsar Broker + + org.awaitility + awaitility + + commons-codec commons-codec diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java index b91bce838486d..56e7a8cdf87ff 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java @@ -140,7 +140,7 @@ public class ServerCnx extends PulsarHandler { AuthenticationState originalAuthState; private boolean pendingAuthChallengeResponse = false; - // Max number of pending requests per connections. If multiple producers are sharing the same connection the flow + // Max number of pending requests per connections. If multiple producers are sharing the same connection, the flow // control done by a single producer might not be enough to prevent write spikes on the broker. private final int maxPendingSendRequests; private final int resumeReadsThreshold; @@ -704,6 +704,7 @@ protected void handleAuthResponse(CommandAuthResponse authResponse) { @Override protected void handleSubscribe(final CommandSubscribe subscribe) { + log.info("handleSubscribe is getting called on ServerCnx"); checkArgument(state == State.Connected); final long requestId = subscribe.getRequestId(); final long consumerId = subscribe.getConsumerId(); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java index d8326285076fb..b6646c79de18b 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java @@ -206,7 +206,7 @@ public void clusters() throws Exception { admin.clusters().createCluster("usw", new ClusterData("http://broker.messaging.use.example.com:8080")); // "test" cluster is part of config-default cluster and it's znode gets created when PulsarService creates - // failure-domain znode of this default cluster + // failure-domain znode of this default cluster. assertEquals(admin.clusters().getClusters(), Lists.newArrayList("test", "usw")); assertEquals(admin.clusters().getCluster("test"), diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java index 558ce39d09f27..ce80c0c59c85b 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java @@ -436,7 +436,7 @@ private void unloadTopic(String topicName, boolean isPersistentTopic) throws Exc * @param namespaceName * @throws Exception */ - @Test(dataProvider = "namespaceNames", timeOut = 10000) + @Test(dataProvider = "namespaceNames", timeOut = 30000) public void testResetCursorOnPosition(String namespaceName) throws Exception { final String topicName = "persistent://prop-xyz/use/" + namespaceName + "/resetPosition"; final int totalProducedMessages = 50; @@ -459,7 +459,7 @@ public void testResetCursorOnPosition(String namespaceName) throws Exception { MessageIdImpl resetMessageId = null; int resetPositionId = 10; for (int i = 0; i < 20; i++) { - message = consumer.receive(1, TimeUnit.SECONDS); + message = consumer.receive(5, TimeUnit.SECONDS); consumer.acknowledge(message); if (i == resetPositionId) { resetMessageId = (MessageIdImpl) message.getMessageId(); @@ -959,7 +959,7 @@ public void testCreateNamespaceWithNoClusters() throws PulsarAdminException { Collections.singletonList(localCluster)); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testConsumerStatsLastTimestamp() throws PulsarClientException, PulsarAdminException, InterruptedException { long timestamp = System.currentTimeMillis(); final String topicName = "consumer-stats-" + timestamp; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v1/V1_AdminApiTest2.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v1/V1_AdminApiTest2.java index 4c8289bfa34da..5b9ec6428e5d3 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v1/V1_AdminApiTest2.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v1/V1_AdminApiTest2.java @@ -449,7 +449,7 @@ public void testResetCursorOnPosition(String namespaceName) throws Exception { MessageIdImpl resetMessageId = null; int resetPositionId = 10; for (int i = 0; i < 20; i++) { - message = consumer.receive(1, TimeUnit.SECONDS); + message = consumer.receive(5, TimeUnit.SECONDS); consumer.acknowledge(message); if (i == resetPositionId) { resetMessageId = (MessageIdImpl) message.getMessageId(); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BatchMessageTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BatchMessageTest.java index 3d5f95603b057..33e2d4759ef73 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BatchMessageTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BatchMessageTest.java @@ -463,7 +463,7 @@ public void testSimpleBatchProducerConsumer1kMessages(BatcherBuilder builder) th Message lastunackedMsg = null; for (int i = 0; i < numMsgs; i++) { - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(5, TimeUnit.SECONDS); assertNotNull(msg); lastunackedMsg = msg; } @@ -708,7 +708,7 @@ public void testConcurrentBatchMessageAck(BatcherBuilder builder) throws Excepti for (int i = 0; i < numMsgs; i++) { executor.submit(() -> { try { - Message msg = myConsumer.receive(1, TimeUnit.SECONDS); + Message msg = myConsumer.receive(5, TimeUnit.SECONDS); myConsumer.acknowledge(msg); } catch (Exception e) { failed.set(false); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerBkEnsemblesTests.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerBkEnsemblesTests.java index c4ceaaa4074d7..fd385683bb42b 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerBkEnsemblesTests.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerBkEnsemblesTests.java @@ -96,7 +96,7 @@ public void testCrashBrokerWithoutCursorLedgerLeak() throws Exception { } Message msg = null; for (int i = 0; i < 10; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); consumer.acknowledge(msg); } @@ -130,7 +130,7 @@ public void testCrashBrokerWithoutCursorLedgerLeak() throws Exception { producer.send(message.getBytes()); } for (int i = 0; i < 10; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); consumer.acknowledge(msg); } @@ -215,7 +215,7 @@ public void testSkipCorruptDataLedger() throws Exception { } // validate: consumer is able to consume msg and close consumer after reading 1 entry - Assert.assertNotNull(consumer.receive(1, TimeUnit.SECONDS)); + Assert.assertNotNull(consumer.receive(5, TimeUnit.SECONDS)); // Need to replace with await() consumer.close(); NavigableMap ledgerInfo = ml.getLedgersInfo(); @@ -249,14 +249,14 @@ public void testSkipCorruptDataLedger() throws Exception { Message msg = null; // start consuming message consumer = client.newConsumer().topic(topic1).subscriptionName("my-subscriber-name").subscribe(); - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(10, TimeUnit.MILLISECONDS); Assert.assertNull(msg); consumer.close(); // (4) enable dynamic config to skip non-recoverable data-ledgers admin.brokers().updateDynamicConfiguration("autoSkipNonRecoverableData", "true"); - retryStrategically((test) -> config.isAutoSkipNonRecoverableData(), 5, 100); + retryStrategically((test) -> config.isAutoSkipNonRecoverableData(), 15, 300); // (5) consumer will be able to consume 20 messages from last non-deleted ledger consumer = client.newConsumer().topic(topic1).subscriptionName("my-subscriber-name").subscribe(); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerBookieIsolationTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerBookieIsolationTest.java index feea1156ba143..ba6a8f3dcd671 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerBookieIsolationTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerBookieIsolationTest.java @@ -246,7 +246,7 @@ public void testBookieIsolation() throws Exception { * @throws Exception */ @Test - public void testBookieIsilationWithSecondaryGroup() throws Exception { + public void testBookieIsolationWithSecondaryGroup() throws Exception { final String tenant1 = "tenant1"; final String cluster = "use"; final String ns1 = String.format("%s/%s/%s", tenant1, cluster, "ns1"); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerTestBase.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerTestBase.java index 314ccfaa4af2d..c7a60434ca636 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerTestBase.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerTestBase.java @@ -30,7 +30,7 @@ /** */ public abstract class BrokerTestBase extends MockedPulsarServiceBaseTest { - protected static final int ASYNC_EVENT_COMPLETION_WAIT = 100; + protected static final int ASYNC_EVENT_COMPLETION_WAIT = 500; protected PulsarService getPulsar() { return pulsar; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PartitionKeyTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PartitionKeyTest.java index fce443b388272..d48896ec0552a 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PartitionKeyTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PartitionKeyTest.java @@ -27,6 +27,8 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import java.util.concurrent.TimeUnit; + /** */ @Test diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PeerReplicatorTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PeerReplicatorTest.java index 27493c9405f6d..45625e650168c 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PeerReplicatorTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PeerReplicatorTest.java @@ -48,13 +48,13 @@ public class PeerReplicatorTest extends ReplicatorTestBase { @Override - @BeforeClass(timeOut = 300000) + @BeforeClass(timeOut = 900000) void setup() throws Exception { super.setup(); } @Override - @AfterClass(timeOut = 300000) + @AfterClass(timeOut = 900000) void shutdown() throws Exception { super.shutdown(); } diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentFailoverE2ETest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentFailoverE2ETest.java index eccaea6237244..8549c34cd1911 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentFailoverE2ETest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentFailoverE2ETest.java @@ -18,11 +18,13 @@ */ package org.apache.pulsar.broker.service; +import static org.hamcrest.MatcherAssert.assertThat; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; +import static org.awaitility.Awaitility.*; import com.google.common.collect.Lists; import com.google.common.collect.Sets; @@ -70,7 +72,7 @@ protected void cleanup() throws Exception { super.internalCleanup(); } - private static final int CONSUMER_ADD_OR_REMOVE_WAIT_TIME = 100; + private static final int CONSUMER_ADD_OR_REMOVE_WAIT_TIME = 500; private static class TestConsumerStateEventListener implements ConsumerEventListener { @@ -109,18 +111,36 @@ private void verifyConsumerNotReceiveAnyStateChanges(TestConsumerStateEventListe assertNull(listener.inActiveQueue.poll()); } - private void verifyConsumerActive(TestConsumerStateEventListener listener, int partitionId) throws Exception { + private void verifyConsumerActive(int waitTime, TestConsumerStateEventListener listener, int partitionId) throws Exception { Integer pid = listener.activeQueue.take(); - assertNotNull(pid); - assertEquals(partitionId, pid.intValue()); - assertNull(listener.inActiveQueue.poll()); + await().atMost(CONSUMER_ADD_OR_REMOVE_WAIT_TIME, + TimeUnit.MILLISECONDS) + .untilAsserted(() -> + assertNotNull(pid)); + await().atMost(CONSUMER_ADD_OR_REMOVE_WAIT_TIME, + TimeUnit.MILLISECONDS) + .untilAsserted(() -> + assertEquals(partitionId, pid.intValue())); + await().atMost(CONSUMER_ADD_OR_REMOVE_WAIT_TIME, + TimeUnit.MILLISECONDS) + .untilAsserted(() -> + assertNull(listener.inActiveQueue.poll())); } - private void verifyConsumerInactive(TestConsumerStateEventListener listener, int partitionId) throws Exception { + private void verifyConsumerInactive(int waitTime, TestConsumerStateEventListener listener, int partitionId) throws Exception { Integer pid = listener.inActiveQueue.take(); - assertNotNull(pid); - assertEquals(partitionId, pid.intValue()); - assertNull(listener.activeQueue.poll()); + await().atMost(CONSUMER_ADD_OR_REMOVE_WAIT_TIME, + TimeUnit.MILLISECONDS) + .untilAsserted(() -> + assertNotNull(pid)); + await().atMost(CONSUMER_ADD_OR_REMOVE_WAIT_TIME, + TimeUnit.MILLISECONDS) + .untilAsserted(() -> + assertEquals(partitionId, pid.intValue())); + await().atMost(CONSUMER_ADD_OR_REMOVE_WAIT_TIME, + TimeUnit.MILLISECONDS) + .untilAsserted(() -> + assertNull(listener.activeQueue.poll())); } private static class ActiveInactiveListenerEvent implements ConsumerEventListener { @@ -159,8 +179,8 @@ public void testSimpleConsumerEventsWithoutPartition() throws Exception { Consumer consumer1 = consumerBulder1.subscribe(); Consumer consumer2 = consumerBuilder.clone().consumerName("2").consumerEventListener(listener2) .subscribe(); - verifyConsumerActive(listener1, -1); - verifyConsumerInactive(listener2, -1); + verifyConsumerActive(ASYNC_EVENT_COMPLETION_WAIT, listener1, -1); + verifyConsumerInactive(ASYNC_EVENT_COMPLETION_WAIT, listener2, -1); listener2.inActiveQueue.clear(); PersistentTopic topicRef = (PersistentTopic) pulsar.getBrokerService().getTopicReference(topicName).get(); @@ -192,9 +212,13 @@ public void testSimpleConsumerEventsWithoutPartition() throws Exception { // 3. consumer1 should have all the messages while consumer2 should have no messages Message msg = null; - Assert.assertNull(consumer2.receive(100, TimeUnit.MILLISECONDS)); + await().atMost(ASYNC_EVENT_COMPLETION_WAIT, + TimeUnit.MILLISECONDS) + .untilAsserted(() -> + assertNull(consumer2.receive(100, TimeUnit.MILLISECONDS))); + for (int i = 0; i < numMsgs; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(2, TimeUnit.SECONDS); Assert.assertNotNull(msg); Assert.assertEquals(new String(msg.getData()), "my-message-" + i); consumer1.acknowledge(msg); @@ -203,8 +227,11 @@ public void testSimpleConsumerEventsWithoutPartition() throws Exception { rolloverPerIntervalStats(); // 4. messages deleted on individual acks - Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT); - assertEquals(subRef.getNumberOfEntriesInBacklog(false), 0); + PersistentSubscription finalSubRef = subRef; + await().atMost(ASYNC_EVENT_COMPLETION_WAIT, + TimeUnit.MILLISECONDS) + .untilAsserted(() -> + assertEquals(finalSubRef.getNumberOfEntriesInBacklog(false), 0)); for (int i = 0; i < numMsgs; i++) { String message = "my-message-" + i; @@ -215,24 +242,24 @@ public void testSimpleConsumerEventsWithoutPartition() throws Exception { // 5. master consumer failure should resend unacked messages and new messages to another consumer for (int i = 0; i < 5; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(2, TimeUnit.SECONDS); Assert.assertNotNull(msg); Assert.assertEquals(new String(msg.getData()), "my-message-" + i); consumer1.acknowledge(msg); } for (int i = 5; i < 10; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(2, TimeUnit.SECONDS); Assert.assertNotNull(msg); Assert.assertEquals(new String(msg.getData()), "my-message-" + i); // do not ack } consumer1.close(); - Thread.sleep(CONSUMER_ADD_OR_REMOVE_WAIT_TIME); - verifyConsumerActive(listener2, -1); + verifyConsumerActive(CONSUMER_ADD_OR_REMOVE_WAIT_TIME, listener2, -1); + verifyConsumerNotReceiveAnyStateChanges(listener1); for (int i = 5; i < numMsgs; i++) { - msg = consumer2.receive(1, TimeUnit.SECONDS); + msg = consumer2.receive(2, TimeUnit.SECONDS); Assert.assertNotNull(msg); Assert.assertEquals(new String(msg.getData()), "my-message-" + i); consumer2.acknowledge(msg); @@ -240,8 +267,11 @@ public void testSimpleConsumerEventsWithoutPartition() throws Exception { Assert.assertNull(consumer2.receive(100, TimeUnit.MILLISECONDS)); rolloverPerIntervalStats(); - Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT); - assertEquals(subRef.getNumberOfEntriesInBacklog(false), 0); + PersistentSubscription finalSubRef1 = subRef; + await().atMost(ASYNC_EVENT_COMPLETION_WAIT, + TimeUnit.MILLISECONDS) + .untilAsserted(() -> + assertEquals(finalSubRef1.getNumberOfEntriesInBacklog(false), 0)); // 8. unsubscribe not allowed if multiple consumers connected try { @@ -325,7 +355,7 @@ public void testSimpleConsumerEventsWithPartition() throws Exception { Message msg = null; Set receivedPtns = Sets.newHashSet(); while (true) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(5, TimeUnit.SECONDS); if (msg == null) { break; } @@ -342,7 +372,7 @@ public void testSimpleConsumerEventsWithPartition() throws Exception { receivedPtns = Sets.newHashSet(); while (true) { - msg = consumer2.receive(1, TimeUnit.SECONDS); + msg = consumer2.receive(5, TimeUnit.SECONDS); if (msg == null) { break; } @@ -369,7 +399,7 @@ public void testSimpleConsumerEventsWithPartition() throws Exception { // add a consumer for (int i = 0; i < 20; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(5, TimeUnit.SECONDS); Assert.assertNotNull(msg); uniqueMessages.add(new String(msg.getData())); consumer1.acknowledge(msg); @@ -380,7 +410,7 @@ public void testSimpleConsumerEventsWithPartition() throws Exception { Thread.sleep(CONSUMER_ADD_OR_REMOVE_WAIT_TIME); int consumer1Messages = 0; while (true) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(5, TimeUnit.SECONDS); if (msg == null) { break; } @@ -390,7 +420,7 @@ public void testSimpleConsumerEventsWithPartition() throws Exception { } int consumer2Messages = 0; while (true) { - msg = consumer2.receive(1, TimeUnit.SECONDS); + msg = consumer2.receive(5, TimeUnit.SECONDS); if (msg == null) { break; } @@ -400,7 +430,7 @@ public void testSimpleConsumerEventsWithPartition() throws Exception { } int consumer3Messages = 0; while (true) { - msg = consumer3.receive(1, TimeUnit.SECONDS); + msg = consumer3.receive(5, TimeUnit.SECONDS); if (msg == null) { break; } @@ -424,7 +454,7 @@ public void testSimpleConsumerEventsWithPartition() throws Exception { // remove a consumer for (int i = 0; i < 10; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(5, TimeUnit.SECONDS); Assert.assertNotNull(msg); uniqueMessages.add(new String(msg.getData())); consumer1.acknowledge(msg); @@ -433,7 +463,7 @@ public void testSimpleConsumerEventsWithPartition() throws Exception { Thread.sleep(CONSUMER_ADD_OR_REMOVE_WAIT_TIME); consumer2Messages = 0; while (true) { - msg = consumer2.receive(1, TimeUnit.SECONDS); + msg = consumer2.receive(5, TimeUnit.SECONDS); if (msg == null) { break; } @@ -443,7 +473,7 @@ public void testSimpleConsumerEventsWithPartition() throws Exception { } consumer3Messages = 0; while (true) { - msg = consumer3.receive(1, TimeUnit.SECONDS); + msg = consumer3.receive(5, TimeUnit.SECONDS); if (msg == null) { break; } diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentQueueE2ETest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentQueueE2ETest.java index 495a9973b5322..dad3cc08f1094 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentQueueE2ETest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentQueueE2ETest.java @@ -29,6 +29,7 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -80,13 +81,22 @@ private void deleteTopic(String topicName) { } } + // Perhaps it would be better to import this method from PulsarTestBase in tests.integration + public static String randomName(int numChars) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < numChars; i++) { + sb.append((char) (ThreadLocalRandom.current().nextInt(26) + 'a')); + } + return sb.toString(); + } + @Test public void testSimpleConsumerEvents() throws Exception { - final String topicName = "persistent://prop/use/ns-abc/shared-topic1"; - final String subName = "sub1"; + final String topicName = "persistent://prop/use/ns-abc/shared-topic1" + randomName(16); + final String subName = "sub1" + randomName(16); final int numMsgs = 100; - // 1. two consumers on the same subscription + // 1. two consumers on the same subscription. Consumer consumer1 = pulsarClient.newConsumer().topic(topicName).subscriptionName(subName) .subscriptionType(SubscriptionType.Shared).subscribe(); @@ -118,14 +128,14 @@ public void testSimpleConsumerEvents() throws Exception { rolloverPerIntervalStats(); assertEquals(subRef.getNumberOfEntriesInBacklog(false), numMsgs * 2); - Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT); + Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT * 3); // both consumers will together consumer all messages Message msg; Consumer c = consumer1; while (true) { try { - msg = c.receive(1, TimeUnit.SECONDS); + msg = c.receive(5, TimeUnit.SECONDS); c.acknowledge(msg); } catch (PulsarClientException e) { if (c.equals(consumer1)) { @@ -154,7 +164,7 @@ public void testSimpleConsumerEvents() throws Exception { // 5. cumulative acks disabled consumer1.close(); producer.send("message".getBytes()); - msg = consumer2.receive(); + msg = consumer2.receive(5, TimeUnit.SECONDS); try { consumer2.acknowledgeCumulative(msg); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicE2ETest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicE2ETest.java index 42190c7a18024..80d387071d1fd 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicE2ETest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicE2ETest.java @@ -169,7 +169,7 @@ public void testSimpleConsumerEvents() throws Exception { Message msg = null; for (int i = 0; i < numMsgs; i++) { - msg = consumer.receive(); + msg = consumer.receive(5, TimeUnit.SECONDS); // 3. in-order message delivery assertEquals(new String(msg.getData()), "my-message-" + i); consumer.acknowledge(msg); @@ -182,7 +182,7 @@ public void testSimpleConsumerEvents() throws Exception { assertEquals(subRef.getNumberOfEntriesInBacklog(false), numMsgs); for (int i = 0; i < numMsgs; i++) { - msg = consumer.receive(); + msg = consumer.receive(5, TimeUnit.SECONDS); if (i == numMsgs - 1) { consumer.acknowledgeCumulative(msg); } @@ -245,7 +245,7 @@ public void testConsumerFlowControl() throws Exception { for (int i = 0; i < recvQueueSize / 2; i++) { String message = "my-message-" + i; producer.send(message.getBytes()); - msg = consumer.receive(); + msg = consumer.receive(5, TimeUnit.SECONDS); consumer.acknowledge(msg); } @@ -285,7 +285,7 @@ public void testActiveSubscriptionWithCache() throws Exception { for (int i = 0; i < recvQueueSize / 2; i++) { String message = "my-message-" + i; producer.send(message.getBytes()); - msg = consumer.receive(); + msg = consumer.receive(5, TimeUnit.SECONDS); consumer.acknowledge(msg); } @@ -340,7 +340,7 @@ public Void call() throws Exception { Consumer consumer = pulsarClient.newConsumer().topic(topicName).subscriptionName(subName) .receiverQueueSize(recvQueueSize).subscribe(); for (int i = 0; i < recvQueueSize / numConsumersThreads; i++) { - Message msg = consumer.receive(); + Message msg = consumer.receive(5, TimeUnit.SECONDS); consumer.acknowledge(msg); } return null; @@ -417,7 +417,7 @@ public void testGracefulClose() throws Exception { Message msg = null; for (int i = 0; i < 10; i++) { - msg = consumer.receive(); + msg = consumer.receive(5, TimeUnit.SECONDS); } // 2. verify consumer close fails when there are outstanding @@ -461,7 +461,7 @@ public void testSimpleCloseTopic() throws Exception { for (int i = 0; i < 10; i++) { String message = "my-message-" + i; producer.send(message.getBytes()); - msg = consumer.receive(); + msg = consumer.receive(5, TimeUnit.SECONDS); consumer.acknowledge(msg); } @@ -1012,7 +1012,7 @@ public void testReceiveWithTimeout() throws Exception { assertEquals(consumer.getAvailablePermits(), 0); - msg = consumer.receive(10, TimeUnit.MILLISECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); assertNotNull(msg); assertEquals(consumer.getAvailablePermits(), 1); @@ -1331,7 +1331,7 @@ public void testPayloadCorruptionDetection() throws Exception { } // We should only receive msg1 - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(5, TimeUnit.SECONDS); assertEquals(new String(msg.getData()), "message-1"); while ((msg = consumer.receive(1, TimeUnit.SECONDS)) != null) { @@ -1374,7 +1374,7 @@ public void testMessageRedelivery() throws Exception { // (2) Consume and only ack last 10 messages for (int i = 0; i < totalMessages; i++) { - msg = consumer.receive(); + msg = consumer.receive(5, TimeUnit.SECONDS); if (i >= 10) { unackedMessages.add(msg); } else { @@ -1387,7 +1387,7 @@ public void testMessageRedelivery() throws Exception { for (int i = 0; i < 10; i++) { // Verify: msg [L:0] must be redelivered try { - final Message redeliveredMsg = consumer.receive(1, TimeUnit.SECONDS); + final Message redeliveredMsg = consumer.receive(5, TimeUnit.SECONDS); unackedMessages.removeIf(unackedMessage -> unackedMessage.getValue().equals(redeliveredMsg.getValue())); } catch (Exception e) { fail("msg should be redelivered ", e); @@ -1397,7 +1397,7 @@ public void testMessageRedelivery() throws Exception { assertEquals(unackedMessages.size(), 0); // Verify no other messages are redelivered - msg = consumer.receive(100, TimeUnit.MILLISECONDS); + msg = consumer.receive(10, TimeUnit.MILLISECONDS); assertNull(msg); consumer.close(); @@ -1405,7 +1405,7 @@ public void testMessageRedelivery() throws Exception { } /** - * Verify: 1. Broker should not replay already acknowledged messages 2. Dispatcher should not stuck while + * Verify: 1. Broker should not replay already acknowledged messages 2. Dispatcher should not get stuck while * dispatching new messages due to previous-replay of invalid/already-acked messages * * @throws Exception @@ -1448,7 +1448,7 @@ public void testMessageReplay() throws Exception { MessageIdImpl firstAckedMsg = null; // (2) Consume and ack messages except first message for (int i = 0; i < totalMessages; i++) { - msg = consumer.receive(); + msg = consumer.receive(5, TimeUnit.SECONDS); consumer.acknowledge(msg); MessageIdImpl msgId = (MessageIdImpl) msg.getMessageId(); if (i == 0) { @@ -1476,7 +1476,7 @@ public void testMessageReplay() throws Exception { producer.send(testMsg.getBytes()); // consumer should be able to receive only new message and not the dispatcher.consumerFlow(dispatcher.getConsumers().get(0), 1); - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); assertNotNull(msg); assertEquals(msg.getData(), testMsg.getBytes()); @@ -1543,7 +1543,7 @@ public void testWithEventTime() throws Exception { Producer producer = pulsarClient.newProducer(Schema.STRING).topic(topicName).create(); producer.newMessage().value("test").eventTime(5).send(); - Message msg = consumer.receive(); + Message msg = consumer.receive(5, TimeUnit.SECONDS); assertNotNull(msg); assertEquals(msg.getValue(), "test"); assertEquals(msg.getEventTime(), 5); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTest.java index 95edfe27c3209..e3da62d8c8b27 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTest.java @@ -35,13 +35,7 @@ import java.util.List; import java.util.SortedSet; import java.util.TreeSet; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import lombok.Cleanup; @@ -96,13 +90,13 @@ public void beforeMethod(Method m) throws Exception { } @Override - @BeforeClass(timeOut = 300000) + @BeforeClass(timeOut = 900000) void setup() throws Exception { super.setup(); } @Override - @AfterClass(timeOut = 300000) + @AfterClass(timeOut = 900000) void shutdown() throws Exception { super.shutdown(); } @@ -195,7 +189,7 @@ public Void call() throws Exception { } @SuppressWarnings("unchecked") - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testConcurrentReplicator() throws Exception { log.info("--- Starting ReplicatorTest::testConcurrentReplicator ---"); @@ -409,7 +403,7 @@ public void testFailures() throws Exception { } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testReplicatePeekAndSkip() throws Exception { final TopicName dest = TopicName.get("persistent://pulsar/ns/peekAndSeekTopic"); @@ -431,7 +425,7 @@ public void testReplicatePeekAndSkip() throws Exception { assertNull(entry); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testReplicatorClearBacklog() throws Exception { // This test is to verify that reset cursor fails on global topic @@ -541,7 +535,7 @@ public void testReplicationForBatchMessages() throws Exception { * * @throws Exception */ - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testDeleteReplicatorFailure() throws Exception { log.info("--- Starting ReplicatorTest::testDeleteReplicatorFailure ---"); final String topicName = "persistent://pulsar/ns/repltopicbatch"; @@ -681,7 +675,7 @@ public void testResumptionAfterBacklogRelaxed() throws Exception { * * @throws Exception */ - @Test(timeOut = 15000) + @Test(timeOut = 55000) public void testCloseReplicatorStartProducer() throws Exception { TopicName dest = TopicName.get("persistent://pulsar/ns1/closeCursor"); // Producer on r1 @@ -727,7 +721,7 @@ public void testCloseReplicatorStartProducer() throws Exception { assertNull(replicatorProducer); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void verifyChecksumAfterReplication() throws Exception { final String topicName = "persistent://pulsar/ns/checksumAfterReplication"; @@ -767,7 +761,7 @@ public void testReplicatorOnPartitionedTopic(boolean isPartitionedTopic) throws log.info("--- Starting ReplicatorTest::{} --- ", methodName); - final String namespace = "pulsar/partitionedNs-" + isPartitionedTopic; + final String namespace = "pulsar/partitionedNs-" + isPartitionedTopic + randomName(16); final String persistentTopicName = "persistent://" + namespace + "/partTopic-" + isPartitionedTopic; final String nonPersistentTopicName = "non-persistent://" + namespace + "/partTopic-" + isPartitionedTopic; BrokerService brokerService = pulsar1.getBrokerService(); @@ -815,12 +809,21 @@ public void testReplicatorOnPartitionedTopic(boolean isPartitionedTopic) throws } + // Perhaps it would be better to import this method from PulsarTestBase in tests.integration + public static String randomName(int numChars) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < numChars; i++) { + sb.append((char) (ThreadLocalRandom.current().nextInt(26) + 'a')); + } + return sb.toString(); + } + @Test public void testReplicatedCluster() throws Exception { log.info("--- Starting ReplicatorTest::testReplicatedCluster ---"); - final String namespace = "pulsar/global/repl"; + final String namespace = "pulsar/global/repl" + randomName(16); final String topicName = String.format("persistent://%s/topic1", namespace); admin1.namespaces().createNamespace(namespace); admin1.namespaces().setNamespaceReplicationClusters(namespace, Sets.newHashSet("r1", "r2", "r3")); @@ -839,9 +842,9 @@ public void testReplicatedCluster() throws Exception { // publish message local only TypedMessageBuilder msg = producer1.newMessage().replicationClusters(Lists.newArrayList("r1")).value(value); msg.send(); - assertEquals(consumer1.receive().getValue(), value); + assertEquals(consumer1.receive(5, TimeUnit.SECONDS).getValue(), value); - Message msg2 = consumer2.receive(1, TimeUnit.SECONDS); + Message msg2 = consumer2.receive(5, TimeUnit.SECONDS); if (msg2 != null) { fail("msg should have not been replicated to remote cluster"); } @@ -857,7 +860,7 @@ public void testReplicatedCluster() throws Exception { *
      *  1. Create global topic with 4 partitions
      *  2. Update partition with 8 partitions
-     *  3. Create producer on the partition topic which loads all new partitions
+     *  3. Create producer on the partition topic which loads all new partitions.
      *  4. Check subscriptions are created on all new partitions.
      * 
* @throws Exception @@ -868,7 +871,7 @@ public void testUpdateGlobalTopicPartition() throws Exception { final String cluster1 = pulsar1.getConfig().getClusterName(); final String cluster2 = pulsar2.getConfig().getClusterName(); - final String namespace = "pulsar/global/ns3"; + final String namespace = "pulsar/global/ns3" + randomName(16); final String topicName = "persistent://" + namespace + "/topic1"; int startPartitions = 4; int newPartitions = 8; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTlsTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTlsTest.java index 3ad22e9a134fb..5cf88275a3a38 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTlsTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTlsTest.java @@ -33,7 +33,7 @@ public class ReplicatorTlsTest extends ReplicatorTestBase { @Override - @BeforeClass(timeOut = 300000) + @BeforeClass(timeOut = 900000) void setup() throws Exception { config1.setBrokerClientTlsEnabled(true); config2.setBrokerClientTlsEnabled(true); @@ -42,7 +42,7 @@ void setup() throws Exception { } @Override - @AfterClass(timeOut = 300000) + @AfterClass(timeOut = 900000) void shutdown() throws Exception { super.shutdown(); } diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java index ba4cf5bee2815..8aa7163493309 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java @@ -212,7 +212,7 @@ public void teardown() throws Exception { executor.shutdownNow(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testConnectCommand() throws Exception { resetChannel(); assertTrue(channel.isActive()); @@ -245,7 +245,7 @@ private static ByteBuf newConnect(AuthMethod authMethod, String authData, int pr * * @throws Exception */ - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testConnectCommandWithEnum() throws Exception { resetChannel(); assertTrue(channel.isActive()); @@ -260,7 +260,7 @@ public void testConnectCommandWithEnum() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testConnectCommandWithProtocolVersion() throws Exception { resetChannel(); assertTrue(channel.isActive()); @@ -276,7 +276,7 @@ public void testConnectCommandWithProtocolVersion() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testKeepAlive() throws Exception { resetChannel(); assertTrue(channel.isActive()); @@ -301,7 +301,7 @@ public void testKeepAlive() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testKeepAliveNotEnforcedWithOlderClients() throws Exception { resetChannel(); assertTrue(channel.isActive()); @@ -326,7 +326,7 @@ public void testKeepAliveNotEnforcedWithOlderClients() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testKeepAliveBeforeHandshake() throws Exception { resetChannel(); assertTrue(channel.isActive()); @@ -345,7 +345,7 @@ public void testKeepAliveBeforeHandshake() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testConnectCommandWithAuthenticationPositive() throws Exception { AuthenticationService authenticationService = mock(AuthenticationService.class); AuthenticationProvider authenticationProvider = mock(AuthenticationProvider.class); @@ -380,7 +380,7 @@ public void testConnectCommandWithAuthenticationPositive() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testConnectCommandWithAuthenticationNegative() throws Exception { AuthenticationService authenticationService = mock(AuthenticationService.class); doReturn(authenticationService).when(brokerService).getAuthenticationService(); @@ -400,7 +400,7 @@ public void testConnectCommandWithAuthenticationNegative() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testProducerCommand() throws Exception { resetChannel(); setChannelConnected(); @@ -428,7 +428,7 @@ public void testProducerCommand() throws Exception { assertEquals(topicRef.getProducers().size(), 0); } - @Test(timeOut = 5000) + @Test(timeOut = 50000) public void testDuplicateConcurrentProducerCommand() throws Exception { resetChannel(); setChannelConnected(); @@ -451,7 +451,7 @@ public void testDuplicateConcurrentProducerCommand() throws Exception { assertEquals(error.getError(), ServerError.ServiceNotReady); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testProducerOnNotOwnedTopic() throws Exception { resetChannel(); setChannelConnected(); @@ -475,7 +475,7 @@ public void testProducerOnNotOwnedTopic() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testProducerCommandWithAuthorizationPositive() throws Exception { AuthorizationService authorizationService = mock(AuthorizationService.class); doReturn(CompletableFuture.completedFuture(true)).when(authorizationService).canProduceAsync(Mockito.any(), @@ -500,7 +500,7 @@ public void testProducerCommandWithAuthorizationPositive() throws Exception { assertEquals(topicRef.getProducers().size(), 0); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testNonExistentTopic() throws Exception { ZooKeeperDataCache zkDataCache = mock(ZooKeeperDataCache.class); ConfigurationCacheService configCacheService = mock(ConfigurationCacheService.class); @@ -536,7 +536,7 @@ public void testNonExistentTopic() throws Exception { assertTrue(getResponse() instanceof CommandError); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testClusterAccess() throws Exception { svcConfig.setAuthorizationEnabled(true); AuthorizationService authorizationService = spy(new AuthorizationService(svcConfig, configCacheService)); @@ -565,7 +565,7 @@ public void testClusterAccess() throws Exception { assertTrue(getResponse() instanceof CommandError); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testNonExistentTopicSuperUserAccess() throws Exception { AuthorizationService authorizationService = spy(new AuthorizationService(svcConfig, configCacheService)); doReturn(authorizationService).when(brokerService).getAuthorizationService(); @@ -622,7 +622,7 @@ public void testProducerCommandWithAuthorizationNegative() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testSendCommand() throws Exception { resetChannel(); setChannelConnected(); @@ -645,7 +645,7 @@ public void testSendCommand() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testUseSameProducerName() throws Exception { resetChannel(); setChannelConnected(); @@ -665,7 +665,7 @@ public void testUseSameProducerName() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testRecreateSameProducer() throws Exception { resetChannel(); setChannelConnected(); @@ -699,7 +699,7 @@ public void testRecreateSameProducer() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testSubscribeMultipleTimes() throws Exception { resetChannel(); setChannelConnected(); @@ -756,7 +756,7 @@ public void testDuplicateConcurrentSubscribeCommand() throws Exception { assertEquals(error.getError(), ServerError.ServiceNotReady); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testCreateProducerTimeout() throws Exception { resetChannel(); setChannelConnected(); @@ -891,7 +891,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable { channel.finish(); } - @Test(timeOut = 30000, invocationCount = 1, skipFailedInvocations = true) + @Test(timeOut = 90000, invocationCount = 1, skipFailedInvocations = true) public void testCreateProducerBookieTimeout() throws Exception { resetChannel(); setChannelConnected(); @@ -961,7 +961,7 @@ public void testCreateProducerBookieTimeout() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testSubscribeTimeout() throws Exception { resetChannel(); setChannelConnected(); @@ -1035,7 +1035,7 @@ public void testSubscribeTimeout() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testSubscribeBookieTimeout() throws Exception { resetChannel(); setChannelConnected(); @@ -1120,7 +1120,7 @@ public void testSubscribeBookieTimeout() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testSubscribeCommand() throws Exception { final String failSubName = "failSub"; @@ -1159,7 +1159,7 @@ public void testSubscribeCommand() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testUnsupportedBatchMsgSubscribeCommand() throws Exception { final String failSubName = "failSub"; @@ -1192,7 +1192,7 @@ public void testUnsupportedBatchMsgSubscribeCommand() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testSubscribeCommandWithAuthorizationPositive() throws Exception { AuthorizationService authorizationService = mock(AuthorizationService.class); doReturn(CompletableFuture.completedFuture(true)).when(authorizationService).canConsumeAsync(Mockito.any(), @@ -1214,7 +1214,7 @@ public void testSubscribeCommandWithAuthorizationPositive() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testSubscribeCommandWithAuthorizationNegative() throws Exception { AuthorizationService authorizationService = mock(AuthorizationService.class); doReturn(CompletableFuture.completedFuture(false)).when(authorizationService).canConsumeAsync(Mockito.any(), @@ -1235,7 +1235,7 @@ public void testSubscribeCommandWithAuthorizationNegative() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testAckCommand() throws Exception { resetChannel(); setChannelConnected(); @@ -1258,7 +1258,7 @@ public void testAckCommand() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testFlowCommand() throws Exception { resetChannel(); setChannelConnected(); @@ -1278,7 +1278,7 @@ public void testFlowCommand() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testProducerSuccessOnEncryptionRequiredTopic() throws Exception { resetChannel(); setChannelConnected(); @@ -1306,7 +1306,7 @@ public void testProducerSuccessOnEncryptionRequiredTopic() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testProducerFailureOnEncryptionRequiredTopic() throws Exception { resetChannel(); setChannelConnected(); @@ -1336,7 +1336,7 @@ public void testProducerFailureOnEncryptionRequiredTopic() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testSendSuccessOnEncryptionRequiredTopic() throws Exception { resetChannel(); setChannelConnected(); @@ -1371,7 +1371,7 @@ public void testSendSuccessOnEncryptionRequiredTopic() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testSendFailureOnEncryptionRequiredTopic() throws Exception { resetChannel(); setChannelConnected(); @@ -1552,7 +1552,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable { doReturn(successSubName).when(cursorMock).getName(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testInvalidTopicOnLookup() throws Exception { resetChannel(); setChannelConnected(); @@ -1572,7 +1572,7 @@ public void testInvalidTopicOnLookup() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testInvalidTopicOnProducer() throws Exception { resetChannel(); setChannelConnected(); @@ -1593,7 +1593,7 @@ public void testInvalidTopicOnProducer() throws Exception { channel.finish(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testInvalidTopicOnSubscribe() throws Exception { resetChannel(); setChannelConnected(); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/DelayedDeliveryTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/DelayedDeliveryTest.java index 3cd2e255e7920..4440f1b98a3b3 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/DelayedDeliveryTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/DelayedDeliveryTest.java @@ -88,7 +88,7 @@ public void testDelayedDelivery() // Failover consumer will receive the messages immediately while // the shared consumer will get them after the delay - Message msg = sharedConsumer.receive(100, TimeUnit.MILLISECONDS); + Message msg = sharedConsumer.receive(10, TimeUnit.MILLISECONDS); assertNull(msg); for (int i = 0; i < 10; i++) { @@ -194,7 +194,7 @@ public void testEverythingFilteredInMultipleReads() .send(); } - Message msg = sharedConsumer.receive(100, TimeUnit.MILLISECONDS); + Message msg = sharedConsumer.receive(10, TimeUnit.MILLISECONDS); assertNull(msg); Set receivedMsgs = new TreeSet<>(); @@ -256,7 +256,7 @@ public void testDelayedDeliveryWithMultipleConcurrentReadEntries() producer.flush(); - Message msg = consumer.receive(100, TimeUnit.MILLISECONDS); + Message msg = consumer.receive(10, TimeUnit.MILLISECONDS); assertNull(msg); Set receivedMsgs = new TreeSet<>(); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/PartitionedTopicsSchemaTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/PartitionedTopicsSchemaTest.java index 93e41dd11e7af..69173071b902e 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/PartitionedTopicsSchemaTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/PartitionedTopicsSchemaTest.java @@ -25,6 +25,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; import org.apache.pulsar.broker.service.BkEnsemblesTestBase; import org.apache.pulsar.client.api.Consumer; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/ManagedLedgerMetricsTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/ManagedLedgerMetricsTest.java index f74f192385210..d67512f6abd92 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/ManagedLedgerMetricsTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/ManagedLedgerMetricsTest.java @@ -34,8 +34,6 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -/** - */ public class ManagedLedgerMetricsTest extends BrokerTestBase { @BeforeClass diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java index e569cafdf5044..ca13acdb78151 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java @@ -29,8 +29,10 @@ import java.util.Map; import java.util.HashMap; import java.util.TreeMap; +import java.util.concurrent.ThreadLocalRandom; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import org.apache.pulsar.broker.service.BrokerTestBase; import org.apache.pulsar.broker.stats.prometheus.PrometheusMetricsGenerator; @@ -57,10 +59,21 @@ protected void cleanup() throws Exception { super.internalCleanup(); } + // Perhaps it would be better to import this method from PulsarTestBase in tests.integration + public static String randomName(int numChars) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < numChars; i++) { + sb.append((char) (ThreadLocalRandom.current().nextInt(26) + 'a')); + } + return sb.toString(); + } + @Test public void testPerTopicStats() throws Exception { - Producer p1 = pulsarClient.newProducer().topic("persistent://my-property/use/my-ns/my-topic1").create(); - Producer p2 = pulsarClient.newProducer().topic("persistent://my-property/use/my-ns/my-topic2").create(); + String randSeed = randomName(16); + System.out.println("The randSeed of testPerTopicStats() is: " + randSeed); + Producer p1 = pulsarClient.newProducer().topic("persistent://my-property/use/" + randSeed + "/my-topic1").create(); + Producer p2 = pulsarClient.newProducer().topic("persistent://my-property/use/" + randSeed + "/my-topic2").create(); for (int i = 0; i < 10; i++) { String message = "my-message-" + i; p1.send(message.getBytes()); @@ -78,36 +91,95 @@ public void testPerTopicStats() throws Exception { // There should be 2 metrics with different tags for each topic List cm = (List) metrics.get("pulsar_storage_write_latency_le_1"); - assertEquals(cm.size(), 2); - assertEquals(cm.get(0).tags.get("topic"), "persistent://my-property/use/my-ns/my-topic2"); - assertEquals(cm.get(0).tags.get("namespace"), "my-property/use/my-ns"); - assertEquals(cm.get(1).tags.get("topic"), "persistent://my-property/use/my-ns/my-topic1"); - assertEquals(cm.get(1).tags.get("namespace"), "my-property/use/my-ns"); + List matchingMetrics = cm.stream().filter(t -> t.tags.containsValue("my-property/use/" + randSeed)).collect(Collectors.toList()); + // I think there's a race that's causing cm.get(0) and cm.get(1) to swap items... + int positionOfTopic1; + int positionOfTopic2; + + matchingMetrics = cm.stream().filter(t -> t.tags.containsValue("my-property/use/" + randSeed)).collect(Collectors.toList()); + if(matchingMetrics.size() > 2){ + System.out.println("matchingMetrics.size() > 2 in testPerTopicStats(). First check. Debug entries: "); + matchingMetrics.forEach(t -> t.tags.entrySet().forEach(kv -> System.out.println(kv.getKey() + ":" + kv.getValue()))); + } + if(matchingMetrics.get(0).tags.get("topic").equals("persistent://my-property/use/" + randSeed + "/my-topic1")) { + positionOfTopic1 = 0; + positionOfTopic2 = 1; + } else { + positionOfTopic2 = 0; + positionOfTopic1 = 1; + } + assertEquals(matchingMetrics.size(), 2); + assertEquals(matchingMetrics.get(positionOfTopic2).tags.get("topic"), "persistent://my-property/use/" + randSeed + "/my-topic2"); + assertEquals(matchingMetrics.get(positionOfTopic2).tags.get("namespace"), "my-property/use/" + randSeed); + assertEquals(matchingMetrics.get(positionOfTopic1).tags.get("topic"), "persistent://my-property/use/" + randSeed + "/my-topic1"); + assertEquals(matchingMetrics.get(positionOfTopic1).tags.get("namespace"), "my-property/use/" + randSeed); cm = (List) metrics.get("pulsar_producers_count"); - assertEquals(cm.size(), 3); - assertEquals(cm.get(1).tags.get("topic"), "persistent://my-property/use/my-ns/my-topic2"); - assertEquals(cm.get(1).tags.get("namespace"), "my-property/use/my-ns"); - assertEquals(cm.get(2).tags.get("topic"), "persistent://my-property/use/my-ns/my-topic1"); - assertEquals(cm.get(2).tags.get("namespace"), "my-property/use/my-ns"); + + matchingMetrics = cm.stream().filter(t -> t.tags.containsValue("my-property/use/" + randSeed)).collect(Collectors.toList()); + if(matchingMetrics.size() > 2){ + System.out.println("matchingMetrics.size() > 2 in testPerTopicStats(). Second check. Debug entries: "); + matchingMetrics.forEach(t -> t.tags.entrySet().forEach(kv -> System.out.println(kv.getKey() + ":" + kv.getValue()))); + } + if(matchingMetrics.get(1).tags.get("topic").equals("persistent://my-property/use/" + randSeed + "/my-topic1")) { + positionOfTopic1 = 1; + positionOfTopic2 = 0; + } else { + positionOfTopic2 = 1; + positionOfTopic1 = 0; + } + assertEquals(matchingMetrics.size(), 2); + assertEquals(matchingMetrics.get(positionOfTopic2).tags.get("topic"), "persistent://my-property/use/" + randSeed + "/my-topic2"); + assertEquals(matchingMetrics.get(positionOfTopic2).tags.get("namespace"), "my-property/use/" + randSeed); + assertEquals(matchingMetrics.get(positionOfTopic1).tags.get("topic"), "persistent://my-property/use/" + randSeed + "/my-topic1"); + assertEquals(matchingMetrics.get(positionOfTopic1).tags.get("namespace"), "my-property/use/" + randSeed); cm = (List) metrics.get("topic_load_times_count"); + //matchingMetrics = cm.stream().filter(t -> t.tags.containsValue("my-property/use/" + randSeed)).collect(Collectors.toList()); + if(cm.size() > 1){ // This one doesn't have the entire topic name... Hopefully, that won't cause concurrency problems. + System.out.println("matchingMetrics.size() > 2 in testPerTopicStats(). Third check. Debug entries: "); + cm.forEach(t -> t.tags.entrySet().forEach(kv -> System.out.println(kv.getKey() + ":" + kv.getValue()))); + } assertEquals(cm.size(), 1); assertEquals(cm.get(0).tags.get("cluster"), "test"); cm = (List) metrics.get("pulsar_in_bytes_total"); - assertEquals(cm.size(), 2); - assertEquals(cm.get(0).tags.get("topic"), "persistent://my-property/use/my-ns/my-topic2"); - assertEquals(cm.get(0).tags.get("namespace"), "my-property/use/my-ns"); - assertEquals(cm.get(1).tags.get("topic"), "persistent://my-property/use/my-ns/my-topic1"); - assertEquals(cm.get(1).tags.get("namespace"), "my-property/use/my-ns"); + matchingMetrics = cm.stream().filter(t -> t.tags.containsValue("my-property/use/" + randSeed)).collect(Collectors.toList()); + if(matchingMetrics.size() > 2){ + System.out.println("matchingMetrics.size() > 2 in testPerTopicStats(). Fourth check. Debug entries: "); + matchingMetrics.forEach(t -> t.tags.entrySet().forEach(kv -> System.out.println(kv.getKey() + ":" + kv.getValue()))); + } + if(matchingMetrics.get(0).tags.get("topic").equals("persistent://my-property/use/" + randSeed + "/my-topic1")) { + positionOfTopic1 = 0; + positionOfTopic2 = 1; + } else { + positionOfTopic2 = 0; + positionOfTopic1 = 1; + } + assertEquals(matchingMetrics.size(), 2); + assertEquals(matchingMetrics.get(positionOfTopic2).tags.get("topic"), "persistent://my-property/use/" + randSeed + "/my-topic2"); + assertEquals(matchingMetrics.get(positionOfTopic2).tags.get("namespace"), "my-property/use/" + randSeed); + assertEquals(matchingMetrics.get(positionOfTopic1).tags.get("topic"), "persistent://my-property/use/" + randSeed + "/my-topic1"); + assertEquals(matchingMetrics.get(positionOfTopic1).tags.get("namespace"), "my-property/use/" + randSeed); cm = (List) metrics.get("pulsar_in_messages_total"); - assertEquals(cm.size(), 2); - assertEquals(cm.get(0).tags.get("topic"), "persistent://my-property/use/my-ns/my-topic2"); - assertEquals(cm.get(0).tags.get("namespace"), "my-property/use/my-ns"); - assertEquals(cm.get(1).tags.get("topic"), "persistent://my-property/use/my-ns/my-topic1"); - assertEquals(cm.get(1).tags.get("namespace"), "my-property/use/my-ns"); + matchingMetrics = cm.stream().filter(t -> t.tags.containsValue("my-property/use/" + randSeed)).collect(Collectors.toList()); + if(matchingMetrics.size() > 2){ + System.out.println("matchingMetrics.size() > 2 in testPerTopicStats(). Fifth check. Debug entries: "); + matchingMetrics.forEach(t -> t.tags.entrySet().forEach(kv -> System.out.println(kv.getKey() + ":" + kv.getValue()))); + } + if(matchingMetrics.get(0).tags.get("topic").equals("persistent://my-property/use/" + randSeed + "/my-topic1")) { + positionOfTopic1 = 0; + positionOfTopic2 = 1; + } else { + positionOfTopic2 = 0; + positionOfTopic1 = 1; + } + assertEquals(matchingMetrics.size(), 2); + assertEquals(matchingMetrics.get(positionOfTopic2).tags.get("topic"), "persistent://my-property/use/" + randSeed + "/my-topic2"); + assertEquals(matchingMetrics.get(positionOfTopic2).tags.get("namespace"), "my-property/use/" + randSeed); + assertEquals(matchingMetrics.get(positionOfTopic1).tags.get("topic"), "persistent://my-property/use/" + randSeed + "/my-topic1"); + assertEquals(matchingMetrics.get(positionOfTopic1).tags.get("namespace"), "my-property/use/" + randSeed); p1.close(); p2.close(); @@ -115,8 +187,10 @@ public void testPerTopicStats() throws Exception { @Test public void testPerNamespaceStats() throws Exception { - Producer p1 = pulsarClient.newProducer().topic("persistent://my-property/use/my-ns/my-topic1").create(); - Producer p2 = pulsarClient.newProducer().topic("persistent://my-property/use/my-ns/my-topic2").create(); + String randSeed = randomName(16); + System.out.println("The randSeed of testPerNamespaceStats() is: " + randSeed); + Producer p1 = pulsarClient.newProducer().topic("persistent://my-property/use/" + randSeed + "/my-topic1").create(); + Producer p2 = pulsarClient.newProducer().topic("persistent://my-property/use/" + randSeed + "/my-topic2").create(); for (int i = 0; i < 10; i++) { String message = "my-message-" + i; p1.send(message.getBytes()); @@ -135,15 +209,29 @@ public void testPerNamespaceStats() throws Exception { // There should be 1 metric aggregated per namespace List cm = (List) metrics.get("pulsar_storage_write_latency_le_1"); - assertEquals(cm.size(), 1); - assertNull(cm.get(0).tags.get("topic")); - assertEquals(cm.get(0).tags.get("namespace"), "my-property/use/my-ns"); + // Need to filter out Prometheus metrics like the way we're doing it in the Go Functions API... + // Maybe there's a workaround for now. + List matchingMetrics = cm.stream().filter(t -> t.tags.containsValue("my-property/use/" + randSeed)).collect(Collectors.toList()); + if(matchingMetrics.size() > 1){ + System.out.println("matchingMetrics.size() > 1 in testPerNamespaceStats(). First check. Debug entries: "); + matchingMetrics.forEach(t -> t.tags.entrySet().forEach(kv -> System.out.println(kv.getKey() + ":" + kv.getValue()))); + } + assertEquals(matchingMetrics.size(), 1); + assertNull(matchingMetrics.get(0).tags.get("topic"), "Test"); + assertEquals(matchingMetrics.get(0).tags.get("namespace"), "my-property/use/" + randSeed); + // Need to filter out Prometheus metrics like the way we're doing it in the Go Functions API... + // Maybe there's a workaround for now. cm = (List) metrics.get("pulsar_producers_count"); - assertEquals(cm.size(), 2); - assertEquals(cm.get(1).value, 2.0); - assertNull(cm.get(1).tags.get("topic")); - assertEquals(cm.get(1).tags.get("namespace"), "my-property/use/my-ns"); + matchingMetrics = cm.stream().filter(t -> t.tags.containsValue("my-property/use/" + randSeed)).collect(Collectors.toList()); + if(matchingMetrics.size() > 1){ + System.out.println("matchingMetrics.size() > 1 in testPerNamespaceStats(). Second check. Debug entries: "); + matchingMetrics.forEach(t -> t.tags.entrySet().forEach(kv -> System.out.println(kv.getKey() + ":" + kv.getValue()))); + } + assertEquals(matchingMetrics.size(), 1); + assertEquals(matchingMetrics.get(0).value, 2.0); + assertNull(matchingMetrics.get(0).tags.get("topic")); + assertEquals(matchingMetrics.get(0).tags.get("namespace"), "my-property/use/" + randSeed); p1.close(); p2.close(); @@ -264,6 +352,10 @@ private static Multimap parseMetrics(String metrics) { } Matcher matcher = pattern.matcher(line); + if(!matcher.matches()){ + System.out.println("Failing line is: " + line); + System.out.println("Failing pattern is: " + pattern.toString()); + } assertTrue(matcher.matches()); String name = matcher.group(1); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ClientDeduplicationTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ClientDeduplicationTest.java index 09bfb79ccdcd1..98adeada995e5 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ClientDeduplicationTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ClientDeduplicationTest.java @@ -24,6 +24,7 @@ import static org.testng.Assert.fail; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import org.testng.annotations.AfterClass; @@ -46,11 +47,11 @@ protected void cleanup() throws Exception { @Test public void testProducerSequenceAfterReconnect() throws Exception { - String topic = "persistent://my-property/my-ns/testProducerSequenceAfterReconnect"; + String topic = "persistent://my-property/my-ns/testProducerSequenceAfterReconnect"+ randomName(16); admin.namespaces().setDeduplicationStatus("my-property/my-ns", true); ProducerBuilder producerBuilder = pulsarClient.newProducer().topic(topic) - .producerName("my-producer-name"); + .producerName("my-producer-name"+ randomName(16)); Producer producer = producerBuilder.create(); assertEquals(producer.getLastSequenceId(), -1L); @@ -77,11 +78,11 @@ public void testProducerSequenceAfterReconnect() throws Exception { @Test public void testProducerSequenceAfterRestart() throws Exception { - String topic = "persistent://my-property/my-ns/testProducerSequenceAfterRestart"; + String topic = "persistent://my-property/my-ns/testProducerSequenceAfterRestart"+ randomName(16); admin.namespaces().setDeduplicationStatus("my-property/my-ns", true); ProducerBuilder producerBuilder = pulsarClient.newProducer().topic(topic) - .producerName("my-producer-name"); + .producerName("my-producer-name"+ randomName(16)); Producer producer = producerBuilder.create(); assertEquals(producer.getLastSequenceId(), -1L); @@ -109,19 +110,19 @@ public void testProducerSequenceAfterRestart() throws Exception { producer.close(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testProducerDeduplication() throws Exception { - String topic = "persistent://my-property/my-ns/testProducerDeduplication"; + String topic = "persistent://my-property/my-ns/testProducerDeduplication"+ randomName(16); admin.namespaces().setDeduplicationStatus("my-property/my-ns", true); // Set infinite timeout ProducerBuilder producerBuilder = pulsarClient.newProducer().topic(topic) - .producerName("my-producer-name").sendTimeout(0, TimeUnit.SECONDS); + .producerName("my-producer-name" + randomName(16)).sendTimeout(0, TimeUnit.SECONDS); Producer producer = producerBuilder.create(); assertEquals(producer.getLastSequenceId(), -1L); - Consumer consumer = pulsarClient.newConsumer().topic(topic).subscriptionName("my-subscription") + Consumer consumer = pulsarClient.newConsumer().topic(topic).subscriptionName("my-subscription"+ randomName(16)) .subscribe(); producer.newMessage().value("my-message-0".getBytes()).sequenceId(0).send(); @@ -141,7 +142,7 @@ public void testProducerDeduplication() throws Exception { } // No other messages should be received - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(10, TimeUnit.MILLISECONDS); assertNull(msg); // Kill and restart broker @@ -154,25 +155,32 @@ public void testProducerDeduplication() throws Exception { producer.newMessage().value("my-message-1".getBytes()).sequenceId(1).send(); producer.newMessage().value("my-message-2".getBytes()).sequenceId(2).send(); - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(10, TimeUnit.MILLISECONDS); assertNull(msg); producer.close(); } + public static String randomName(int numChars) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < numChars; i++) { + sb.append((char) (ThreadLocalRandom.current().nextInt(26) + 'a')); + } + return sb.toString(); + } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testProducerDeduplicationWithDiscontinuousSequenceId() throws Exception { - String topic = "persistent://my-property/my-ns/testProducerDeduplicationWithDiscontinuousSequenceId"; + String topic = "persistent://my-property/my-ns/testProducerDeduplicationWithDiscontinuousSequenceId"+ randomName(16); admin.namespaces().setDeduplicationStatus("my-property/my-ns", true); // Set infinite timeout ProducerBuilder producerBuilder = pulsarClient.newProducer().topic(topic) - .producerName("my-producer-name").enableBatching(true).batchingMaxMessages(10).sendTimeout(0, TimeUnit.SECONDS); + .producerName("my-producer-name" + randomName(16)).enableBatching(true).batchingMaxMessages(10).sendTimeout(0, TimeUnit.SECONDS); Producer producer = producerBuilder.create(); assertEquals(producer.getLastSequenceId(), -1L); - Consumer consumer = pulsarClient.newConsumer().topic(topic).subscriptionName("my-subscription") + Consumer consumer = pulsarClient.newConsumer().topic(topic).subscriptionName("my-subscription" + randomName(16)) .subscribe(); producer.newMessage().value("my-message-0".getBytes()).sequenceId(2).sendAsync(); @@ -194,7 +202,7 @@ public void testProducerDeduplicationWithDiscontinuousSequenceId() throws Except } // No other messages should be received - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(10, TimeUnit.MILLISECONDS); assertNull(msg); producer.close(); @@ -209,25 +217,25 @@ public void testProducerDeduplicationWithDiscontinuousSequenceId() throws Except producer.newMessage().value("my-message-2".getBytes()).sequenceId(4).sendAsync(); producer.flush(); - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(100, TimeUnit.MILLISECONDS); assertNull(msg); producer.close(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testProducerDeduplicationNonBatchAsync() throws Exception { - String topic = "persistent://my-property/my-ns/testProducerDeduplicationNonBatchAsync"; + String topic = "persistent://my-property/my-ns/testProducerDeduplicationNonBatchAsync"+ randomName(16); admin.namespaces().setDeduplicationStatus("my-property/my-ns", true); // Set infinite timeout ProducerBuilder producerBuilder = pulsarClient.newProducer().topic(topic) - .producerName("my-producer-name").enableBatching(false).sendTimeout(0, TimeUnit.SECONDS); + .producerName("my-producer-name" + randomName(16)).enableBatching(false).sendTimeout(0, TimeUnit.SECONDS); Producer producer = producerBuilder.create(); assertEquals(producer.getLastSequenceId(), -1L); - Consumer consumer = pulsarClient.newConsumer().topic(topic).subscriptionName("my-subscription") + Consumer consumer = pulsarClient.newConsumer().topic(topic).subscriptionName("my-subscription"+ randomName(16)) .subscribe(); producer.newMessage().value("my-message-0".getBytes()).sequenceId(2).sendAsync(); @@ -246,7 +254,7 @@ public void testProducerDeduplicationNonBatchAsync() throws Exception { } // No other messages should be received - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(10, TimeUnit.MILLISECONDS); assertNull(msg); // Kill and restart broker @@ -259,7 +267,7 @@ public void testProducerDeduplicationNonBatchAsync() throws Exception { producer.newMessage().value("my-message-1".getBytes()).sequenceId(2).sendAsync(); producer.newMessage().value("my-message-2".getBytes()).sequenceId(4).sendAsync(); - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(10, TimeUnit.MILLISECONDS); assertNull(msg); producer.close(); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/DeadLetterTopicTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/DeadLetterTopicTest.java index b1f1ddd6fd849..c069e4c340902 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/DeadLetterTopicTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/DeadLetterTopicTest.java @@ -106,7 +106,7 @@ public void testDeadLetterTopic() throws Exception { .subscriptionInitialPosition(SubscriptionInitialPosition.Earliest) .subscribe(); - Message checkMessage = checkConsumer.receive(3, TimeUnit.SECONDS); + Message checkMessage = checkConsumer.receive(10, TimeUnit.MILLISECONDS); if (checkMessage != null) { log.info("check consumer received message : {} {}", checkMessage.getMessageId(), new String(checkMessage.getData())); } @@ -288,7 +288,7 @@ public void testDeadLetterWithoutConsumerReceiveImmediately() throws PulsarClien // Wait a while, message should not be send to DLQ Thread.sleep(5000L); - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(5, TimeUnit.SECONDS); assertNotNull(msg); } } diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/DispatcherBlockConsumerTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/DispatcherBlockConsumerTest.java index 5cb4fc1383dae..7507ac7d18ba4 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/DispatcherBlockConsumerTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/DispatcherBlockConsumerTest.java @@ -670,12 +670,12 @@ public void testBrokerSubscriptionRecovery(boolean unloadBundleGracefully) throw * acking a. as consumer is acking not reached maxUnAckPerDispatcher=20 unack msg => consumes all produced msgs * 4.Subscription-1 : acks all pending msgs and consume by acking a. broker unblocks all dispatcher and sub-1 * consumes all messages 5. Subscription-2 : it triggers redelivery and acks all messages so, it consumes all - * produced messages + * produced messages. * * * @throws Exception */ - @Test(timeOut = 10000) + @Test(timeOut = 190000) public void testBlockBrokerDispatching() throws Exception { log.info("-- Starting {} test --", methodName); @@ -743,7 +743,7 @@ public void testBlockBrokerDispatching() throws Exception { Message msg = null; Set messages1 = Sets.newHashSet(); for (int j = 0; j < totalProducedMsgs; j++) { - msg = consumer1Sub1.receive(100, TimeUnit.MILLISECONDS); + msg = consumer1Sub1.receive(5, TimeUnit.SECONDS); if (msg != null) { messages1.add(msg.getMessageId()); } else { @@ -752,7 +752,7 @@ public void testBlockBrokerDispatching() throws Exception { // once consumer receives maxUnAckPerBroker-msgs then sleep to give a chance to scheduler to block the // subscription if (j == maxUnAckPerBroker) { - Thread.sleep(200); + Thread.sleep(1000); } } // client must receive number of messages = maxUnAckPerbroker rather all produced messages @@ -764,7 +764,7 @@ public void testBlockBrokerDispatching() throws Exception { .subscriptionType(SubscriptionType.Shared).acknowledgmentGroupTime(0, TimeUnit.SECONDS).subscribe(); int consumer2Msgs = 0; for (int j = 0; j < totalProducedMsgs; j++) { - msg = consumer2Sub1.receive(100, TimeUnit.MILLISECONDS); + msg = consumer2Sub1.receive(5, TimeUnit.SECONDS); if (msg != null) { consumer2Msgs++; } else { @@ -789,7 +789,7 @@ public void testBlockBrokerDispatching() throws Exception { .subscriptionType(SubscriptionType.Shared).acknowledgmentGroupTime(0, TimeUnit.SECONDS).subscribe(); Set messages2 = Sets.newHashSet(); for (int j = 0; j < totalProducedMsgs; j++) { - msg = consumerSub2.receive(100, TimeUnit.MILLISECONDS); + msg = consumerSub2.receive(5, TimeUnit.SECONDS); if (msg != null) { messages2.add(msg.getMessageId()); } else { @@ -806,7 +806,7 @@ public void testBlockBrokerDispatching() throws Exception { .subscriptionType(SubscriptionType.Shared).acknowledgmentGroupTime(0, TimeUnit.SECONDS).subscribe(); int consumedMsgsSub3 = 0; for (int j = 0; j < totalProducedMsgs; j++) { - msg = consumer1Sub3.receive(100, TimeUnit.MILLISECONDS); + msg = consumer1Sub3.receive(5, TimeUnit.SECONDS); if (msg != null) { consumedMsgsSub3++; consumer1Sub3.acknowledge(msg); @@ -822,7 +822,7 @@ public void testBlockBrokerDispatching() throws Exception { // sleep so, broker receives all ack back to unblock subscription Thread.sleep(1000); for (int j = 0; j < totalProducedMsgs; j++) { - msg = consumer1Sub1.receive(1, TimeUnit.SECONDS); + msg = consumer1Sub1.receive(5, TimeUnit.SECONDS); if (msg != null) { messages1.add(msg.getMessageId()); consumer1Sub1.acknowledge(msg); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ExposeMessageRedeliveryCountTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ExposeMessageRedeliveryCountTest.java index 8ebbca0be23d6..a8e88196d435c 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ExposeMessageRedeliveryCountTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ExposeMessageRedeliveryCountTest.java @@ -43,7 +43,7 @@ protected void cleanup() throws Exception { super.internalCleanup(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testRedeliveryCount() throws PulsarClientException { final String topic = "persistent://my-property/my-ns/redeliveryCount"; @@ -78,7 +78,7 @@ public void testRedeliveryCount() throws PulsarClientException { consumer.close(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testRedeliveryCountWithPartitionedTopic() throws PulsarClientException, PulsarAdminException { final String topic = "persistent://my-property/my-ns/redeliveryCount.partitioned"; @@ -117,7 +117,7 @@ public void testRedeliveryCountWithPartitionedTopic() throws PulsarClientExcepti admin.topics().deletePartitionedTopic(topic); } - @Test(timeOut = 30000) + @Test(timeOut = 190000) public void testRedeliveryCountWhenConsumerDisconnected() throws PulsarClientException, InterruptedException { String topic = "persistent://my-property/my-ns/testRedeliveryCountWhenConsumerDisconnected"; @@ -150,7 +150,7 @@ public void testRedeliveryCountWhenConsumerDisconnected() throws PulsarClientExc List> receivedMessagesForConsumer1 = new ArrayList<>(); for (int i = 0; i < messages; i++) { - Message msg = consumer0.receive(1, TimeUnit.SECONDS); + Message msg = consumer0.receive(5, TimeUnit.SECONDS); if (msg != null) { receivedMessagesForConsumer0.add(msg); } else { @@ -159,7 +159,7 @@ public void testRedeliveryCountWhenConsumerDisconnected() throws PulsarClientExc } for (int i = 0; i < messages; i++) { - Message msg = consumer1.receive(1, TimeUnit.SECONDS); + Message msg = consumer1.receive(5, TimeUnit.SECONDS); if (msg != null) { receivedMessagesForConsumer1.add(msg); } else { diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/NonPersistentTopicTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/NonPersistentTopicTest.java index 9232642c02f9b..3855390f771b6 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/NonPersistentTopicTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/NonPersistentTopicTest.java @@ -119,7 +119,7 @@ public void testNonPersistentTopic(SubscriptionType type) throws Exception { Message msg = null; Set messageSet = Sets.newHashSet(); for (int i = 0; i < totalProduceMsg; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { consumer.acknowledge(msg); String receivedMessage = new String(msg.getData()); @@ -162,7 +162,7 @@ public void testPartitionedNonPersistentTopic(SubscriptionType type) throws Exce Message msg = null; Set messageSet = Sets.newHashSet(); for (int i = 0; i < totalProduceMsg; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { consumer.acknowledge(msg); String receivedMessage = new String(msg.getData()); @@ -217,7 +217,7 @@ public void testPartitionedNonPersistentTopicWithTcpLookup(SubscriptionType type Message msg = null; Set messageSet = Sets.newHashSet(); for (int i = 0; i < totalProduceMsg; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { consumer.acknowledge(msg); String receivedMessage = new String(msg.getData()); @@ -260,7 +260,7 @@ public void testConsumerInternalQueueMaxOut(SubscriptionType type) throws Except Message msg = null; Set messageSet = Sets.newHashSet(); for (int i = 0; i < totalProduceMsg; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { consumer.acknowledge(msg); String receivedMessage = new String(msg.getData()); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/PartitionedProducerConsumerTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/PartitionedProducerConsumerTest.java index 982005640b55c..be9d2f37687da 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/PartitionedProducerConsumerTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/PartitionedProducerConsumerTest.java @@ -69,7 +69,7 @@ protected void cleanup() throws Exception { executor.shutdown(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testRoundRobinProducer() throws Exception { log.info("-- Starting {} test --", methodName); PulsarClient pulsarClient = newPulsarClient(lookupUrl.toString(), 0);// Creates new client connection @@ -95,7 +95,7 @@ public void testRoundRobinProducer() throws Exception { Message msg; Set messageSet = Sets.newHashSet(); for (int i = 0; i < 10; i++) { - msg = consumer.receive(5, TimeUnit.SECONDS); + msg = consumer.receive(); Assert.assertNotNull(msg, "Message should not be null"); consumer.acknowledge(msg); String receivedMessage = new String(msg.getData()); @@ -112,7 +112,7 @@ public void testRoundRobinProducer() throws Exception { log.info("-- Exiting {} test --", methodName); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testPartitionedTopicNameWithSpecialCharacter() throws Exception { log.info("-- Starting {} test --", methodName); @@ -130,7 +130,7 @@ public void testPartitionedTopicNameWithSpecialCharacter() throws Exception { log.info("-- Exiting {} test --", methodName); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testCustomPartitionProducer() throws Exception { PulsarClient pulsarClient = newPulsarClient(lookupUrl.toString(), 0);// Creates new client connection TopicName topicName = null; @@ -162,7 +162,7 @@ public void testCustomPartitionProducer() throws Exception { Set messageSet = Sets.newHashSet(); for (int i = 0; i < MESSAGE_COUNT; i++) { - msg = consumer.receive(5, TimeUnit.SECONDS); + msg = consumer.receive(); Assert.assertNotNull(msg, "Message should not be null"); consumer.acknowledge(msg); String receivedMessage = new String(msg.getData()); @@ -181,7 +181,7 @@ public void testCustomPartitionProducer() throws Exception { } } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testSinglePartitionProducer() throws Exception { log.info("-- Starting {} test --", methodName); PulsarClient pulsarClient = newPulsarClient(lookupUrl.toString(), 0);// Creates new client connection @@ -207,7 +207,7 @@ public void testSinglePartitionProducer() throws Exception { Set messageSet = Sets.newHashSet(); for (int i = 0; i < 10; i++) { - msg = consumer.receive(5, TimeUnit.SECONDS); + msg = consumer.receive(); Assert.assertNotNull(msg, "Message should not be null"); consumer.acknowledge(msg); String receivedMessage = new String(msg.getData()); @@ -225,7 +225,7 @@ public void testSinglePartitionProducer() throws Exception { log.info("-- Exiting {} test --", methodName); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testKeyBasedProducer() throws Exception { log.info("-- Starting {} test --", methodName); PulsarClient pulsarClient = newPulsarClient(lookupUrl.toString(), 0);// Creates new client connection @@ -253,7 +253,7 @@ public void testKeyBasedProducer() throws Exception { Set messageSet = Sets.newHashSet(); for (int i = 0; i < 10; i++) { - Message msg = consumer.receive(5, TimeUnit.SECONDS); + Message msg = consumer.receive(); Assert.assertNotNull(msg, "Message should not be null"); consumer.acknowledge(msg); String receivedMessage = new String(msg.getData()); @@ -334,7 +334,7 @@ public void testPauseAndResume() throws Exception { log.info("-- Exiting {} test --", methodName); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testInvalidSequence() throws Exception { log.info("-- Starting {} test --", methodName); @@ -389,7 +389,7 @@ public void testInvalidSequence() throws Exception { } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testSillyUser() throws Exception { int numPartitions = 4; @@ -433,7 +433,7 @@ public void testSillyUser() throws Exception { } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testDeletePartitionedTopic() throws Exception { int numPartitions = 4; TopicName topicName = TopicName @@ -455,7 +455,7 @@ public void testDeletePartitionedTopic() throws Exception { } } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testAsyncPartitionedProducerConsumer() throws Exception { log.info("-- Starting {} test --", methodName); @@ -504,7 +504,7 @@ public void testAsyncPartitionedProducerConsumer() throws Exception { log.info("-- Exiting {} test --", methodName); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testAsyncPartitionedProducerConsumerQueueSizeOne() throws Exception { log.info("-- Starting {} test --", methodName); PulsarClient pulsarClient = newPulsarClient(lookupUrl.toString(), 0);// Creates new client connection @@ -561,7 +561,7 @@ public void testAsyncPartitionedProducerConsumerQueueSizeOne() throws Exception * * @throws Exception */ - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testFairDistributionForPartitionConsumers() throws Exception { log.info("-- Starting {} test --", methodName); PulsarClient pulsarClient = newPulsarClient(lookupUrl.toString(), 0);// Creates new client connection @@ -748,7 +748,7 @@ public void testMessageIdForSubscribeToSinglePartition() throws Exception { * * @throws Exception */ - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testAutoUpdatePartitionsForProducerConsumer() throws Exception { log.info("-- Starting {} test --", methodName); PulsarClient pulsarClient = newPulsarClient(lookupUrl.toString(), 0);// Creates new client connection diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerStatTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerStatTest.java index 62b4aec3a4a09..9a77b06a7c4e8 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerStatTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerStatTest.java @@ -26,11 +26,7 @@ import java.util.List; import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.pulsar.broker.stats.NamespaceStats; @@ -64,6 +60,15 @@ protected void cleanup() throws Exception { super.internalCleanup(); } + // Perhaps it would be better to import this method from PulsarTestBase in tests.integration + public static String randomName(int numChars) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < numChars; i++) { + sb.append((char) (ThreadLocalRandom.current().nextInt(26) + 'a')); + } + return sb.toString(); + } + @DataProvider(name = "batch") public Object[][] batchMessageDelayMsProvider() { return new Object[][] { { 0 }, { 1000 } }; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java index 612b610754361..e3e6d5bb9e80c 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java @@ -536,7 +536,7 @@ public void testSendTimeout(int batchMessageDelayMs) throws Exception { startBroker(); // We should not have received any message - Message msg = consumer.receive(3, TimeUnit.SECONDS); + Message msg = consumer.receive(10, TimeUnit.MILLISECONDS); Assert.assertNull(msg); consumer.close(); log.info("-- Exiting {} test --", methodName); @@ -750,7 +750,7 @@ public void testConcurrentConsumerReceiveWhileReconnect(int batchMessageDelayMs) // clear the queue while (true) { - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(7, TimeUnit.SECONDS); if (msg == null) { break; } @@ -946,7 +946,7 @@ public void testActiveAndInActiveConsumerEntryCacheBehavior() throws Exception { // sleep for a second: as ledger.updateCursorRateLimit RateLimiter will allow to invoke cursor-update after a // second - Thread.sleep(1000);// + Thread.sleep(2000); // Needs to be replaced with await() approach. // produce-consume one more message to trigger : ledger.internalReadFromLedger(..) which updates cursor and // EntryCache producer.send("message".getBytes()); @@ -970,7 +970,7 @@ public void testActiveAndInActiveConsumerEntryCacheBehavior() throws Exception { // sleep for a second: as ledger.updateCursorRateLimit RateLimiter will allow to invoke cursor-update after a // second - Thread.sleep(1000);// + Thread.sleep(2000);// Needs to be replaced with await() approach. // produce-consume one more message to trigger : ledger.internalReadFromLedger(..) which updates cursor and // EntryCache producer.send("message".getBytes()); @@ -1176,7 +1176,7 @@ public void testSendCallBack() throws Exception { * * @throws Exception */ - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testSharedConsumerAckDifferentConsumer() throws Exception { log.info("-- Starting {} test --", methodName); @@ -1301,7 +1301,7 @@ public void testConsumerBlockingWithUnAckedMessages() throws Exception { Message msg = null; List> messages = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(2, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); log.info("Received message: " + new String(msg.getData())); @@ -1324,7 +1324,7 @@ public void testConsumerBlockingWithUnAckedMessages() throws Exception { // try to consume remaining messages int remainingMessages = totalProducedMsgs - messages.size(); for (int i = 0; i < remainingMessages; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(2, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); log.info("Received message: " + new String(msg.getData())); @@ -1386,7 +1386,7 @@ public void testConsumerBlockingWithUnAckedMessagesMultipleIteration() throws Ex Message msg = null; List> messages = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(2, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); log.info("Received message: " + new String(msg.getData())); @@ -1461,7 +1461,7 @@ public void testMutlipleSharedConsumerBlockingWithUnAckedMessages() throws Excep Message msg = null; List> messages = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(2, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); totalReceiveMessages++; @@ -1476,7 +1476,7 @@ public void testMutlipleSharedConsumerBlockingWithUnAckedMessages() throws Excep // (3.1) Consumer2 will start consuming messages without ack: it should stop after maxUnackedMessages messages.clear(); for (int i = 0; i < totalProducedMsgs - maxUnackedMessages; i++) { - msg = consumer2.receive(1, TimeUnit.SECONDS); + msg = consumer2.receive(2, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); totalReceiveMessages++; @@ -1498,7 +1498,7 @@ public void testMutlipleSharedConsumerBlockingWithUnAckedMessages() throws Excep // (4) Consumer2 consumer and ack: so it should consume all remaining messages messages.clear(); for (int i = 0; i < totalProducedMsgs - (2 * maxUnackedMessages); i++) { - msg = consumer2.receive(1, TimeUnit.SECONDS); + msg = consumer2.receive(2, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); totalReceiveMessages++; @@ -1559,7 +1559,7 @@ public void testShouldNotBlockConsumerIfRedeliverBeforeReceive() throws Exceptio assertEquals(consumer.numMessagesInQueue(), receiverQueueSize); for (int i = 0; i < totalProducedMsgs; i++) { - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { consumer.acknowledge(msg); totalReceiveMsg++; @@ -1610,7 +1610,7 @@ public void testUnackBlockRedeliverMessages() throws Exception { Message msg = null; List> messages = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(2, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); totalReceiveMsg++; @@ -1626,7 +1626,7 @@ public void testUnackBlockRedeliverMessages() throws Exception { int alreadyConsumedMessages = messages.size(); messages.clear(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { consumer.acknowledge(msg); totalReceiveMsg++; @@ -1691,7 +1691,7 @@ public void testUnackedBlockAtBatch(int batchMessageDelayMs) throws Exception { Message msg = null; List> messages = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(2, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); totalReceiveMessages++; @@ -1714,7 +1714,7 @@ public void testUnackedBlockAtBatch(int batchMessageDelayMs) throws Exception { // (3) Consumer consumes and ack: so it should consume all remaining messages messages.clear(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(2, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); totalReceiveMessages++; @@ -1774,7 +1774,7 @@ public void testBlockUnackConsumerAckByDifferentConsumer() throws Exception { Message msg = null; List> messages = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(2, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); totalReceiveMessages++; @@ -1797,7 +1797,7 @@ public void testBlockUnackConsumerAckByDifferentConsumer() throws Exception { // (4) consumer1 will consumer remaining msgs and consumer2 will ack those messages for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(2, TimeUnit.SECONDS); if (msg != null) { totalReceiveMessages++; consumer2.acknowledge(msg); @@ -1808,7 +1808,7 @@ public void testBlockUnackConsumerAckByDifferentConsumer() throws Exception { } for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer2.receive(1, TimeUnit.SECONDS); + msg = consumer2.receive(2, TimeUnit.SECONDS); if (msg != null) { totalReceiveMessages++; log.info("Received message: " + new String(msg.getData())); @@ -1904,7 +1904,7 @@ public void testBlockUnackedConsumerRedeliverySpecificMessagesProduceWithPause() Message msg = null; List> messages1 = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(2, TimeUnit.SECONDS); if (msg != null) { messages1.add(msg); log.info("Received message: " + new String(msg.getData())); @@ -1925,7 +1925,7 @@ public void testBlockUnackedConsumerRedeliverySpecificMessagesProduceWithPause() Set messages2 = Sets.newHashSet(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(2, TimeUnit.SECONDS); if (msg != null) { messages2.add((MessageIdImpl) msg.getMessageId()); log.info("Received message: " + new String(msg.getData())); @@ -1993,7 +1993,7 @@ public void testBlockUnackedConsumerRedeliverySpecificMessagesCloseConsumerWhile Message msg = null; List> messages1 = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(2, TimeUnit.SECONDS); if (msg != null) { messages1.add(msg); log.info("Received message: " + new String(msg.getData())); @@ -2014,7 +2014,7 @@ public void testBlockUnackedConsumerRedeliverySpecificMessagesCloseConsumerWhile Set messages2 = Sets.newHashSet(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(2, TimeUnit.SECONDS); if (msg != null) { messages2.add((MessageIdImpl) msg.getMessageId()); log.info("Received message: " + new String(msg.getData())); @@ -2271,7 +2271,7 @@ public void testRedeliveryFailOverConsumer() throws Exception { Message msg = null; List> messages1 = Lists.newArrayList(); for (int i = 0; i < consumeMsgInParts; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { messages1.add(msg); consumer.acknowledge(msg); @@ -2286,7 +2286,7 @@ public void testRedeliveryFailOverConsumer() throws Exception { // (1.b) consume second consumeMsgInParts msgs and trigger redeliver messages1.clear(); for (int i = 0; i < consumeMsgInParts; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { messages1.add(msg); consumer.acknowledge(msg); @@ -2308,7 +2308,7 @@ public void testRedeliveryFailOverConsumer() throws Exception { int remainingMsgs = (2 * receiverQueueSize) - (2 * consumeMsgInParts); messages1.clear(); for (int i = 0; i < remainingMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { messages1.add(msg); consumer.acknowledge(msg); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SubscriptionMessageDispatchThrottlingTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SubscriptionMessageDispatchThrottlingTest.java index 7ed88f5c516f2..b3c6ad4b520c8 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SubscriptionMessageDispatchThrottlingTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SubscriptionMessageDispatchThrottlingTest.java @@ -21,6 +21,7 @@ import com.google.common.collect.Sets; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import org.apache.pulsar.broker.service.Dispatcher; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/TlsProducerConsumerTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/TlsProducerConsumerTest.java index 82aa7d35aa0e4..e08ff688efed3 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/TlsProducerConsumerTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/TlsProducerConsumerTest.java @@ -35,7 +35,7 @@ public class TlsProducerConsumerTest extends TlsProducerConsumerBase { * * @throws Exception */ - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testTlsLargeSizeMessage() throws Exception { log.info("-- Starting {} test --", methodName); @@ -69,7 +69,7 @@ public void testTlsLargeSizeMessage() throws Exception { log.info("-- Exiting {} test --", methodName); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testTlsClientAuthOverBinaryProtocol() throws Exception { log.info("-- Starting {} test --", methodName); @@ -97,7 +97,7 @@ public void testTlsClientAuthOverBinaryProtocol() throws Exception { } } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testTlsClientAuthOverHTTPProtocol() throws Exception { log.info("-- Starting {} test --", methodName); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/v1/V1_ProducerConsumerTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/v1/V1_ProducerConsumerTest.java index a54dcd853c701..742bb8deed3d9 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/v1/V1_ProducerConsumerTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/v1/V1_ProducerConsumerTest.java @@ -329,7 +329,7 @@ public void testSendTimeout(int batchMessageDelayMs) throws Exception { startBroker(); // We should not have received any message - Message msg = consumer.receive(3, TimeUnit.SECONDS); + Message msg = consumer.receive(10, TimeUnit.MILLISECONDS); Assert.assertNull(msg); consumer.close(); log.info("-- Exiting {} test --", methodName); @@ -520,7 +520,7 @@ public Void call() throws Exception { } barrier.await(); - // there will be 10 threads calling receive() from the same consumer and will block + // there will be 10 threads calling receive(5) from the same consumer and will block Thread.sleep(100); // we restart the broker to reconnect @@ -565,7 +565,7 @@ public Void call() throws Exception { // clear the queue while (true) { - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(5, TimeUnit.SECONDS); if (msg == null) { break; } @@ -853,7 +853,7 @@ public void testSendCallBack() throws Exception { * * @throws Exception */ - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testSharedConsumerAckDifferentConsumer() throws Exception { log.info("-- Starting {} test --", methodName); @@ -985,7 +985,7 @@ public void testConsumerBlockingWithUnAckedMessages() throws Exception { Messagemsg = null; List> messages = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); log.info("Received message: " + new String(msg.getData())); @@ -1008,7 +1008,7 @@ public void testConsumerBlockingWithUnAckedMessages() throws Exception { // try to consume remaining messages int remainingMessages = totalProducedMsgs - messages.size(); for (int i = 0; i < remainingMessages; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); log.info("Received message: " + new String(msg.getData())); @@ -1073,7 +1073,7 @@ public void testConsumerBlockingWithUnAckedMessagesMultipleIteration() throws Ex Messagemsg = null; List> messages = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); log.info("Received message: " + new String(msg.getData())); @@ -1154,7 +1154,7 @@ public void testMutlipleSharedConsumerBlockingWithUnAckedMessages() throws Excep Messagemsg = null; List> messages = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(5, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); totalReceiveMessages++; @@ -1169,7 +1169,7 @@ public void testMutlipleSharedConsumerBlockingWithUnAckedMessages() throws Excep // (3.1) Consumer2 will start consuming messages without ack: it should stop after maxUnackedMessages messages.clear(); for (int i = 0; i < totalProducedMsgs - maxUnackedMessages; i++) { - msg = consumer2.receive(1, TimeUnit.SECONDS); + msg = consumer2.receive(5, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); totalReceiveMessages++; @@ -1191,7 +1191,7 @@ public void testMutlipleSharedConsumerBlockingWithUnAckedMessages() throws Excep // (4) Consumer2 consumer and ack: so it should consume all remaining messages messages.clear(); for (int i = 0; i < totalProducedMsgs - (2 * maxUnackedMessages); i++) { - msg = consumer2.receive(1, TimeUnit.SECONDS); + msg = consumer2.receive(5, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); totalReceiveMessages++; @@ -1254,7 +1254,7 @@ public void testShouldNotBlockConsumerIfRedeliverBeforeReceive() throws Exceptio assertEquals(consumer.numMessagesInQueue(), receiverQueueSize); for (int i = 0; i < totalProducedMsgs; i++) { - Messagemsg = consumer.receive(1, TimeUnit.SECONDS); + Messagemsg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { consumer.acknowledge(msg); totalReceiveMsg++; @@ -1309,7 +1309,7 @@ public void testUnackBlockRedeliverMessages() throws Exception { Messagemsg = null; List> messages = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); totalReceiveMsg++; @@ -1325,7 +1325,7 @@ public void testUnackBlockRedeliverMessages() throws Exception { int alreadyConsumedMessages = messages.size(); messages.clear(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { consumer.acknowledge(msg); totalReceiveMsg++; @@ -1387,7 +1387,7 @@ public void testUnackedBlockAtBatch(int batchMessageDelayMs) throws Exception { Messagemsg = null; List> messages = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(5, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); totalReceiveMessages++; @@ -1410,7 +1410,7 @@ public void testUnackedBlockAtBatch(int batchMessageDelayMs) throws Exception { // (3) Consumer consumes and ack: so it should consume all remaining messages messages.clear(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(5, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); totalReceiveMessages++; @@ -1473,7 +1473,7 @@ public void testBlockUnackConsumerAckByDifferentConsumer() throws Exception { Messagemsg = null; List> messages = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(5, TimeUnit.SECONDS); if (msg != null) { messages.add(msg); totalReceiveMessages++; @@ -1496,7 +1496,7 @@ public void testBlockUnackConsumerAckByDifferentConsumer() throws Exception { // (4) consumer1 will consumer remaining msgs and consumer2 will ack those messages for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(5, TimeUnit.SECONDS); if (msg != null) { totalReceiveMessages++; consumer2.acknowledge(msg); @@ -1507,7 +1507,7 @@ public void testBlockUnackConsumerAckByDifferentConsumer() throws Exception { } for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer2.receive(1, TimeUnit.SECONDS); + msg = consumer2.receive(5, TimeUnit.SECONDS); if (msg != null) { totalReceiveMessages++; log.info("Received message: " + new String(msg.getData())); @@ -1609,7 +1609,7 @@ public void testBlockUnackedConsumerRedeliverySpecificMessagesProduceWithPause() Messagemsg = null; List> messages1 = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { messages1.add(msg); log.info("Received message: " + new String(msg.getData())); @@ -1630,7 +1630,7 @@ public void testBlockUnackedConsumerRedeliverySpecificMessagesProduceWithPause() Set messages2 = Sets.newHashSet(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { messages2.add((MessageIdImpl) msg.getMessageId()); log.info("Received message: " + new String(msg.getData())); @@ -1705,7 +1705,7 @@ public void testBlockUnackedConsumerRedeliverySpecificMessagesCloseConsumerWhile Messagemsg = null; List> messages1 = Lists.newArrayList(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { messages1.add(msg); log.info("Received message: " + new String(msg.getData())); @@ -1726,7 +1726,7 @@ public void testBlockUnackedConsumerRedeliverySpecificMessagesCloseConsumerWhile Set messages2 = Sets.newHashSet(); for (int i = 0; i < totalProducedMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { messages2.add((MessageIdImpl) msg.getMessageId()); log.info("Received message: " + new String(msg.getData())); @@ -1985,7 +1985,7 @@ public void testRedeliveryFailOverConsumer() throws Exception { Message msg = null; List> messages1 = Lists.newArrayList(); for (int i = 0; i < consumeMsgInParts; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { messages1.add(msg); consumer.acknowledge(msg); @@ -2000,7 +2000,7 @@ public void testRedeliveryFailOverConsumer() throws Exception { // (1.b) consume second consumeMsgInParts msgs and trigger redeliver messages1.clear(); for (int i = 0; i < consumeMsgInParts; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { messages1.add(msg); consumer.acknowledge(msg); @@ -2022,7 +2022,7 @@ public void testRedeliveryFailOverConsumer() throws Exception { int remainingMsgs = (2 * receiverQueueSize) - (2 * consumeMsgInParts); messages1.clear(); for (int i = 0; i < remainingMsgs; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); if (msg != null) { messages1.add(msg); consumer.acknowledge(msg); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/BrokerClientIntegrationTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/BrokerClientIntegrationTest.java index 15357d318c8d6..16c85be11fdb6 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/BrokerClientIntegrationTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/BrokerClientIntegrationTest.java @@ -352,7 +352,7 @@ public void testUnsupportedBatchMessageConsumer(SubscriptionType subType) throws Set messageSet = Sets.newHashSet(); Message msg = null; for (int i = 0; i < numMessagesPerBatch; i++) { - msg = consumer1.receive(1, TimeUnit.SECONDS); + msg = consumer1.receive(5, TimeUnit.SECONDS); String receivedMessage = new String(msg.getData()); String expectedMessage = "my-message-" + i; testMessageOrderAndDuplicates(messageSet, receivedMessage, expectedMessage); @@ -370,7 +370,7 @@ public void testUnsupportedBatchMessageConsumer(SubscriptionType subType) throws batchProducer.flush(); // consumer should have not received any message as it should have been disconnected - msg = consumer1.receive(100, TimeUnit.MILLISECONDS); + msg = consumer1.receive(10, TimeUnit.MILLISECONDS); assertNull(msg); // subscribe consumer2 with supporting batch version diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/CompactedOutBatchMessageTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/CompactedOutBatchMessageTest.java index f7020378d5655..2bd28d7fbbf70 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/CompactedOutBatchMessageTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/CompactedOutBatchMessageTest.java @@ -33,6 +33,8 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import java.util.concurrent.TimeUnit; + public class CompactedOutBatchMessageTest extends ProducerConsumerBase { @BeforeMethod @Override diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ConsumerDedupPermitsUpdate.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ConsumerDedupPermitsUpdate.java index 15070484a0fb8..6e1434d5b2a4f 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ConsumerDedupPermitsUpdate.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ConsumerDedupPermitsUpdate.java @@ -92,7 +92,7 @@ public void testConsumerDedup(boolean batchingEnabled, int receiverQueueSize) th // Consumer receives and acks all the messages, though the acks // are still cached in client lib for (int i = 0; i < 30; i++) { - Message msg = consumer.receive(); + Message msg = consumer.receive(); // Can't use receive with timeout, if the queue size is 0 assertEquals(msg.getValue(), "hello-" + i); consumer.acknowledge(msg); } diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/MessageIdTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/MessageIdTest.java index 14349f7c4f8f8..12930356e5d4e 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/MessageIdTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/MessageIdTest.java @@ -343,9 +343,9 @@ public void testChecksumVersionComptability() throws Exception { ((ConsumerImpl) consumer).grabCnx(); // We should only receive msg1 - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(5, TimeUnit.SECONDS); assertEquals(new String(msg.getData()), "message-1"); - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); assertEquals(new String(msg.getData()), "message-3"); } @@ -415,9 +415,9 @@ public void testChecksumReconnection() throws Exception { ((ConsumerImpl) consumer).grabCnx(); // We should only receive msg1 - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(5, TimeUnit.SECONDS); assertEquals(new String(msg.getData()), "message-1"); - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); assertEquals(new String(msg.getData()), "message-3"); } diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/PatternTopicsConsumerImplTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/PatternTopicsConsumerImplTest.java index b14c1cd466090..a1d8dd23ac837 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/PatternTopicsConsumerImplTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/PatternTopicsConsumerImplTest.java @@ -809,7 +809,7 @@ public void testTopicDeletion() throws Exception { producer2.send("msg-2"); - message = consumer.receive(); + message = consumer.receive(5, TimeUnit.SECONDS); assertEquals(message.getValue(), "msg-2"); consumer.acknowledge(message); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ProducerSemaphoreTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ProducerSemaphoreTest.java index d435938c33f72..d3026a460a45c 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ProducerSemaphoreTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ProducerSemaphoreTest.java @@ -55,7 +55,7 @@ public void cleanup() throws Exception { super.internalCleanup(); } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testProducerSemaphoreAcquireAndRelease() throws PulsarClientException, ExecutionException, InterruptedException { final int pendingQueueSize = 100; @@ -122,9 +122,9 @@ public void testProducerSemaphoreAcquireAndRelease() throws PulsarClientExceptio /** * We use semaphore to limit the pending send, so we must ensure that the thread of sending message never block * at the pending message queue. If not, the dead lock might occur. Here is the related issue to describe the - * dead lock happens {https://github.com/apache/pulsar/issues/5585} + * dead lock {https://github.com/apache/pulsar/issues/5585} */ - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testEnsureNotBlockOnThePendingQueue() throws Exception { final int pendingQueueSize = 10; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ReaderTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ReaderTest.java index b75cfcee0b9d2..e24933597e9ec 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ReaderTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ReaderTest.java @@ -139,9 +139,11 @@ public void testReadMessageWithBatchingWithMessageInclusive() throws Exception { String topic = "persistent://my-property/my-ns/my-reader-topic-with-batching-inclusive"; Set keys = publishMessages(topic, 10, true); - Reader reader = pulsarClient.newReader().topic(topic).startMessageId(MessageId.latest) + Reader reader = pulsarClient.newReader().topic(topic).startMessageId(MessageId.earliest) .startMessageIdInclusive().readerName(subscription).create(); + // If we use MessageId.latest, then publishMessages must occur after we create the reader. + Assert.assertTrue(reader.hasMessageAvailable()); while (reader.hasMessageAvailable()) { Assert.assertTrue(keys.remove(reader.readNext().getKey())); } @@ -199,7 +201,7 @@ public void testReadFromPartition() throws Exception { * 1. publish messages which are 5 hour old * 2. publish messages which are 1 hour old * 3. Create reader with rollback time 2 hours - * 4. Reader should be able to read only messages which are only 2 hours old + * 4. Reader should be able to read only messages which are only 2 hours old. * * @throws Exception */ diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/SequenceIdWithErrorTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/SequenceIdWithErrorTest.java index b604505ac54d0..df2027ac311a7 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/SequenceIdWithErrorTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/SequenceIdWithErrorTest.java @@ -21,6 +21,7 @@ import static org.testng.Assert.assertEquals; import java.util.Collections; +import java.util.concurrent.TimeUnit; import org.apache.bookkeeper.mledger.ManagedLedger; import org.apache.bookkeeper.mledger.ManagedLedgerFactory; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TopicsConsumerImplTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TopicsConsumerImplTest.java index c6883c63e0670..6ade1c59b8cb7 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TopicsConsumerImplTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TopicsConsumerImplTest.java @@ -638,7 +638,7 @@ public void testTopicsNameSubscribeWithBuilderFail() throws Exception { /** * Test Listener for github issue #2547 */ - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testMultiTopicsMessageListener() throws Exception { String key = "MultiTopicsMessageListenerTest"; final String subscriptionName = "my-ex-subscription-" + key; @@ -704,7 +704,7 @@ public void testMultiTopicsMessageListener() throws Exception { * 4. produce message to xx-partition-2 again, and verify consumer could receive message. * */ - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void testTopicAutoUpdatePartitions() throws Exception { String key = "TestTopicAutoUpdatePartitions"; final String subscriptionName = "my-ex-subscription-" + key; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/UnAcknowledgedMessagesTimeoutTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/UnAcknowledgedMessagesTimeoutTest.java index 122ce3ea158c8..299bb0cba365a 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/UnAcknowledgedMessagesTimeoutTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/UnAcknowledgedMessagesTimeoutTest.java @@ -45,7 +45,7 @@ public class UnAcknowledgedMessagesTimeoutTest extends BrokerTestBase { private static final Logger log = LoggerFactory.getLogger(UnAcknowledgedMessagesTimeoutTest.class); - private final long ackTimeOutMillis = TimeUnit.SECONDS.toMillis(2); + private final long ackTimeOutMillis = TimeUnit.SECONDS.toMillis(12); @Override @BeforeMethod @@ -209,7 +209,7 @@ public void testSharedSingleAckedPartitionedTopic() throws Exception { // 5. Check if Messages redelivered again // Since receive is a blocking call hoping that timeout will kick in - Thread.sleep((int) (ackTimeOutMillis * 1.1)); + Thread.sleep((int) (ackTimeOutMillis * 1.1)); // Timeout triggers redelivery of unacked messages. log.info(key + " Timeout should be triggered now"); messageCount1 = receiveAllMessage(consumer1, true); messageCount2 += receiveAllMessage(consumer2, false); @@ -236,7 +236,7 @@ public void testSharedSingleAckedPartitionedTopic() throws Exception { private static int receiveAllMessage(Consumer consumer, boolean ackMessages) throws Exception { int messagesReceived = 0; - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(2, TimeUnit.SECONDS); while (msg != null) { ++messagesReceived; log.info("Consumer received {}", new String(msg.getData())); @@ -245,7 +245,7 @@ private static int receiveAllMessage(Consumer consumer, boolean ackMessages) consumer.acknowledge(msg); } - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(2, TimeUnit.SECONDS); } return messagesReceived; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionE2ETest.java b/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionE2ETest.java index c5b605a766a23..ee17012fff279 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionE2ETest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionE2ETest.java @@ -489,13 +489,13 @@ private void testE2EPulsarFunction(String jarFilePathUrl) throws Exception { Assert.assertEquals(foundFiles.length, 0, "Temporary files left over: " + Arrays.asList(foundFiles)); } - @Test(timeOut = 20000) + @Test(timeOut = 40000) public void testE2EPulsarFunctionWithFile() throws Exception { String jarFilePathUrl = Utils.FILE + ":" + getClass().getClassLoader().getResource("pulsar-functions-api-examples.jar").getFile(); testE2EPulsarFunction(jarFilePathUrl); } - @Test(timeOut = 40000) + @Test(timeOut = 80000) public void testE2EPulsarFunctionWithUrl() throws Exception { String jarFilePathUrl = String.format("http://127.0.0.1:%d/pulsar-functions-api-examples.jar", fileServer.getAddress().getPort()); @@ -720,13 +720,13 @@ private void testPulsarSinkStats(String jarFilePathUrl) throws Exception { Assert.assertEquals(foundFiles.length, 0, "Temporary files left over: " + Arrays.asList(foundFiles)); } - @Test(timeOut = 20000) + @Test(timeOut = 40000) public void testPulsarSinkStatsWithFile() throws Exception { String jarFilePathUrl = Utils.FILE + ":" + getClass().getClassLoader().getResource("pulsar-io-data-generator.nar").getFile(); testPulsarSinkStats(jarFilePathUrl); } - @Test(timeOut = 40000) + @Test(timeOut = 80000) public void testPulsarSinkStatsWithUrl() throws Exception { String jarFilePathUrl = String.format("http://127.0.0.1:%d/pulsar-io-data-generator.nar", fileServer.getAddress().getPort()); @@ -860,20 +860,20 @@ private void testPulsarSourceStats(String jarFilePathUrl) throws Exception { Assert.assertEquals(foundFiles.length, 0, "Temporary files left over: " + Arrays.asList(foundFiles)); } - @Test(timeOut = 20000) + @Test(timeOut = 40000) public void testPulsarSourceStatsWithFile() throws Exception { String jarFilePathUrl = Utils.FILE + ":" + getClass().getClassLoader().getResource("pulsar-io-data-generator.nar").getFile(); testPulsarSourceStats(jarFilePathUrl); } - @Test(timeOut = 40000) + @Test(timeOut = 80000) public void testPulsarSourceStatsWithUrl() throws Exception { String jarFilePathUrl = String.format("http://127.0.0.1:%d/pulsar-io-data-generator.nar", fileServer.getAddress().getPort()); testPulsarSourceStats(jarFilePathUrl); } - @Test(timeOut = 20000) + @Test(timeOut = 40000) public void testPulsarFunctionStats() throws Exception { final String namespacePortion = "io"; @@ -1209,7 +1209,7 @@ public void testPulsarFunctionStats() throws Exception { Assert.assertEquals(foundFiles.length, 0, "Temporary files left over: " + Arrays.asList(foundFiles)); } - @Test(timeOut = 20000) + @Test(timeOut = 40000) public void testPulsarFunctionStatus() throws Exception { final String namespacePortion = "io"; @@ -1319,7 +1319,7 @@ public void testAuthorization(boolean validRoleName) throws Exception { } } - @Test(timeOut = 20000) + @Test(timeOut = 40000) public void testFunctionStopAndRestartApi() throws Exception { final String namespacePortion = "io"; @@ -1386,7 +1386,7 @@ public void testFunctionStopAndRestartApi() throws Exception { producer.close(); } - @Test(timeOut = 20000) + @Test(timeOut = 40000) public void testFunctionAutomaticSubCleanup() throws Exception { final String namespacePortion = "io"; final String replNamespace = tenant + "/" + namespacePortion; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/websocket/proxy/ProxyPublishConsumeTlsTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/websocket/proxy/ProxyPublishConsumeTlsTest.java index d4e90329c0133..5481895fb210f 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/websocket/proxy/ProxyPublishConsumeTlsTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/websocket/proxy/ProxyPublishConsumeTlsTest.java @@ -86,7 +86,7 @@ protected void cleanup() throws Exception { } - @Test(timeOut = 30000) + @Test(timeOut = 90000) public void socketTest() throws InterruptedException, GeneralSecurityException { String consumerUri = "wss://localhost:" + proxyServer.getListenPortHTTPS().get() + "/ws/consumer/persistent/my-property/use/my-ns/my-topic/my-sub"; diff --git a/pulsar-client-cpp/tests/BasicEndToEndTest.cc b/pulsar-client-cpp/tests/BasicEndToEndTest.cc index 0010c963fdcb3..f73f2dd4d53c6 100644 --- a/pulsar-client-cpp/tests/BasicEndToEndTest.cc +++ b/pulsar-client-cpp/tests/BasicEndToEndTest.cc @@ -748,7 +748,7 @@ TEST(BasicEndToEndTest, testSinglePartitionRoutingPolicy) { for (int i = 0; i < 10; i++) { Message m; - consumer.receive(m); + consumer.receive(m, 9000); consumer.acknowledgeCumulative(m); } @@ -1990,14 +1990,14 @@ TEST(BasicEndToEndTest, testPatternMultiTopicsConsumerPubSub) { LOG_INFO("Consuming and acking 300 messages by multiTopicsConsumer"); for (int i = 0; i < 3 * messageNumber; i++) { Message m; - ASSERT_EQ(ResultOk, consumer.receive(m, 1000)); + ASSERT_EQ(ResultOk, consumer.receive(m, 5000)); ASSERT_EQ(ResultOk, consumer.acknowledge(m)); } LOG_INFO("Consumed and acked 300 messages by multiTopicsConsumer"); - // verify no more to receive, because producer4 not match pattern + // verify no more to receive because producer4 not match pattern Message m; - ASSERT_EQ(ResultTimeout, consumer.receive(m, 1000)); + ASSERT_EQ(ResultTimeout, consumer.receive(m, 5000)); ASSERT_EQ(ResultOk, consumer.unsubscribe()); @@ -2085,14 +2085,14 @@ TEST(BasicEndToEndTest, testpatternMultiTopicsHttpConsumerPubSub) { LOG_INFO("Consuming and acking 300 messages by multiTopicsConsumer"); for (int i = 0; i < 3 * messageNumber; i++) { Message m; - ASSERT_EQ(ResultOk, consumer.receive(m, 1000)); + ASSERT_EQ(ResultOk, consumer.receive(m, 5000)); ASSERT_EQ(ResultOk, consumer.acknowledge(m)); } LOG_INFO("Consumed and acked 300 messages by multiTopicsConsumer"); // verify no more to receive Message m; - ASSERT_EQ(ResultTimeout, consumer.receive(m, 1000)); + ASSERT_EQ(ResultTimeout, consumer.receive(m, 5000)); ASSERT_EQ(ResultOk, consumer.unsubscribe()); @@ -2230,14 +2230,14 @@ TEST(BasicEndToEndTest, testPatternMultiTopicsConsumerAutoDiscovery) { LOG_INFO("Consuming and acking 300 messages by pattern topics consumer"); for (int i = 0; i < 3 * messageNumber; i++) { Message m; - ASSERT_EQ(ResultOk, consumer.receive(m, 1000)); + ASSERT_EQ(ResultOk, consumer.receive(m, 5000)); ASSERT_EQ(ResultOk, consumer.acknowledge(m)); } LOG_INFO("Consumed and acked 300 messages by pattern topics consumer"); // verify no more to receive, because producer4 not match pattern Message m; - ASSERT_EQ(ResultTimeout, consumer.receive(m, 1000)); + ASSERT_EQ(ResultTimeout, consumer.receive(m, 5000)); ASSERT_EQ(ResultOk, consumer.unsubscribe()); diff --git a/pulsar-client-kafka-compat/pulsar-client-kafka_0_8/pom.xml b/pulsar-client-kafka-compat/pulsar-client-kafka_0_8/pom.xml index 8d35f2d265d33..18f4fe0984690 100644 --- a/pulsar-client-kafka-compat/pulsar-client-kafka_0_8/pom.xml +++ b/pulsar-client-kafka-compat/pulsar-client-kafka_0_8/pom.xml @@ -49,6 +49,10 @@ test
+ + org.awaitility + awaitility + ${project.groupId} diff --git a/pulsar-client-kafka-compat/pulsar-client-kafka_0_8/src/test/java/org/apache/kafka/clients/producer/PulsarKafkaProducerTest.java b/pulsar-client-kafka-compat/pulsar-client-kafka_0_8/src/test/java/org/apache/kafka/clients/producer/PulsarKafkaProducerTest.java index 4cccf83ce79db..bf74f9e348e9c 100644 --- a/pulsar-client-kafka-compat/pulsar-client-kafka_0_8/src/test/java/org/apache/kafka/clients/producer/PulsarKafkaProducerTest.java +++ b/pulsar-client-kafka-compat/pulsar-client-kafka_0_8/src/test/java/org/apache/kafka/clients/producer/PulsarKafkaProducerTest.java @@ -28,6 +28,7 @@ import org.apache.pulsar.client.impl.ProducerBuilderImpl; import org.apache.pulsar.client.impl.conf.ProducerConfigurationData; import org.testng.annotations.Test; +import static org.awaitility.Awaitility.*; import kafka.producer.Partitioner; import kafka.producer.ProducerConfig; @@ -101,10 +102,18 @@ public void testPulsarKafkaProducerWithSerializer() throws Exception { properties.put(PARTITIONER_CLASS, TestPartitioner.class.getName()); ProducerConfig config = new ProducerConfig(properties); PulsarKafkaProducer producer = new PulsarKafkaProducer<>(config); - assertEquals(producer.getKeySerializer().getClass(), TestEncoder.class); - assertEquals(producer.getValueSerializer().getClass(), TestEncoder.class); - assertEquals(producer.getPartitioner().getClass(), TestPartitioner.class); - + await().atMost(300, + TimeUnit.MILLISECONDS) + .untilAsserted(() -> + assertEquals(producer.getKeySerializer().getClass(), TestEncoder.class)); + await().atMost(300, + TimeUnit.MILLISECONDS) + .untilAsserted(() -> + assertEquals(producer.getValueSerializer().getClass(), TestEncoder.class)); + await().atMost(300, + TimeUnit.MILLISECONDS) + .untilAsserted(() -> + assertEquals(producer.getPartitioner().getClass(), TestPartitioner.class)); } public static class TestEncoder implements Encoder { diff --git a/pulsar-client-kafka-compat/pulsar-client-kafka_0_8/src/test/java/org/apache/pulsar/client/kafka/test/KafkaProducerSimpleConsumerTest.java b/pulsar-client-kafka-compat/pulsar-client-kafka_0_8/src/test/java/org/apache/pulsar/client/kafka/test/KafkaProducerSimpleConsumerTest.java index 82621fb06200d..6dc414b2733d2 100644 --- a/pulsar-client-kafka-compat/pulsar-client-kafka_0_8/src/test/java/org/apache/pulsar/client/kafka/test/KafkaProducerSimpleConsumerTest.java +++ b/pulsar-client-kafka-compat/pulsar-client-kafka_0_8/src/test/java/org/apache/pulsar/client/kafka/test/KafkaProducerSimpleConsumerTest.java @@ -188,7 +188,7 @@ public void testPulsarKafkaProducerWithSerializer(int partitions) throws Excepti final long expectedReadOffsetPosition = lastOffset; - retryStrategically((test) -> fetchOffset(consumer, topicPartition, groupId) == expectedReadOffsetPosition, 10, 150); + retryStrategically((test) -> fetchOffset(consumer, topicPartition, groupId) == expectedReadOffsetPosition, 30, 250); long offset1 = fetchOffset(consumer, topicPartition, groupId); MessageIdImpl actualMsgId = ((MessageIdImpl)MessageIdUtils.getMessageId(offset1)); diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java index 14d0aeb14daee..ebf270dc7d6e5 100644 --- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java +++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java @@ -547,79 +547,100 @@ public void connectionOpened(final ClientCnx cnx) { cnx.registerConsumer(consumerId, this); log.info("[{}][{}] Subscribing to topic on cnx {}", topic, subscription, cnx.ctx().channel()); - + log.info("ConsumerImpl.connectionOpened(..)01"); long requestId = client.newRequestId(); int currentSize; synchronized (this) { currentSize = incomingMessages.size(); startMessageId = clearReceiverQueue(); + log.info("ConsumerImpl.connectionOpened(..)02"); if (possibleSendToDeadLetterTopicMessages != null) { possibleSendToDeadLetterTopicMessages.clear(); } } boolean isDurable = subscriptionMode == SubscriptionMode.Durable; + log.info("ConsumerImpl.connectionOpened(..)03"); MessageIdData startMessageIdData; if (isDurable) { // For regular durable subscriptions, the message id from where to restart will be determined by the broker. startMessageIdData = null; + log.info("ConsumerImpl.connectionOpened(..)04"); } else { // For non-durable we are going to restart from the next entry MessageIdData.Builder builder = MessageIdData.newBuilder(); + log.info("ConsumerImpl.connectionOpened(..)05"); builder.setLedgerId(startMessageId.getLedgerId()); builder.setEntryId(startMessageId.getEntryId()); if (startMessageId instanceof BatchMessageIdImpl) { + log.info("ConsumerImpl.connectionOpened(..)06"); builder.setBatchIndex(((BatchMessageIdImpl) startMessageId).getBatchIndex()); } startMessageIdData = builder.build(); builder.recycle(); + log.info("ConsumerImpl.connectionOpened(..)07"); } SchemaInfo si = schema.getSchemaInfo(); if (si != null && (SchemaType.BYTES == si.getType() || SchemaType.NONE == si.getType())) { + log.info("ConsumerImpl.connectionOpened(..)08"); // don't set schema for Schema.BYTES si = null; } // startMessageRollbackDurationInSec should be consider only once when consumer connects to first time long startMessageRollbackDuration = (startMessageRollbackDurationInSec > 0 && startMessageId.equals(initialStartMessageId)) ? startMessageRollbackDurationInSec : 0; + log.info("ConsumerImpl.connectionOpened(..)09"); ByteBuf request = Commands.newSubscribe(topic, subscription, consumerId, requestId, getSubType(), priorityLevel, consumerName, isDurable, startMessageIdData, metadata, readCompacted, conf.isReplicateSubscriptionState(), InitialPosition.valueOf(subscriptionInitialPosition.getValue()), startMessageRollbackDuration, si, createTopicIfDoesNotExist, conf.getKeySharedPolicy()); + log.info("ConsumerImpl.connectionOpened(..)10"); if (startMessageIdData != null) { + log.info("ConsumerImpl.connectionOpened(..)25"); startMessageIdData.recycle(); + log.info("ConsumerImpl.connectionOpened(..)26"); } + log.info("ConsumerImpl.connectionOpened(..)11"); cnx.sendRequestWithId(request, requestId).thenRun(() -> { + log.info("ConsumerImpl.connectionOpened(..)22"); synchronized (ConsumerImpl.this) { + log.info("ConsumerImpl.connectionOpened(..)12"); if (changeToReadyState()) { consumerIsReconnectedToBroker(cnx, currentSize); + log.info("ConsumerImpl.connectionOpened(..)13"); } else { // Consumer was closed while reconnecting, close the connection to make sure the broker // drops the consumer on its side + log.info("ConsumerImpl.connectionOpened(..)14"); setState(State.Closed); cnx.removeConsumer(consumerId); cnx.channel().close(); return; } } + log.info("ConsumerImpl.connectionOpened(..)23"); resetBackoff(); + log.info("ConsumerImpl.connectionOpened(..)24"); boolean firstTimeConnect = subscribeFuture.complete(this); + log.info("ConsumerImpl.connectionOpened(..)15"); // if the consumer is not partitioned or is re-connected and is partitioned, we send the flow // command to receive messages. // For readers too (isDurable==false), the partition idx will be set though we have to // send available permits immediately after establishing the reader session if (!(firstTimeConnect && hasParentConsumer && isDurable) && conf.getReceiverQueueSize() != 0) { + log.info("ConsumerImpl.connectionOpened(..)16"); sendFlowPermitsToBroker(cnx, conf.getReceiverQueueSize()); } }).exceptionally((e) -> { cnx.removeConsumer(consumerId); if (getState() == State.Closing || getState() == State.Closed) { + log.info("ConsumerImpl.connectionOpened(..)17"); // Consumer was closed while reconnecting, close the connection to make sure the broker // drops the consumer on its side cnx.channel().close(); @@ -631,8 +652,10 @@ public void connectionOpened(final ClientCnx cnx) { && getConnectionHandler().isRetriableError((PulsarClientException) e.getCause()) && System.currentTimeMillis() < subscribeTimeout) { reconnectLater(e.getCause()); + log.info("ConsumerImpl.connectionOpened(..)18"); } else if (!subscribeFuture.isDone()) { // unable to create new consumer, fail operation + log.info("ConsumerImpl.connectionOpened(..)19"); setState(State.Failed); closeConsumerTasks(); subscribeFuture.completeExceptionally( @@ -646,12 +669,14 @@ && getConnectionHandler().isRetriableError((PulsarClientException) e.getCause()) // * Regular consumer after topic is manually delete and with // auto-topic-creation set to false // No more retries are needed in this case. + log.info("ConsumerImpl.connectionOpened(..)20"); setState(State.Failed); client.cleanupConsumer(this); log.warn("[{}][{}] Closed consumer because topic does not exist anymore {}", topic, subscription, cnx.channel().remoteAddress()); } else { // consumer was subscribed and connected but we got some error, keep trying reconnectLater(e.getCause()); + log.info("ConsumerImpl.connectionOpened(..)21"); } return null; }); diff --git a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ParserProxyHandler.java b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ParserProxyHandler.java index c168676eedf8d..19c15dc167748 100644 --- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ParserProxyHandler.java +++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ParserProxyHandler.java @@ -172,24 +172,29 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) { } finally { - if (cmdBuilder != null) { - cmdBuilder.recycle(); + try{ + if (cmdBuilder != null) { + cmdBuilder.recycle(); + } + if (cmd != null) { + cmd.recycle(); + } + buffer.resetReaderIndex(); + buffer.resetWriterIndex(); + + // add totalSize to buffer Head + ByteBuf totalSizeBuf = Unpooled.buffer(4); + totalSizeBuf.writeInt(buffer.readableBytes()); + CompositeByteBuf compBuf = Unpooled.compositeBuffer(); + compBuf.addComponents(totalSizeBuf,buffer); + compBuf.writerIndex(totalSizeBuf.capacity()+buffer.capacity()); + + //next handler + ctx.fireChannelRead(compBuf); + } catch (Exception e) { + log.error("{},{},{}" , e.getMessage() , e.getStackTrace() , e.getCause()); } - if (cmd != null) { - cmd.recycle(); - } - buffer.resetReaderIndex(); - buffer.resetWriterIndex(); - - // add totalSize to buffer Head - ByteBuf totalSizeBuf = Unpooled.buffer(4); - totalSizeBuf.writeInt(buffer.readableBytes()); - CompositeByteBuf compBuf = Unpooled.compositeBuffer(); - compBuf.addComponents(totalSizeBuf,buffer); - compBuf.writerIndex(totalSizeBuf.capacity()+buffer.capacity()); - - //next handler - ctx.fireChannelRead(compBuf); + } } diff --git a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java index e1a5a0172f85e..40e8663b23a29 100644 --- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java +++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java @@ -20,6 +20,8 @@ import static com.google.common.base.Preconditions.checkArgument; +import java.io.PrintWriter; +import java.io.StringWriter; import java.net.SocketAddress; import java.util.concurrent.TimeUnit; @@ -121,11 +123,15 @@ public ProxyConnection(ProxyService proxyService, SslContext sslCtx) { @Override public void channelRegistered(ChannelHandlerContext ctx) throws Exception { + LOG.info("ProxyConnection.channelRegistered(..)01"); super.channelRegistered(ctx); + LOG.info("ProxyConnection.channelRegistered(..)02"); ProxyService.activeConnections.inc(); if (ProxyService.activeConnections.get() > service.getConfiguration().getMaxConcurrentInboundConnections()) { + LOG.info("ProxyConnection.channelRegistered(..)03"); ctx.close(); ProxyService.rejectedConnections.inc(); + LOG.info("ProxyConnection.channelRegistered(..)04"); return; } } @@ -138,7 +144,9 @@ public void channelUnregistered(ChannelHandlerContext ctx) throws Exception { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { + LOG.info("ProxyConnection.channelActive(..)01"); super.channelActive(ctx); + LOG.info("ProxyConnection.channelActive(..)02"); ProxyService.newConnections.inc(); service.getClientCnxs().add(this); LOG.info("[{}] New connection opened", remoteAddress); @@ -384,6 +392,26 @@ protected void handleGetSchema(CommandGetSchema commandGetSchema) { lookupProxyHandler.handleGetSchema(commandGetSchema); } + @Override + protected void handleSubscribe(PulsarApi.CommandSubscribe subscribe) { + LOG.info("ERROR: We are calling handleSubscribe(..) on ProxyConnection! This shouldn't happen!"); + StringWriter sw = new StringWriter(); + new Throwable("").printStackTrace(new PrintWriter(sw)); + String stackTrace = sw.toString(); + LOG.info("Stacktrace is: " + stackTrace); + super.handleSubscribe(subscribe); + } + + @Override + protected void handleProducer(PulsarApi.CommandProducer producer) { + LOG.info("ERROR: We are calling handleProducer(..) on ProxyConnection! This shouldn't happen!"); + StringWriter sw = new StringWriter(); + new Throwable("").printStackTrace(new PrintWriter(sw)); + String stackTrace = sw.toString(); + LOG.info("Stacktrace is: " + stackTrace); + super.handleProducer(producer); + } + /** * handles discovery request from client ands sends next active broker address */ diff --git a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyLookupThrottlingTest.java b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyLookupThrottlingTest.java index 8949f8df34995..4bb6865b25d85 100644 --- a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyLookupThrottlingTest.java +++ b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyLookupThrottlingTest.java @@ -22,6 +22,7 @@ import static org.testng.Assert.assertTrue; import java.util.Optional; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import lombok.Cleanup; @@ -71,6 +72,14 @@ protected void cleanup() throws Exception { internalCleanup(); proxyService.close(); } + // Perhaps it would be better to import this method from PulsarTestBase in tests.integration + public static String randomName(int numChars) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < numChars; i++) { + sb.append((char) (ThreadLocalRandom.current().nextInt(26) + 'a')); + } + return sb.toString(); + } @Test public void testLookup() throws Exception { @@ -83,14 +92,15 @@ public void testLookup() throws Exception { .build(); assertTrue(proxyService.getLookupRequestSemaphore().tryAcquire()); assertTrue(proxyService.getLookupRequestSemaphore().tryAcquire()); + String randSeed = randomName(16); @Cleanup - Producer producer1 = client.newProducer(Schema.BYTES).topic("persistent://sample/test/local/producer-topic") + Producer producer1 = client.newProducer(Schema.BYTES).topic("persistent://sample/test/local/producer-topic" + randSeed) .create(); assertTrue(proxyService.getLookupRequestSemaphore().tryAcquire()); try { @Cleanup - Producer producer2 = client.newProducer(Schema.BYTES).topic("persistent://sample/test/local/producer-topic") + Producer producer2 = client.newProducer(Schema.BYTES).topic("persistent://sample/test/local/producer-topic" + randSeed) .create(); Assert.fail("Should have failed since can't acquire LookupRequestSemaphore"); } catch (Exception ex) { @@ -100,7 +110,7 @@ public void testLookup() throws Exception { proxyService.getLookupRequestSemaphore().release(); try { @Cleanup - Producer producer3 = client.newProducer(Schema.BYTES).topic("persistent://sample/test/local/producer-topic") + Producer producer3 = client.newProducer(Schema.BYTES).topic("persistent://sample/test/local/producer-topic" + randSeed) .create(); } catch (Exception ex) { Assert.fail("Should not have failed since can acquire LookupRequestSemaphore"); diff --git a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyParserTest.java b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyParserTest.java index 907dc787451a8..a30fdcb061403 100644 --- a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyParserTest.java +++ b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyParserTest.java @@ -29,6 +29,7 @@ import java.util.Optional; import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import lombok.Cleanup; @@ -127,7 +128,7 @@ public void testProducerConsumer() throws Exception { } for (int i = 0; i < 10; i++) { - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(5, TimeUnit.SECONDS); checkNotNull(msg); consumer.acknowledge(msg); } @@ -139,21 +140,33 @@ public void testProducerConsumer() throws Exception { client.close(); } + public static String randomName(int numChars) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < numChars; i++) { + sb.append((char) (ThreadLocalRandom.current().nextInt(26) + 'a')); + } + return sb.toString(); + } + @Test public void testPartitions() throws Exception { + String randSeed = randomName(16); TenantInfo tenantInfo = createDefaultTenantInfo(); - admin.tenants().createTenant("sample", tenantInfo); + String topicName = "persistent://sample/test/local/partitioned-topic" + randSeed; + if(!admin.tenants().getTenants().contains("sample")){ + admin.tenants().createTenant("sample", tenantInfo); + } PulsarClient client = PulsarClient.builder().serviceUrl(proxyService.getServiceUrl()) .build(); - admin.topics().createPartitionedTopic("persistent://sample/test/local/partitioned-topic", 2); + admin.topics().createPartitionedTopic(topicName, 2); Producer producer = client.newProducer(Schema.BYTES) - .topic("persistent://sample/test/local/partitioned-topic") + .topic(topicName) .enableBatching(false) .messageRoutingMode(MessageRoutingMode.RoundRobinPartition).create(); // Create a consumer directly attached to broker - Consumer consumer = pulsarClient.newConsumer().topic("persistent://sample/test/local/partitioned-topic") + Consumer consumer = pulsarClient.newConsumer().topic(topicName) .subscriptionName("my-sub").subscribe(); for (int i = 0; i < 10; i++) { @@ -161,14 +174,14 @@ public void testPartitions() throws Exception { } for (int i = 0; i < 10; i++) { - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(5, TimeUnit.SECONDS); checkNotNull(msg); } client.close(); } - @Test + @Test(invocationCount = 10) public void testRegexSubscription() throws Exception { @Cleanup PulsarClient client = PulsarClient.builder().serviceUrl(proxyService.getServiceUrl()) @@ -214,7 +227,7 @@ public void testRegexSubscription() throws Exception { } @Test - private void testProtocolVersionAdvertisement() throws Exception { + public void testProtocolVersionAdvertisement() throws Exception { final String topic = "persistent://sample/test/local/protocol-version-advertisement"; final String sub = "my-sub"; diff --git a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTest.java b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTest.java index 7b308d198e401..a311e03880bc6 100644 --- a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTest.java +++ b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTest.java @@ -150,7 +150,7 @@ public void testProducerConsumer() throws Exception { } for (int i = 0; i < 10; i++) { - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(); checkNotNull(msg); consumer.acknowledge(msg); } @@ -184,7 +184,7 @@ public void testPartitions() throws Exception { } for (int i = 0; i < 10; i++) { - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(); checkNotNull(msg); } } diff --git a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTlsTest.java b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTlsTest.java index 847e6a569ca6e..69fedfb19f170 100644 --- a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTlsTest.java +++ b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTlsTest.java @@ -114,7 +114,7 @@ public void testPartitions() throws Exception { } for (int i = 0; i < 10; i++) { - Message msg = consumer.receive(1, TimeUnit.SECONDS); + Message msg = consumer.receive(5, TimeUnit.SECONDS); checkNotNull(msg); } diff --git a/pulsar-sql/presto-pulsar/src/test/java/org/apache/pulsar/sql/presto/TestPulsarConnector.java b/pulsar-sql/presto-pulsar/src/test/java/org/apache/pulsar/sql/presto/TestPulsarConnector.java index adeababe481e8..8cadfca388526 100644 --- a/pulsar-sql/presto-pulsar/src/test/java/org/apache/pulsar/sql/presto/TestPulsarConnector.java +++ b/pulsar-sql/presto-pulsar/src/test/java/org/apache/pulsar/sql/presto/TestPulsarConnector.java @@ -193,7 +193,7 @@ public static class Boo { public Foo foo; public Boo boo; public Bar bar; - // different namespace with same classname should work though + // different namespace with same classname should work though. public Foo.Bar foobar; } diff --git a/tests/integration/pom.xml b/tests/integration/pom.xml index 4a3016e42e888..e10ec558ecee1 100644 --- a/tests/integration/pom.xml +++ b/tests/integration/pom.xml @@ -37,6 +37,16 @@ + + org.testng + testng + test + + + org.awaitility + awaitility + test + com.google.code.gson gson diff --git a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/functions/PulsarFunctionsTest.java b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/functions/PulsarFunctionsTest.java index e18a2ee320efe..b2782d1abadbe 100644 --- a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/functions/PulsarFunctionsTest.java +++ b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/functions/PulsarFunctionsTest.java @@ -83,10 +83,10 @@ @Slf4j public abstract class PulsarFunctionsTest extends PulsarFunctionsTestBase { - final Duration ONE_MINUTE = Duration.ofMinutes(1); - final Duration TEN_SECONDS = Duration.ofSeconds(10); + final Duration ONE_MINUTE = Duration.ofMinutes(1); + final Duration TEN_SECONDS = Duration.ofSeconds(10); - final RetryPolicy statusRetryPolicy = new RetryPolicy() + final RetryPolicy statusRetryPolicy = new RetryPolicy() .withMaxDuration(ONE_MINUTE) .withDelay(TEN_SECONDS) .onRetry(e -> log.error("Retry ... ")); diff --git a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/functions/PulsarStateTest.java b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/functions/PulsarStateTest.java index 2e386ebe6ba1e..6b76710f416a9 100644 --- a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/functions/PulsarStateTest.java +++ b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/functions/PulsarStateTest.java @@ -116,7 +116,7 @@ public void testSourceState() throws Exception { } catch (PulsarAdminException e) { return false; } - }, 10, 200); + }, 20, 400); SourceStatus status = admin.sources().getSourceStatus("public", "default", sourceName); assertEquals(status.getInstances().size(), 1); @@ -173,7 +173,7 @@ public void testSinkState() throws Exception { } catch (PulsarAdminException e) { return false; } - }, 10, 200); + }, 20, 400); SinkStatus status = admin.sinks().getSinkStatus("public", "default", sinkName); assertEquals(status.getInstances().size(), 1); diff --git a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/io/SourceTester.java b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/io/SourceTester.java index 5040de5577e3b..f662c6b351c2e 100644 --- a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/io/SourceTester.java +++ b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/io/SourceTester.java @@ -73,7 +73,7 @@ public Map sourceConfig() { public void validateSourceResult(Consumer> consumer, int number, String eventType) throws Exception { int recordsNumber = 0; - Message> msg = consumer.receive(2, TimeUnit.SECONDS); + Message> msg = consumer.receive(5, TimeUnit.SECONDS); while(msg != null) { recordsNumber ++; final String key = new String(msg.getValue().getKey()); @@ -85,7 +85,7 @@ public void validateSourceResult(Consumer> consumer, in Assert.assertTrue(value.contains(this.eventContains(eventType))); } consumer.acknowledge(msg); - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); } Assert.assertEquals(recordsNumber, number); diff --git a/tests/pulsar-kafka-compat-client-test/src/test/java/org/apache/pulsar/tests/integration/compat/kafka/KafkaApiTest.java b/tests/pulsar-kafka-compat-client-test/src/test/java/org/apache/pulsar/tests/integration/compat/kafka/KafkaApiTest.java index fafb1bc66306e..adc583caf8622 100644 --- a/tests/pulsar-kafka-compat-client-test/src/test/java/org/apache/pulsar/tests/integration/compat/kafka/KafkaApiTest.java +++ b/tests/pulsar-kafka-compat-client-test/src/test/java/org/apache/pulsar/tests/integration/compat/kafka/KafkaApiTest.java @@ -588,7 +588,7 @@ public void testSimpleProducer() throws Exception { producer.close(); for (int i = 0; i < 10; i++) { - Message msg = pulsarConsumer.receive(1, TimeUnit.SECONDS); + Message msg = pulsarConsumer.receive(5, TimeUnit.SECONDS); assertEquals(new String(msg.getData()), "hello-" + i); pulsarConsumer.acknowledge(msg); } @@ -627,7 +627,7 @@ public void testProducerCallback() throws Exception { counter.await(); for (int i = 0; i < 10; i++) { - Message msg = pulsarConsumer.receive(1, TimeUnit.SECONDS); + Message msg = pulsarConsumer.receive(5, TimeUnit.SECONDS); assertEquals(new String(msg.getData()), "hello-" + i); pulsarConsumer.acknowledge(msg); } @@ -667,7 +667,7 @@ public void testProducerAvroSchemaWithPulsarKafkaClient() throws Exception { producer.close(); for (int i = 0; i < 10; i++) { - Message msg = pulsarConsumer.receive(1, TimeUnit.SECONDS); + Message msg = pulsarConsumer.receive(5, TimeUnit.SECONDS); Foo value = fooSchema.decode(msg.getValue()); Assert.assertEquals(value.getField1(), "field1"); Assert.assertEquals(value.getField2(), "field2"); diff --git a/tests/pulsar-storm-test/src/test/java/org/apache/pulsar/storm/PulsarBoltTest.java b/tests/pulsar-storm-test/src/test/java/org/apache/pulsar/storm/PulsarBoltTest.java index f74f066dd1797..315b9afa288c7 100644 --- a/tests/pulsar-storm-test/src/test/java/org/apache/pulsar/storm/PulsarBoltTest.java +++ b/tests/pulsar-storm-test/src/test/java/org/apache/pulsar/storm/PulsarBoltTest.java @@ -154,7 +154,7 @@ public void testNoMessageSend() throws Exception { Tuple tuple = getMockTuple(msgContent); bolt.execute(tuple); Assert.assertTrue(mockCollector.acked()); - Message msg = consumer.receive(5, TimeUnit.SECONDS); + Message msg = consumer.receive(10, TimeUnit.MILLISECONDS); Assert.assertNull(msg); } diff --git a/tests/pulsar-storm-test/src/test/java/org/apache/pulsar/storm/example/StormExample.java b/tests/pulsar-storm-test/src/test/java/org/apache/pulsar/storm/example/StormExample.java index 93404ea7789cf..1add47bf14721 100644 --- a/tests/pulsar-storm-test/src/test/java/org/apache/pulsar/storm/example/StormExample.java +++ b/tests/pulsar-storm-test/src/test/java/org/apache/pulsar/storm/example/StormExample.java @@ -135,7 +135,7 @@ public static void main(String[] args) throws Exception { } Message msg = null; for (int i = 0; i < 10; i++) { - msg = consumer.receive(1, TimeUnit.SECONDS); + msg = consumer.receive(5, TimeUnit.SECONDS); LOG.info("Message {} received", new String(msg.getData())); } cluster.killTopology("test");