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

penghui 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 fb45a14  Test Cleanup (#10009)
fb45a14 is described below

commit fb45a1476ebdb74d8028e708c076d44a3d09445c
Author: Ali Ahmed <[email protected]>
AuthorDate: Mon Mar 22 22:39:12 2021 -0700

    Test Cleanup (#10009)
---
 .../apache/pulsar/broker/admin/AdminApiTest2.java  | 69 +++++++++++-----------
 .../broker/auth/MockedPulsarServiceBaseTest.java   |  6 +-
 2 files changed, 34 insertions(+), 41 deletions(-)

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 abb916a..7087c1a 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
@@ -346,7 +346,7 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         consumer.close();
 
         topicStats = admin.topics().getStats(persistentTopicName);
-        assertTrue(topicStats.subscriptions.keySet().contains("my-sub"));
+        assertTrue(topicStats.subscriptions.containsKey("my-sub"));
         assertEquals(topicStats.publishers.size(), 0);
 
         // test partitioned-topic
@@ -377,12 +377,12 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
      * @throws Exception
      */
     @Test
-    public void testSetPersistencepolicies() throws Exception {
+    public void testSetPersistencePolicies() throws Exception {
 
         final String namespace = "prop-xyz/ns2";
         admin.namespaces().createNamespace(namespace, Sets.newHashSet("test"));
 
-        assertEquals(admin.namespaces().getPersistence(namespace), null);
+        assertNull(admin.namespaces().getPersistence(namespace));
         admin.namespaces().setPersistence(namespace, new 
PersistencePolicies(3, 3, 3, 10.0));
         assertEquals(admin.namespaces().getPersistence(namespace), new 
PersistencePolicies(3, 3, 3, 10.0));
 
@@ -446,10 +446,8 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         assertEquals(cursor.getThrottleMarkDelete(), newThrottleRate);
 
         // (2) verify new ledger creation takes new config
-
         producer.close();
         consumer.close();
-
     }
 
     /**
@@ -472,7 +470,7 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         final boolean isPersistentTopic = topic instanceof PersistentTopic;
 
         // (1) unload the topic
-        unloadTopic(topicName, isPersistentTopic);
+        unloadTopic(topicName);
 
         // topic must be removed from map
         
assertFalse(pulsar.getBrokerService().getTopicReference(topicName).isPresent());
@@ -482,7 +480,7 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         topic = pulsar.getBrokerService().getTopicReference(topicName).get();
         assertNotNull(topic);
         // unload the topic
-        unloadTopic(topicName, isPersistentTopic);
+        unloadTopic(topicName);
         // producer will retry and recreate the topic
         for (int i = 0; i < 5; i++) {
             if 
(!pulsar.getBrokerService().getTopicReference(topicName).isPresent() || i != 4) 
{
@@ -494,7 +492,7 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         assertNotNull(topic);
     }
 
-    private void unloadTopic(String topicName, boolean isPersistentTopic) 
throws Exception {
+    private void unloadTopic(String topicName) throws Exception {
         admin.topics().unload(topicName);
     }
 
@@ -545,7 +543,10 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         consumer.close();
 
         // messages should still be available due to retention
-        MessageIdImpl messageId = new 
MessageIdImpl(resetMessageId.getLedgerId(), resetMessageId.getEntryId(), -1);
+        MessageIdImpl messageId = new MessageIdImpl(
+                resetMessageId.getLedgerId(),
+                resetMessageId.getEntryId(),
+                -1);
         // reset position at resetMessageId
         admin.topics().resetCursor(topicName, "my-sub", messageId);
 
@@ -619,7 +620,6 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         
this.conf.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
         MockedPulsarService mockPulsarSetup1 = new 
MockedPulsarService(this.conf);
         mockPulsarSetup1.setup();
-        PulsarService simpleLoadManager = mockPulsarSetup1.getPulsar();
         PulsarAdmin simpleLoadManagerAdmin = mockPulsarSetup1.getAdmin();
         assertNotNull(simpleLoadManagerAdmin.brokerStats().getLoadReport());
 
@@ -892,7 +892,7 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
     }
 
     @Test
-    public void testTenantNameWithInvalidCharacters() throws Exception {
+    public void testTenantNameWithInvalidCharacters() {
         TenantInfo tenantInfo = new TenantInfo(Sets.newHashSet("role1", 
"role2"), Sets.newHashSet("test"));
 
         // If we try to create property with invalid characters, it should 
fail immediately
@@ -951,15 +951,15 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         String brokerName = pulsar.getAdvertisedAddress();
         String brokerAddress = brokerName + ":" + 
pulsar.getConfiguration().getWebServicePort().get();
         NamespaceIsolationData nsPolicyData1 = new NamespaceIsolationData();
-        nsPolicyData1.namespaces = new ArrayList<String>();
+        nsPolicyData1.namespaces = new ArrayList<>();
         nsPolicyData1.namespaces.add(namespaceRegex);
-        nsPolicyData1.primary = new ArrayList<String>();
+        nsPolicyData1.primary = new ArrayList<>();
         nsPolicyData1.primary.add(brokerName + ":[0-9]*");
-        nsPolicyData1.secondary = new ArrayList<String>();
+        nsPolicyData1.secondary = new ArrayList<>();
         nsPolicyData1.secondary.add(brokerName + ".*");
         nsPolicyData1.auto_failover_policy = new AutoFailoverPolicyData();
         nsPolicyData1.auto_failover_policy.policy_type = 
AutoFailoverPolicyType.min_available;
-        nsPolicyData1.auto_failover_policy.parameters = new HashMap<String, 
String>();
+        nsPolicyData1.auto_failover_policy.parameters = new HashMap<>();
         nsPolicyData1.auto_failover_policy.parameters.put("min_limit", "1");
         nsPolicyData1.auto_failover_policy.parameters.put("usage_threshold", 
"100");
         admin.clusters().createNamespaceIsolationPolicy(cluster, policyName1, 
nsPolicyData1);
@@ -999,15 +999,14 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         // create
         String policyName1 = "policy-1";
         String cluster = pulsar.getConfiguration().getClusterName();
-        String namespaceRegex = ns1Name;
         NamespaceIsolationData nsPolicyData1 = new NamespaceIsolationData();
-        nsPolicyData1.namespaces = new ArrayList<String>();
+        nsPolicyData1.namespaces = new ArrayList<>();
         nsPolicyData1.namespaces.add(ns1Name);
-        nsPolicyData1.primary = new ArrayList<String>();
+        nsPolicyData1.primary = new ArrayList<>();
         nsPolicyData1.primary.add(brokerName + ".*");
         nsPolicyData1.auto_failover_policy = new AutoFailoverPolicyData();
         nsPolicyData1.auto_failover_policy.policy_type = 
AutoFailoverPolicyType.min_available;
-        nsPolicyData1.auto_failover_policy.parameters = new HashMap<String, 
String>();
+        nsPolicyData1.auto_failover_policy.parameters = new HashMap<>();
         nsPolicyData1.auto_failover_policy.parameters.put("min_limit", "1");
         nsPolicyData1.auto_failover_policy.parameters.put("usage_threshold", 
"100");
         admin.clusters().createNamespaceIsolationPolicyAsync(cluster, 
policyName1, nsPolicyData1).get();
@@ -1018,7 +1017,7 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         log.info(" 1 get lookup url {}", brokerUrl);
 
         //  2. update isolation policy, without broker matched, lookup will 
fail.
-        nsPolicyData1.primary = new ArrayList<String>();
+        nsPolicyData1.primary = new ArrayList<>();
         nsPolicyData1.primary.add(brokerName + "not_match");
         admin.clusters().updateNamespaceIsolationPolicyAsync(cluster, 
policyName1, nsPolicyData1).get();
 
@@ -1048,7 +1047,7 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
     /**
      * verifies cluster has been set before create topic
      *
-     * @throws Exception
+     * @throws PulsarAdminException
      */
     @Test
     public void testClusterIsReadyBeforeCreateTopic() throws 
PulsarAdminException {
@@ -1065,12 +1064,13 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         try {
             
admin.topics().createPartitionedTopic(persistentPartitionedTopicName, 
partitions);
             Assert.fail("should have failed due to Namespace does not have any 
clusters configured");
-        } catch (PulsarAdminException.PreconditionFailedException e) {
+        } catch (PulsarAdminException.PreconditionFailedException ignored) {
         }
+
         try {
             
admin.topics().createPartitionedTopic(NonPersistentPartitionedTopicName, 
partitions);
             Assert.fail("should have failed due to Namespace does not have any 
clusters configured");
-        } catch (PulsarAdminException.PreconditionFailedException e) {
+        } catch (PulsarAdminException.PreconditionFailedException ignored) {
         }
     }
 
@@ -1183,8 +1183,7 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         assertTrue(consumedTimestamp < lastConsumedTimestamp);
         assertTrue(ackedTimestamp < lastAckedTimestamp);
         assertTrue(startConsumedTimestampInConsumerStats < 
lastConsumedTimestamp);
-        assertTrue(startAckedTimestampInConsumerStats < lastAckedTimestamp);
-        assertTrue(consumedFlowTimestamp == lastConsumedFlowTimestamp);
+        assertEquals(lastConsumedFlowTimestamp, consumedFlowTimestamp);
         assertTrue(ackedTimestampInSubStats < lastAckedTimestampInSubStats);
         assertEquals(lastConsumedTimestamp, lastConsumedTimestampInSubStats);
 
@@ -1295,7 +1294,7 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
     }
 
     @Test
-    public void testPreciseBacklogForPartitionedTopic() throws 
PulsarClientException, PulsarAdminException, InterruptedException {
+    public void testPreciseBacklogForPartitionedTopic() throws 
PulsarClientException, PulsarAdminException {
         final String topic = 
"persistent://prop-xyz/ns1/precise-back-log-for-partitioned-topic";
         admin.topics().createPartitionedTopic(topic, 2);
         final String subName = "sub-name";
@@ -1468,7 +1467,6 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         for (int i = 0; i < 10; i++) {
             admin.namespaces().createNamespace("testTenant/ns-" + i, 
Sets.newHashSet("test"));
         }
-
     }
 
     @Test
@@ -1796,8 +1794,8 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         try {
             pulsarClient.newProducer().topic(topic).create();
             fail("should fail");
-        } catch (PulsarClientException ignore) {
-            assertTrue(ignore.getMessage().contains("Topic reached max 
producers limit"));
+        } catch (PulsarClientException e) {
+            assertTrue(e.getMessage().contains("Topic reached max producers 
limit"));
         }
         //set the limit to 3
         admin.namespaces().setMaxProducersPerTopic(myNamespace, 3);
@@ -1809,8 +1807,8 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         try {
             pulsarClient.newProducer().topic(topic).create();
             fail("should fail");
-        } catch (PulsarClientException ignore) {
-            assertTrue(ignore.getMessage().contains("Topic reached max 
producers limit"));
+        } catch (PulsarClientException e) {
+            assertTrue(e.getMessage().contains("Topic reached max producers 
limit"));
         }
 
         //clean up
@@ -1852,8 +1850,8 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         try {
             
pulsarClient.newConsumer().subscriptionName(UUID.randomUUID().toString()).topic(topic).subscribe();
             fail("should fail");
-        } catch (PulsarClientException ignore) {
-            assertTrue(ignore.getMessage().contains("Topic reached max 
consumers limit"));
+        } catch (PulsarClientException e) {
+            assertTrue(e.getMessage().contains("Topic reached max consumers 
limit"));
         }
         //set the limit to 3
         admin.namespaces().setMaxConsumersPerTopic(myNamespace, 3);
@@ -1866,8 +1864,8 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         try {
             
pulsarClient.newConsumer().subscriptionName(UUID.randomUUID().toString()).topic(topic).subscribe();
             fail("should fail");
-        } catch (PulsarClientException ignore) {
-            assertTrue(ignore.getMessage().contains("Topic reached max 
consumers limit"));
+        } catch (PulsarClientException e) {
+            assertTrue(e.getMessage().contains("Topic reached max consumers 
limit"));
         }
 
         //clean up
@@ -1946,5 +1944,4 @@ public class AdminApiTest2 extends 
MockedPulsarServiceBaseTest {
         verify(mockTopic, times(2)).triggerCompaction();
     }
 
-
 }
diff --git 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockedPulsarServiceBaseTest.java
 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockedPulsarServiceBaseTest.java
index 4e0a7ee..a89f88e 100644
--- 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockedPulsarServiceBaseTest.java
+++ 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockedPulsarServiceBaseTest.java
@@ -103,7 +103,6 @@ public abstract class MockedPulsarServiceBaseTest extends 
TestRetrySupport {
         this.conf = getDefaultConf();
     }
 
-
     protected final void internalSetup() throws Exception {
         incrementSetupNumber();
         init();
@@ -269,9 +268,7 @@ public abstract class MockedPulsarServiceBaseTest extends 
TestRetrySupport {
 
     protected PulsarService startBroker(ServiceConfiguration conf) throws 
Exception {
 
-        PulsarService pulsar = startBrokerWithoutAuthorization(conf);
-
-        return pulsar;
+        return startBrokerWithoutAuthorization(conf);
     }
 
     protected PulsarService 
startBrokerWithoutAuthorization(ServiceConfiguration conf) throws Exception {
@@ -424,7 +421,6 @@ public abstract class MockedPulsarServiceBaseTest extends 
TestRetrySupport {
         configuration.setAdvertisedAddress("localhost");
         configuration.setClusterName(configClusterName);
         // there are TLS tests in here, they need to use localhost because of 
the certificate
-        configuration.setAdvertisedAddress("localhost");
         configuration.setManagedLedgerCacheSizeMB(8);
         configuration.setActiveConsumerFailoverDelayTimeMillis(0);
         configuration.setDefaultNumberOfNamespaceBundles(1);

Reply via email to