You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2019/03/02 04:19:05 UTC
[pulsar] branch master updated: Fix Test localhost resolution
errors (#3730)
This is an automated email from the ASF dual-hosted git repository.
mmerli 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 40aecc1 Fix Test localhost resolution errors (#3730)
40aecc1 is described below
commit 40aecc1b33e3cc59151aee84bbef2983641b4039
Author: Ali Ahmed <al...@gmail.com>
AuthorDate: Fri Mar 1 20:18:58 2019 -0800
Fix Test localhost resolution errors (#3730)
---
.../org/apache/pulsar/broker/PulsarService.java | 15 +++--
.../broker/auth/MockedPulsarServiceBaseTest.java | 16 +++--
.../broker/loadbalance/LoadBalancerTest.java | 70 +++++++++++-----------
.../loadbalance/ModularLoadManagerImplTest.java | 60 +++++++++----------
.../pulsar/client/impl/TopicFromMessageTest.java | 5 --
.../worker/PulsarWorkerAssignmentTest.java | 7 +--
.../apache/pulsar/io/PulsarFunctionAdminTest.java | 2 +-
.../apache/pulsar/io/PulsarFunctionE2ETest.java | 13 ++--
.../stats/client/PulsarBrokerStatsClientTest.java | 22 ++++---
.../org/apache/pulsar/storm/PulsarSpoutTest.java | 2 +-
10 files changed, 97 insertions(+), 115 deletions(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java
index 0dccc8d..54d8092 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java
@@ -49,7 +49,6 @@ import org.apache.bookkeeper.common.util.OrderedScheduler;
import org.apache.bookkeeper.conf.ClientConfiguration;
import org.apache.bookkeeper.mledger.LedgerOffloader;
import org.apache.bookkeeper.mledger.LedgerOffloaderFactory;
-import org.apache.bookkeeper.mledger.ManagedLedgerConfig;
import org.apache.bookkeeper.mledger.ManagedLedgerFactory;
import org.apache.bookkeeper.mledger.impl.NullLedgerOffloader;
import org.apache.bookkeeper.mledger.offload.OffloaderUtils;
@@ -123,7 +122,7 @@ import org.slf4j.LoggerFactory;
public class PulsarService implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(PulsarService.class);
private ServiceConfiguration config = null;
- private NamespaceService nsservice = null;
+ private NamespaceService nsService = null;
private ManagedLedgerClientFactory managedLedgerClientFactory = null;
private LeaderElectionService leaderElectionService = null;
private BrokerService brokerService = null;
@@ -265,7 +264,7 @@ public class PulsarService implements AutoCloseable {
client = null;
}
- nsservice = null;
+ nsService = null;
if (compactorExecutor != null) {
compactorExecutor.shutdown();
@@ -421,7 +420,7 @@ public class PulsarService implements AutoCloseable {
this.webService.addStaticResources("/static", "/static");
// Register heartbeat and bootstrap namespaces.
- this.nsservice.registerBootstrapNamespaces();
+ this.nsService.registerBootstrapNamespaces();
schemaRegistryService = SchemaRegistryService.create(this);
@@ -498,14 +497,14 @@ public class PulsarService implements AutoCloseable {
boolean acquiredSLANamespace;
try {
- acquiredSLANamespace = nsservice.registerSLANamespace();
+ acquiredSLANamespace = nsService.registerSLANamespace();
LOG.info("Register SLA Namespace = {}, returned - {}.", nsName, acquiredSLANamespace);
} catch (PulsarServerException e) {
acquiredSLANamespace = false;
}
if (!acquiredSLANamespace) {
- this.nsservice.unloadSLANamespace();
+ this.nsService.unloadSLANamespace();
}
} catch (Exception ex) {
LOG.warn(
@@ -557,7 +556,7 @@ public class PulsarService implements AutoCloseable {
LOG.info("Starting name space service, bootstrap namespaces=" + config.getBootstrapNamespaces());
- this.nsservice = getNamespaceServiceProvider().get();
+ this.nsService = getNamespaceServiceProvider().get();
}
public Supplier<NamespaceService> getNamespaceServiceProvider() throws PulsarServerException {
@@ -660,7 +659,7 @@ public class PulsarService implements AutoCloseable {
* @return a reference of the current namespace service instance.
*/
public NamespaceService getNamespaceService() {
- return this.nsservice;
+ return this.nsService;
}
public WorkerService getWorkerService() {
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 c33b212..e65ce0f 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
@@ -37,7 +37,6 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.function.Supplier;
-import org.apache.bookkeeper.client.BKException;
import org.apache.bookkeeper.client.BookKeeper;
import org.apache.bookkeeper.client.PulsarMockBookKeeper;
import org.apache.bookkeeper.test.PortManager;
@@ -93,7 +92,6 @@ public abstract class MockedPulsarServiceBaseTest {
protected void resetConfig() {
this.conf = new ServiceConfiguration();
this.conf.setBrokerServicePort(BROKER_PORT);
- this.conf.setAdvertisedAddress("localhost");
this.conf.setWebServicePort(BROKER_WEBSERVICE_PORT);
this.conf.setClusterName(configClusterName);
this.conf.setAdvertisedAddress("localhost"); // there are TLS tests in here, they need to use localhost because of the certificate
@@ -158,7 +156,7 @@ public abstract class MockedPulsarServiceBaseTest {
pulsar.close();
}
if (mockBookKeeper != null) {
- mockBookKeeper.reallyShutdow();
+ mockBookKeeper.reallyShutdown();
}
if (mockZookKeeper != null) {
mockZookKeeper.shutdown();
@@ -187,7 +185,7 @@ public abstract class MockedPulsarServiceBaseTest {
protected void stopBroker() throws Exception {
pulsar.close();
// Simulate cleanup of ephemeral nodes
- //mockZookKeeper.delete("/loadbalance/brokers/localhost:" + pulsar.getConfiguration().getWebServicePort(), -1);
+ //mockZooKeeper.delete("/loadbalance/brokers/localhost:" + pulsar.getConfiguration().getWebServicePort(), -1);
}
protected void startBroker() throws Exception {
@@ -199,7 +197,7 @@ public abstract class MockedPulsarServiceBaseTest {
setupBrokerMocks(pulsar);
boolean isAuthorizationEnabled = conf.isAuthorizationEnabled();
- // enable authrorization to initialize authorization service which is used by grant-permission
+ // enable authorization to initialize authorization service which is used by grant-permission
conf.setAuthorizationEnabled(true);
pulsar.start();
conf.setAuthorizationEnabled(isAuthorizationEnabled);
@@ -223,7 +221,7 @@ public abstract class MockedPulsarServiceBaseTest {
public static MockZooKeeper createMockZooKeeper() throws Exception {
MockZooKeeper zk = MockZooKeeper.newInstance(MoreExecutors.newDirectExecutorService());
- List<ACL> dummyAclList = new ArrayList<ACL>(0);
+ List<ACL> dummyAclList = new ArrayList<>(0);
ZkUtils.createFullPathOptimistic(zk, "/ledgers/available/192.168.1.1:" + 5000,
"".getBytes(ZookeeperClientFactoryImpl.ENCODING_SCHEME), dummyAclList, CreateMode.PERSISTENT);
@@ -246,7 +244,7 @@ public abstract class MockedPulsarServiceBaseTest {
}
@Override
- public void close() throws InterruptedException, BKException {
+ public void close() {
// no-op
}
@@ -255,7 +253,7 @@ public abstract class MockedPulsarServiceBaseTest {
// no-op
}
- public void reallyShutdow() {
+ public void reallyShutdown() {
super.shutdown();
}
}
@@ -273,7 +271,7 @@ public abstract class MockedPulsarServiceBaseTest {
private BookKeeperClientFactory mockBookKeeperClientFactory = new BookKeeperClientFactory() {
@Override
- public BookKeeper create(ServiceConfiguration conf, ZooKeeper zkClient) throws IOException {
+ public BookKeeper create(ServiceConfiguration conf, ZooKeeper zkClient) {
// Always return the same instance (so that we don't loose the mock BK content on broker restart
return mockBookKeeper;
}
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LoadBalancerTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LoadBalancerTest.java
index a959dee..3b5c577 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LoadBalancerTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LoadBalancerTest.java
@@ -18,33 +18,11 @@
*/
package org.apache.pulsar.broker.loadbalance;
-import static org.apache.pulsar.broker.cache.ConfigurationCacheService.POLICIES;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
-import java.lang.reflect.Field;
-import java.net.InetAddress;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
-import java.util.concurrent.atomic.AtomicReference;
-
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
import org.apache.bookkeeper.test.PortManager;
import org.apache.bookkeeper.util.ZkUtils;
import org.apache.pulsar.broker.PulsarService;
@@ -85,11 +63,31 @@ import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.base.Charsets;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
+import java.lang.reflect.Field;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.apache.pulsar.broker.cache.ConfigurationCacheService.POLICIES;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
/**
* Start two brokers in the same cluster and have them connect to the same zookeeper. When the PulsarService starts, it
@@ -101,7 +99,7 @@ import com.google.common.collect.Sets;
public class LoadBalancerTest {
LocalBookkeeperEnsemble bkEnsemble;
- ExecutorService executor = new ThreadPoolExecutor(5, 20, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ ExecutorService executor = new ThreadPoolExecutor(5, 20, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
private static final Logger log = LoggerFactory.getLogger(LoadBalancerTest.class);
@@ -127,7 +125,7 @@ public class LoadBalancerTest {
"{\"loadBalancerStrategy\":\"leastLoadedServer\"}".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
- final String localhost = InetAddress.getLocalHost().getHostName();
+ final String localhost = "localhost";
// start brokers
for (int i = 0; i < BROKER_COUNT; i++) {
brokerWebServicePorts[i] = PortManager.nextFreePort();
@@ -136,7 +134,7 @@ public class LoadBalancerTest {
ServiceConfiguration config = new ServiceConfiguration();
config.setBrokerServicePort(brokerNativeBrokerPorts[i]);
config.setClusterName("use");
- config.setAdvertisedAddress("localhost");
+ config.setAdvertisedAddress(localhost);
config.setWebServicePort(brokerWebServicePorts[i]);
config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
config.setBrokerServicePort(brokerNativeBrokerPorts[i]);
@@ -984,7 +982,7 @@ public class LoadBalancerTest {
zkCacheField.set(pulsarServices[0], mockCache);
int totalAvailabilityWeight = 0;
- TreeMap<Long, Set<ResourceUnit>> sortedRankingsInstance = new TreeMap<Long, Set<ResourceUnit>>();
+ TreeMap<Long, Set<ResourceUnit>> sortedRankingsInstance = new TreeMap<>();
for (int i = 1; i <= 3; i++) {
PulsarResourceDescription rd = createResourceDescription(memoryMB * i, cpuPercent * i, bInMbps * i,
bOutMbps * 2, threads * i);
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/ModularLoadManagerImplTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/ModularLoadManagerImplTest.java
index 0303fbf..6d25b7d 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/ModularLoadManagerImplTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/ModularLoadManagerImplTest.java
@@ -18,35 +18,11 @@
*/
package org.apache.pulsar.broker.loadbalance;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertTrue;
-
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.BoundType;
import com.google.common.collect.Range;
import com.google.common.collect.Sets;
import com.google.common.hash.Hashing;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.net.InetAddress;
-import java.net.URL;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.function.Supplier;
-
import org.apache.bookkeeper.test.PortManager;
import org.apache.bookkeeper.util.ZkUtils;
import org.apache.pulsar.broker.BrokerData;
@@ -85,6 +61,28 @@ import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Supplier;
+
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertTrue;
+
public class ModularLoadManagerImplTest {
private LocalBookkeeperEnsemble bkEnsemble;
@@ -105,7 +103,7 @@ public class ModularLoadManagerImplTest {
private ModularLoadManagerImpl secondaryLoadManager;
private ExecutorService executor = new ThreadPoolExecutor(5, 20, 30, TimeUnit.SECONDS,
- new LinkedBlockingQueue<Runnable>());
+ new LinkedBlockingQueue<>());
private final int ZOOKEEPER_PORT = PortManager.nextFreePort();
private final int PRIMARY_BROKER_WEBSERVICE_PORT = PortManager.nextFreePort();
@@ -156,11 +154,12 @@ public class ModularLoadManagerImplTest {
config1.setWebServicePort(PRIMARY_BROKER_WEBSERVICE_PORT);
config1.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
config1.setBrokerServicePort(PRIMARY_BROKER_PORT);
+ config1.setAdvertisedAddress("localhost");
pulsar1 = new PulsarService(config1);
pulsar1.start();
- primaryHost = String.format("%s:%d", InetAddress.getLocalHost().getHostName(), PRIMARY_BROKER_WEBSERVICE_PORT);
+ primaryHost = String.format("%s:%d", "localhost", PRIMARY_BROKER_WEBSERVICE_PORT);
url1 = new URL("http://127.0.0.1" + ":" + PRIMARY_BROKER_WEBSERVICE_PORT);
admin1 = PulsarAdmin.builder().serviceHttpUrl(url1.toString()).build();
@@ -171,8 +170,9 @@ public class ModularLoadManagerImplTest {
config2.setWebServicePort(SECONDARY_BROKER_WEBSERVICE_PORT);
config2.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
config2.setBrokerServicePort(SECONDARY_BROKER_PORT);
+ config2.setAdvertisedAddress("localhost");
pulsar2 = new PulsarService(config2);
- secondaryHost = String.format("%s:%d", InetAddress.getLocalHost().getHostName(),
+ secondaryHost = String.format("%s:%d", "localhost",
SECONDARY_BROKER_WEBSERVICE_PORT);
pulsar2.start();
@@ -342,7 +342,7 @@ public class ModularLoadManagerImplTest {
final BrokerData brokerDataSpy1 = spy(brokerDataMap.get(primaryHost));
when(brokerDataSpy1.getLocalData()).thenReturn(localBrokerData);
brokerDataMap.put(primaryHost, brokerDataSpy1);
- // Need to update all the bundle data for the shedder to see the spy.
+ // Need to update all the bundle data for the shredder to see the spy.
primaryLoadManager.onUpdate(null, null, null);
Thread.sleep(100);
localBrokerData.setCpu(new ResourceUsage(80, 100));
@@ -461,10 +461,10 @@ public class ModularLoadManagerImplTest {
pulsar2.getLocalZkCache().getZooKeeper().delete(LoadManager.LOADBALANCE_BROKERS_ROOT + "/" + secondaryBroker,
-1);
Thread.sleep(100);
- ModularLoadManagerWrapper loadManagerWapper = (ModularLoadManagerWrapper) pulsar1.getLoadManager().get();
+ ModularLoadManagerWrapper loadManagerWrapper = (ModularLoadManagerWrapper) pulsar1.getLoadManager().get();
Field loadMgrField = ModularLoadManagerWrapper.class.getDeclaredField("loadManager");
loadMgrField.setAccessible(true);
- ModularLoadManagerImpl loadManager = (ModularLoadManagerImpl) loadMgrField.get(loadManagerWapper);
+ ModularLoadManagerImpl loadManager = (ModularLoadManagerImpl) loadMgrField.get(loadManagerWrapper);
Set<String> avaialbeBrokers = loadManager.getAvailableBrokers();
assertEquals(avaialbeBrokers.size(), 1);
}
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TopicFromMessageTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TopicFromMessageTest.java
index dddbbba..2242435 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TopicFromMessageTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TopicFromMessageTest.java
@@ -22,10 +22,6 @@ import com.google.common.collect.Lists;
import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.client.api.ProducerConsumerBase;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -33,7 +29,6 @@ import org.testng.annotations.Test;
public class TopicFromMessageTest extends ProducerConsumerBase {
private static final long testTimeout = 90000; // 1.5 min
- private static final Logger log = LoggerFactory.getLogger(TopicFromMessageTest.class);
@Override
@BeforeMethod
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarWorkerAssignmentTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarWorkerAssignmentTest.java
index 1825a56..40d4654 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarWorkerAssignmentTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarWorkerAssignmentTest.java
@@ -44,7 +44,6 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
-import java.net.InetAddress;
import java.net.URI;
import java.util.Map;
import java.util.Optional;
@@ -100,9 +99,7 @@ public class PulsarWorkerAssignmentTest {
config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
config.setBrokerServicePort(brokerServicePort);
config.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
- config.setAdvertisedAddress(InetAddress.getLocalHost().getHostAddress());
-
- log.info("Host address : {}", InetAddress.getLocalHost().getHostAddress());
+ config.setAdvertisedAddress("localhost");
functionsWorkerService = createPulsarFunctionWorker(config);
final Optional<WorkerService> functionWorkerService = Optional.of(functionsWorkerService);
@@ -112,7 +109,7 @@ public class PulsarWorkerAssignmentTest {
admin = spy(PulsarAdmin.builder().serviceHttpUrl(brokerWeServiceUrl).build());
brokerStatsClient = admin.brokerStats();
- primaryHost = String.format("http://%s:%d", InetAddress.getLocalHost().getHostAddress(), brokerWebServicePort);
+ primaryHost = String.format("http://%s:%d", "localhost", brokerWebServicePort);
// update cluster metadata
final ClusterData clusterData = new ClusterData(brokerServiceUrl);
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionAdminTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionAdminTest.java
index b9c2162..6b65f9c 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionAdminTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/io/PulsarFunctionAdminTest.java
@@ -139,7 +139,7 @@ public class PulsarFunctionAdminTest {
.allowTlsInsecureConnection(true).authentication(authTls).build());
brokerStatsClient = admin.brokerStats();
- primaryHost = String.format("http://%s:%d", InetAddress.getLocalHost().getHostName(), brokerWebServicePort);
+ primaryHost = String.format("http://%s:%d", "localhost", brokerWebServicePort);
// update cluster metadata
ClusterData clusterData = new ClusterData(urlTls.toString());
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 f04fede..c8a95c1 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
@@ -20,13 +20,11 @@ package org.apache.pulsar.io;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
-import com.google.gson.Gson;
import lombok.ToString;
import org.apache.bookkeeper.test.PortManager;
import org.apache.pulsar.broker.PulsarService;
import org.apache.pulsar.broker.ServiceConfiguration;
import org.apache.pulsar.broker.ServiceConfigurationUtils;
-import org.apache.pulsar.broker.authentication.AuthenticationProviderBasic;
import org.apache.pulsar.broker.authentication.AuthenticationProviderTls;
import org.apache.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl;
import org.apache.pulsar.client.admin.BrokerStats;
@@ -44,7 +42,6 @@ import org.apache.pulsar.common.functions.FunctionConfig;
import org.apache.pulsar.common.functions.Utils;
import org.apache.pulsar.common.io.SinkConfig;
import org.apache.pulsar.common.io.SourceConfig;
-import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.policies.data.ClusterData;
import org.apache.pulsar.common.policies.data.FunctionStats;
import org.apache.pulsar.common.policies.data.FunctionStatus;
@@ -68,7 +65,6 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
-import java.net.InetAddress;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
@@ -154,6 +150,7 @@ public class PulsarFunctionE2ETest {
config.setBrokerServicePortTls(brokerServiceTlsPort);
config.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
config.setTlsAllowInsecureConnection(true);
+ config.setAdvertisedAddress("localhost");
Set<String> providers = new HashSet<>();
providers.add(AuthenticationProviderTls.class.getName());
@@ -189,7 +186,7 @@ public class PulsarFunctionE2ETest {
.allowTlsInsecureConnection(true).authentication(authTls).build());
brokerStatsClient = admin.brokerStats();
- primaryHost = String.format("http://%s:%d", InetAddress.getLocalHost().getHostName(), brokerWebServicePort);
+ primaryHost = String.format("http://%s:%d", "localhost", brokerWebServicePort);
// update cluster metadata
ClusterData clusterData = new ClusterData(urlTls.toString());
@@ -1274,7 +1271,7 @@ public class PulsarFunctionE2ETest {
public static String getPrometheusMetrics(int metricsPort) throws IOException {
StringBuilder result = new StringBuilder();
- URL url = new URL(String.format("http://%s:%s/metrics", InetAddress.getLocalHost().getHostAddress(), metricsPort));
+ URL url = new URL(String.format("http://%s:%s/metrics", "localhost", metricsPort));
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
@@ -1290,7 +1287,7 @@ public class PulsarFunctionE2ETest {
* Hacky parsing of Prometheus text format. Sould be good enough for unit tests
*/
private static Map<String, Metric> parseMetrics(String metrics) {
- Map<String, Metric> parsed = new HashMap<>();
+ final Map<String, Metric> parsed = new HashMap<>();
// Example of lines are
// jvm_threads_current{cluster="standalone",} 203.0
// or
@@ -1321,7 +1318,7 @@ public class PulsarFunctionE2ETest {
@ToString
static class Metric {
- Map<String, String> tags = new TreeMap<>();
+ final Map<String, String> tags = new TreeMap<>();
double value;
}
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/stats/client/PulsarBrokerStatsClientTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/stats/client/PulsarBrokerStatsClientTest.java
index d5dc26b..fca1485 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/stats/client/PulsarBrokerStatsClientTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/stats/client/PulsarBrokerStatsClientTest.java
@@ -18,16 +18,6 @@
*/
package org.apache.pulsar.stats.client;
-import static org.mockito.Mockito.spy;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.net.URL;
-import java.util.concurrent.TimeUnit;
-
-import javax.ws.rs.ClientErrorException;
-import javax.ws.rs.ServerErrorException;
-
import org.apache.pulsar.broker.service.persistent.PersistentTopic;
import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.admin.PulsarAdminException;
@@ -37,7 +27,6 @@ import org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException;
import org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException;
import org.apache.pulsar.client.admin.PulsarAdminException.ServerSideErrorException;
import org.apache.pulsar.client.admin.internal.BrokerStatsImpl;
-import org.apache.pulsar.client.api.Authentication;
import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.Message;
import org.apache.pulsar.client.api.Producer;
@@ -50,6 +39,15 @@ import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.ws.rs.ClientErrorException;
+import javax.ws.rs.ServerErrorException;
+import java.net.URL;
+import java.util.concurrent.TimeUnit;
+
+import static org.mockito.Mockito.spy;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
public class PulsarBrokerStatsClientTest extends ProducerConsumerBase {
@BeforeMethod
@@ -113,7 +111,7 @@ public class PulsarBrokerStatsClientTest extends ProducerConsumerBase {
producer.send(message.getBytes());
}
- Message<byte[]> msg = null;
+ Message<byte[]> msg;
int count = 0;
for (int i = 0; i < numberOfMsgs; i++) {
msg = consumer.receive(5, TimeUnit.SECONDS);
diff --git a/tests/pulsar-storm-test/src/test/java/org/apache/pulsar/storm/PulsarSpoutTest.java b/tests/pulsar-storm-test/src/test/java/org/apache/pulsar/storm/PulsarSpoutTest.java
index a21e216..461a6d7 100644
--- a/tests/pulsar-storm-test/src/test/java/org/apache/pulsar/storm/PulsarSpoutTest.java
+++ b/tests/pulsar-storm-test/src/test/java/org/apache/pulsar/storm/PulsarSpoutTest.java
@@ -317,7 +317,7 @@ public class PulsarSpoutTest extends ProducerConsumerBase {
}
@Test
- public void testFailedConsumer() throws Exception {
+ public void testFailedConsumer() {
PulsarSpoutConfiguration pulsarSpoutConf = new PulsarSpoutConfiguration();
pulsarSpoutConf.setServiceUrl(serviceUrl);
pulsarSpoutConf.setTopic("persistent://invalidTopic");