Skip to content

Commit

Permalink
[fix][test] Fix thread leaks related to unclosed WebSocketService
Browse files Browse the repository at this point in the history
  • Loading branch information
lhotari committed Oct 27, 2023
1 parent 2b5c199 commit 09ef5f6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void setup() throws Exception {
config.setClusterName("test");
config.setConfigurationMetadataStoreUrl(GLOBAL_DUMMY_VALUE);
config.setCryptoKeyReaderFactoryClassName(CryptoKeyReaderFactoryImpl.class.getName());
WebSocketService service = spy(new WebSocketService(config));
service = spy(new WebSocketService(config));
doReturn(new ZKMetadataStore(mockZooKeeperGlobal)).when(service)
.createConfigMetadataStore(anyString(), anyInt(), anyBoolean());
proxyServer = new ProxyServer(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void setup() throws Exception {
config.setWebServicePort(Optional.of(0));
config.setClusterName("test");
config.setConfigurationMetadataStoreUrl(GLOBAL_DUMMY_VALUE);
WebSocketService service = spy(new WebSocketService(config));
service = spy(new WebSocketService(config));
doReturn(new ZKMetadataStore(mockZooKeeperGlobal)).when(service)
.createConfigMetadataStore(anyString(), anyInt(), anyBoolean());
proxyServer = new ProxyServer(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.Cleanup;
import lombok.Getter;
import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
import org.apache.pulsar.client.api.CompressionType;
Expand Down Expand Up @@ -388,10 +389,11 @@ public void consumerBuilderTest() throws IOException {
}

@Test
public void testPingFuture() {
public void testPingFuture() throws IOException {
WebSocketProxyConfiguration webSocketProxyConfiguration = new WebSocketProxyConfiguration();
webSocketProxyConfiguration.setWebSocketPingDurationSeconds(5);

@Cleanup
WebSocketService webSocketService = new WebSocketService(webSocketProxyConfiguration);

HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.pulsar.websocket;

import lombok.Cleanup;
import org.apache.pulsar.common.configuration.PulsarConfigurationLoader;
import org.apache.pulsar.websocket.service.WebSocketProxyConfiguration;
import org.eclipse.jetty.websocket.servlet.UpgradeHttpServletRequest;
Expand Down Expand Up @@ -70,6 +71,7 @@ public void mockRequestTest() throws Exception {
WebSocketProxyConfiguration.class);
String publicKeyPath = "file://" + this.getClass().getClassLoader().getResource("my-public.key").getFile();
config.getProperties().setProperty("tokenPublicKey", publicKeyPath);
@Cleanup
WebSocketService service = new WebSocketService(config);
service.start();

Expand Down

0 comments on commit 09ef5f6

Please sign in to comment.