You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by bo...@apache.org on 2022/09/28 10:00:53 UTC

[pulsar] branch master updated: [fix][flask-test] Fix and improve LookupRetryTest (#17848)

This is an automated email from the ASF dual-hosted git repository.

bogong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 31203c3952d [fix][flask-test] Fix and improve LookupRetryTest (#17848)
31203c3952d is described below

commit 31203c3952dfb82057ac1fbee4efc10682a5570b
Author: Cong Zhao <zh...@apache.org>
AuthorDate: Wed Sep 28 18:00:40 2022 +0800

    [fix][flask-test] Fix and improve LookupRetryTest (#17848)
    
    Fixes #17785
    
    ### Motivation
    
    The `failureMap` need to be clear after run per unit test.
    
    ### Modifications
    
    Clear `failureMap` after run per unit test, and only run once `setup()`/`cleanup()` to reduce execution time.
    
    ### Matching PR in forked repository
    
    PR in forked repository: https://github.com/coderzc/pulsar/pull/6
---
 .../apache/pulsar/client/impl/LookupRetryTest.java  | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/LookupRetryTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/LookupRetryTest.java
index 270d838b61c..448f099c386 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/LookupRetryTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/LookupRetryTest.java
@@ -20,14 +20,12 @@ package org.apache.pulsar.client.impl;
 
 import static org.apache.pulsar.common.protocol.Commands.newLookupErrorResponse;
 import static org.apache.pulsar.common.protocol.Commands.newPartitionMetadataResponse;
-
 import com.google.common.collect.Sets;
 import java.util.Queue;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
-
 import org.apache.pulsar.broker.PulsarService;
 import org.apache.pulsar.broker.ServiceConfiguration;
 import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest;
@@ -44,20 +42,18 @@ import org.apache.pulsar.common.api.proto.ServerError;
 import org.apache.pulsar.common.naming.TopicName;
 import org.apache.pulsar.common.policies.data.ClusterData;
 import org.apache.pulsar.common.policies.data.TenantInfoImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 public class LookupRetryTest extends MockedPulsarServiceBaseTest {
-    private static final Logger log = LoggerFactory.getLogger(LookupRetryTest.class);
     private static final String subscription = "reader-sub";
     private final AtomicInteger connectionsCreated = new AtomicInteger(0);
     private final ConcurrentHashMap<String, Queue<LookupError>> failureMap = new ConcurrentHashMap<>();
 
-    @BeforeMethod
+    @BeforeClass
     @Override
     protected void setup() throws Exception {
         conf.setTopicLevelPoliciesEnabled(false);
@@ -69,8 +65,6 @@ public class LookupRetryTest extends MockedPulsarServiceBaseTest {
         admin.tenants().createTenant("public",
                 new TenantInfoImpl(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("test")));
         admin.namespaces().createNamespace("public/default", Sets.newHashSet("test"));
-
-        connectionsCreated.set(0);
     }
 
     @Override
@@ -94,12 +88,18 @@ public class LookupRetryTest extends MockedPulsarServiceBaseTest {
         };
     }
 
-    @AfterMethod(alwaysRun = true)
+    @AfterClass(alwaysRun = true)
     @Override
     protected void cleanup() throws Exception {
         super.internalCleanup();
     }
 
+    @BeforeMethod(alwaysRun = true)
+    public void reset() {
+        connectionsCreated.set(0);
+        failureMap.clear();
+    }
+
     PulsarClient newClient() throws Exception {
         return PulsarClient.builder()
             .serviceUrl(pulsar.getBrokerServiceUrl())
@@ -244,7 +244,6 @@ public class LookupRetryTest extends MockedPulsarServiceBaseTest {
 
         try (PulsarClient pulsarClient = PulsarClient.builder().serviceUrl(lookupUrl)
                 .maxNumberOfRejectedRequestPerConnection(100)
-                .maxNumberOfRejectedRequestPerConnection(1)
                 .connectionTimeout(2, TimeUnit.SECONDS)
                 .operationTimeout(1, TimeUnit.SECONDS)
                 .lookupTimeout(10, TimeUnit.SECONDS)