liangyepianzhou commented on code in PR #22935:
URL: https://github.com/apache/pulsar/pull/22935#discussion_r1667870698
##########
pulsar-client/src/test/java/org/apache/pulsar/client/impl/PulsarServiceNameResolverTest.java:
##########
@@ -38,12 +43,23 @@
public class PulsarServiceNameResolverTest {
private PulsarServiceNameResolver resolver;
-
+ private ServerSocket serverSocket;
@BeforeMethod
- public void setup() {
+ public void setup() throws IOException {
this.resolver = new PulsarServiceNameResolver();
assertNull(resolver.getServiceUrl());
assertNull(resolver.getServiceUri());
+ InetAddress inetAddress = InetAddress.getByName("0.0.0.0");
+ serverSocket = new ServerSocket(6666, 10, inetAddress);
Review Comment:
Consider creating an additional test class to configure the Pulsar service
as outlined below:
```java
protected void startBroker() throws Exception {
for (int i = 0; i < brokerCount; i++) {
conf.setClusterName(CLUSTER_NAME);
conf.setAdvertisedAddress("localhost");
conf.setManagedLedgerCacheSizeMB(8);
conf.setActiveConsumerFailoverDelayTimeMillis(0);
conf.setDefaultNumberOfNamespaceBundles(1);
conf.setMetadataStoreUrl("zk:localhost:2181");
conf.setConfigurationMetadataStoreUrl("zk:localhost:3181");
conf.setAllowAutoTopicCreationType(TopicType.NON_PARTITIONED);
conf.setBookkeeperClientExposeStatsToPrometheus(true);
conf.setForceDeleteNamespaceAllowed(true);
conf.setBrokerShutdownTimeoutMs(0L);
conf.setLoadBalancerOverrideBrokerNicSpeedGbps(Optional.of(1.0d));
conf.setBrokerServicePort(Optional.of(0));
conf.setAdvertisedAddress("localhost");
conf.setWebServicePort(Optional.of(0));
conf.setTransactionCoordinatorEnabled(true);
conf.setBrokerDeduplicationEnabled(true);
conf.setTransactionBufferSnapshotMaxTransactionCount(2);
conf.setTransactionBufferSnapshotMinTimeInMillis(2000);
serviceConfigurationList.add(conf);
PulsarTestContext.Builder testContextBuilder =
PulsarTestContext.builder()
.brokerInterceptor(new
CounterBrokerInterceptor())
.spyByDefault()
.enableOpenTelemetry(true)
.config(conf);
if (i > 0) {
testContextBuilder.reuseMockBookkeeperAndMetadataStores(pulsarTestContexts.get(0));
} else {
testContextBuilder.withMockZookeeper();
}
PulsarTestContext pulsarTestContext = testContextBuilder
.build();
PulsarService pulsar = pulsarTestContext.getPulsarService();
pulsarServiceList.add(pulsar);
pulsarTestContexts.add(pulsarTestContext);
}
}
```
##########
pulsar-client/src/test/java/org/apache/pulsar/client/impl/PulsarServiceNameResolverTest.java:
##########
@@ -38,12 +43,23 @@
public class PulsarServiceNameResolverTest {
private PulsarServiceNameResolver resolver;
-
+ private ServerSocket serverSocket;
@BeforeMethod
- public void setup() {
+ public void setup() throws IOException {
this.resolver = new PulsarServiceNameResolver();
assertNull(resolver.getServiceUrl());
assertNull(resolver.getServiceUri());
+ InetAddress inetAddress = InetAddress.getByName("0.0.0.0");
+ serverSocket = new ServerSocket(6666, 10, inetAddress);
Review Comment:
IMO, Setting some pulsar service to do this test is a better way.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]