-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[improve][test] Add integration test for websocket (#17843)
- Loading branch information
Andras Beni
authored
Sep 28, 2022
1 parent
31203c3
commit 0678b82
Showing
11 changed files
with
311 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tests/docker-images/latest-version-image/conf/websocket.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
[program:websocket] | ||
autostart=false | ||
redirect_stderr=true | ||
stdout_logfile=/var/log/pulsar/pulsar-websocket.log | ||
directory=/pulsar | ||
environment=PULSAR_MEM="-Xmx128M",PULSAR_GC="-XX:+UseZGC" | ||
command=/pulsar/bin/pulsar websocket | ||
user=pulsar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...tion/src/test/java/org/apache/pulsar/tests/integration/containers/WebSocketContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.tests.integration.containers; | ||
|
||
import org.apache.pulsar.tests.integration.utils.DockerUtils; | ||
|
||
public class WebSocketContainer extends PulsarContainer<WebSocketContainer> { | ||
|
||
public WebSocketContainer(String clusterName, String hostName) { | ||
super(clusterName, hostName, hostName, | ||
"bin/run-websocket.sh", | ||
-1, | ||
BROKER_HTTP_PORT, "/admin/v2/proxy-stats/stats"); | ||
} | ||
|
||
public String getWSUrl() { | ||
return "ws://" + getHost() + ":" + getMappedPort(BROKER_HTTP_PORT); | ||
} | ||
|
||
@Override | ||
protected void afterStart() { | ||
DockerUtils.runCommandAsyncWithLogging(this.dockerClient, this.getContainerId(), | ||
"tail", "-f", "/var/log/pulsar/pulsar-websocket.log"); | ||
} | ||
} |
128 changes: 0 additions & 128 deletions
128
...ation/src/test/java/org/apache/pulsar/tests/integration/proxy/TestProxyWithWebSocket.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...ntegration/src/test/java/org/apache/pulsar/tests/integration/websocket/TestWebSocket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.tests.integration.websocket; | ||
|
||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.apache.pulsar.tests.integration.containers.BrokerContainer; | ||
import org.apache.pulsar.tests.integration.containers.CSContainer; | ||
import org.apache.pulsar.tests.integration.containers.WebSocketContainer; | ||
import org.apache.pulsar.tests.integration.topologies.PulsarClusterSpec; | ||
import org.testng.annotations.Test; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
/** | ||
* Test cases for websocket. | ||
*/ | ||
public class TestWebSocket extends WebSocketTestSuite { | ||
|
||
public static final String WEBSOCKET = "websocket"; | ||
|
||
@Override | ||
protected PulsarClusterSpec.PulsarClusterSpecBuilder beforeSetupCluster( | ||
String clusterName, | ||
PulsarClusterSpec.PulsarClusterSpecBuilder specBuilder) { | ||
|
||
Map<String, String> enableWebSocket = Collections.singletonMap("webSocketServiceEnabled", "true"); | ||
specBuilder.brokerEnvs(enableWebSocket); | ||
specBuilder.proxyEnvs(enableWebSocket); | ||
|
||
specBuilder.externalService(WEBSOCKET, new WebSocketContainer(clusterName, WEBSOCKET)); | ||
specBuilder.externalServiceEnv(WEBSOCKET, ImmutableMap.<String, String>builder() | ||
.put("configurationMetadataStoreUrl", CSContainer.NAME + ":" + CSContainer.CS_PORT) | ||
.put("webServicePort", "" + WebSocketContainer.BROKER_HTTP_PORT) | ||
.put("clusterName", clusterName) | ||
.build()); | ||
return super.beforeSetupCluster(clusterName, specBuilder); | ||
} | ||
|
||
@Test | ||
public void testExternalService() throws Exception { | ||
WebSocketContainer service = (WebSocketContainer) pulsarCluster.getExternalServices().get(WEBSOCKET); | ||
testWebSocket(service.getWSUrl()); | ||
} | ||
|
||
@Test | ||
public void testBroker() throws Exception { | ||
BrokerContainer broker = pulsarCluster.getAnyBroker(); | ||
String url = "ws://" + broker.getHost() + ":" + broker.getMappedPort(BrokerContainer.BROKER_HTTP_PORT); | ||
testWebSocket(url); | ||
} | ||
|
||
@Test | ||
public void testProxy() throws Exception { | ||
String url = pulsarCluster.getProxy().getHttpServiceUrl().replaceFirst("http", "ws"); | ||
testWebSocket(url); | ||
} | ||
} |
Oops, something went wrong.