You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by yo...@apache.org on 2021/12/23 14:03:46 UTC
[pulsar] 01/14: Fix ProxyServiceStarterTest flaky tests (#12344)
This is an automated email from the ASF dual-hosted git repository.
yong pushed a commit to branch branch-2.8
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 5a123c414172035276f8181eebde6f81741c75e6
Author: Nicolò Boschi <bo...@gmail.com>
AuthorDate: Thu Oct 21 18:06:49 2021 +0200
Fix ProxyServiceStarterTest flaky tests (#12344)
* Fix ProxyServiceStarterTest flaky tests
* revert formatting
* use ephimeral port
(cherry picked from commit 7ad46c8c18bb8365c9a2d1233a6cd58ecd6f541f)
---
.../apache/pulsar/proxy/server/ProxyServiceStarter.java | 5 +++++
.../pulsar/proxy/server/ProxyServiceStarterTest.java | 16 +++++++++++-----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java
index 6c151dd..86ce236 100644
--- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java
+++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java
@@ -299,6 +299,11 @@ public class ProxyServiceStarter {
return config;
}
+ @VisibleForTesting
+ public WebServer getServer() {
+ return server;
+ }
+
private static final Logger log = LoggerFactory.getLogger(ProxyServiceStarter.class);
}
diff --git a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyServiceStarterTest.java b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyServiceStarterTest.java
index 3377ec2..bdba8d3 100644
--- a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyServiceStarterTest.java
+++ b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyServiceStarterTest.java
@@ -59,7 +59,8 @@ public class ProxyServiceStarterTest extends MockedPulsarServiceBaseTest {
serviceStarter = new ProxyServiceStarter(ARGS);
serviceStarter.getConfig().setBrokerServiceURL(pulsar.getBrokerServiceUrl());
serviceStarter.getConfig().setBrokerWebServiceURL(pulsar.getWebServiceAddress());
- serviceStarter.getConfig().setServicePort(Optional.of(11000));
+ serviceStarter.getConfig().setWebServicePort(Optional.of(0));
+ serviceStarter.getConfig().setServicePort(Optional.of(0));
serviceStarter.getConfig().setWebSocketServiceEnabled(true);
serviceStarter.start();
}
@@ -71,14 +72,19 @@ public class ProxyServiceStarterTest extends MockedPulsarServiceBaseTest {
serviceStarter.close();
}
+ private String computeWsBasePath() {
+ return String.format("ws://localhost:%d/ws", serviceStarter.getServer().getListenPortHTTP().get());
+ }
+
@Test
public void testEnableWebSocketServer() throws Exception {
HttpClient httpClient = new HttpClient();
WebSocketClient webSocketClient = new WebSocketClient(httpClient);
webSocketClient.start();
MyWebSocket myWebSocket = new MyWebSocket();
- String webSocketUri = "ws://localhost:8080/ws/pingpong";
+ String webSocketUri = computeWsBasePath() + "/pingpong";
Future<Session> sessionFuture = webSocketClient.connect(myWebSocket, URI.create(webSocketUri));
+ System.out.println("uri" + webSocketUri);
sessionFuture.get().getRemote().sendPing(ByteBuffer.wrap("ping".getBytes()));
assertTrue(myWebSocket.getResponse().contains("ping"));
}
@@ -86,7 +92,7 @@ public class ProxyServiceStarterTest extends MockedPulsarServiceBaseTest {
@Test
public void testProducer() throws Exception {
@Cleanup
- PulsarClient client = PulsarClient.builder().serviceUrl("pulsar://localhost:11000")
+ PulsarClient client = PulsarClient.builder().serviceUrl("pulsar://localhost:" + this.pulsar.getBrokerService().getListenPort().get())
.build();
@Cleanup
@@ -105,7 +111,7 @@ public class ProxyServiceStarterTest extends MockedPulsarServiceBaseTest {
WebSocketClient producerWebSocketClient = new WebSocketClient(producerClient);
producerWebSocketClient.start();
MyWebSocket producerSocket = new MyWebSocket();
- String produceUri = "ws://localhost:8080/ws/producer/persistent/sample/test/local/websocket-topic";
+ String produceUri = computeWsBasePath() + "/producer/persistent/sample/test/local/websocket-topic";
Future<Session> producerSession = producerWebSocketClient.connect(producerSocket, URI.create(produceUri));
ProducerMessage produceRequest = new ProducerMessage();
@@ -116,7 +122,7 @@ public class ProxyServiceStarterTest extends MockedPulsarServiceBaseTest {
WebSocketClient consumerWebSocketClient = new WebSocketClient(consumerClient);
consumerWebSocketClient.start();
MyWebSocket consumerSocket = new MyWebSocket();
- String consumeUri = "ws://localhost:8080/ws/consumer/persistent/sample/test/local/websocket-topic/my-sub";
+ String consumeUri = computeWsBasePath() + "/consumer/persistent/sample/test/local/websocket-topic/my-sub";
Future<Session> consumerSession = consumerWebSocketClient.connect(consumerSocket, URI.create(consumeUri));
consumerSession.get().getRemote().sendPing(ByteBuffer.wrap("ping".getBytes()));
producerSession.get().getRemote().sendString(ObjectMapperFactory.getThreadLocal().writeValueAsString(produceRequest));