Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
*/
package org.apache.pulsar.websocket.proxy;

import static java.util.concurrent.Executors.newFixedThreadPool;
import static org.apache.pulsar.broker.BrokerTestUtil.spyWithClassAndConstructorArgs;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import com.google.common.collect.Sets;
import java.net.URI;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.Client;
Expand All @@ -35,7 +33,6 @@
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import lombok.Cleanup;
import org.apache.pulsar.client.api.ProducerConsumerBase;
import org.apache.pulsar.metadata.impl.ZKMetadataStore;
import org.apache.pulsar.websocket.WebSocketService;
Expand Down Expand Up @@ -92,20 +89,12 @@ public void setup() throws Exception {

@AfterMethod(alwaysRun = true)
public void cleanup() throws Exception {
@Cleanup("shutdownNow")
ExecutorService executor = newFixedThreadPool(1);
try {
executor.submit(() -> {
try {
consumeClient.stop();
produceClient.stop();
log.info("proxy clients are stopped successfully");
} catch (Exception e) {
log.error(e.getMessage());
}
}).get(2, TimeUnit.SECONDS);
consumeClient.stop();
produceClient.stop();
log.info("proxy clients are stopped successfully");
} catch (Exception e) {
log.error("failed to close clients ", e);
log.error(e.getMessage());
}

super.internalCleanup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,19 @@
*/
package org.apache.pulsar.websocket.proxy;

import static java.util.concurrent.Executors.newFixedThreadPool;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.apache.pulsar.client.api.CryptoKeyReader;
import org.apache.pulsar.client.api.EncryptionKeyInfo;
import org.apache.pulsar.client.api.ProducerConsumerBase;
Expand All @@ -56,8 +51,6 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import lombok.Cleanup;

@Test(groups = "websocket")
public class ProxyEncryptionPublishConsumeTest extends ProducerConsumerBase {
protected String methodName;
Expand Down Expand Up @@ -220,22 +213,14 @@ public EncryptionKeyInfo getPrivateKey(String keyName, Map<String, String> keyMe
}

private void stopWebSocketClient(WebSocketClient... clients) {
@Cleanup("shutdownNow")
ExecutorService executor = newFixedThreadPool(1);
try {
executor.submit(() -> {
for (WebSocketClient client : clients) {
try {
client.stop();
} catch (Exception e) {
log.error(e.getMessage());
}
}
log.info("proxy clients are stopped successfully");
}).get(2, TimeUnit.SECONDS);
} catch (Exception e) {
log.error("failed to close proxy clients", e);
for (WebSocketClient client : clients) {
try {
client.stop();
} catch (Exception e) {
log.error(e.getMessage());
}
}
log.info("proxy clients are stopped successfully");
}

private static final Logger log = LoggerFactory.getLogger(ProxyEncryptionPublishConsumeTest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.pulsar.websocket.proxy;

import static java.util.concurrent.Executors.newFixedThreadPool;
import static org.apache.pulsar.broker.BrokerTestUtil.spyWithClassAndConstructorArgs;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
Expand All @@ -40,7 +39,6 @@
import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -50,7 +48,6 @@
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import lombok.Cleanup;
import org.apache.pulsar.broker.BrokerTestUtil;
import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.client.api.ProducerAccessMode;
Expand Down Expand Up @@ -1040,22 +1037,14 @@ private void verifyProxyStats(Client client, String baseUrl, String topic) {
}

private void stopWebSocketClient(WebSocketClient... clients) {
@Cleanup("shutdownNow")
ExecutorService executor = newFixedThreadPool(1);
try {
executor.submit(() -> {
for (WebSocketClient client : clients) {
try {
client.stop();
} catch (Exception e) {
log.error(e.getMessage());
}
}
log.info("proxy clients are stopped successfully");
}).get(2, TimeUnit.SECONDS);
} catch (Exception e) {
log.error("failed to close proxy clients", e);
for (WebSocketClient client : clients) {
try {
client.stop();
} catch (Exception e) {
log.error(e.getMessage());
}
}
log.info("proxy clients are stopped successfully");
}

private static final Logger log = LoggerFactory.getLogger(ProxyPublishConsumeTest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@
*/
package org.apache.pulsar.websocket.proxy;

import static java.util.concurrent.Executors.newFixedThreadPool;
import static org.apache.pulsar.broker.BrokerTestUtil.spyWithClassAndConstructorArgs;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import java.net.URI;
import java.security.GeneralSecurityException;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import lombok.Cleanup;
import org.apache.pulsar.client.api.TlsProducerConsumerBase;
import org.apache.pulsar.client.impl.auth.AuthenticationTls;
import org.apache.pulsar.common.util.SecurityUtility;
Expand Down Expand Up @@ -134,18 +131,10 @@ public void socketTest() throws GeneralSecurityException {
log.error(t.getMessage());
Assert.fail(t.getMessage());
} finally {
@Cleanup("shutdownNow")
ExecutorService executor = newFixedThreadPool(1);
try {
executor.submit(() -> {
try {
consumeClient.stop();
produceClient.stop();
log.info("proxy clients are stopped successfully");
} catch (Exception e) {
log.error(e.getMessage());
}
}).get(2, TimeUnit.SECONDS);
consumeClient.stop();
produceClient.stop();
log.info("proxy clients are stopped successfully");
} catch (Exception e) {
log.error("failed to close clients ", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@
*/
package org.apache.pulsar.websocket.proxy;

import static java.util.concurrent.Executors.newFixedThreadPool;
import static org.apache.pulsar.broker.BrokerTestUtil.spyWithClassAndConstructorArgs;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import java.net.URI;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import lombok.Cleanup;
import org.apache.pulsar.client.api.ProducerConsumerBase;
import org.apache.pulsar.metadata.impl.ZKMetadataStore;
import org.apache.pulsar.websocket.WebSocketService;
Expand Down Expand Up @@ -113,18 +109,10 @@ public void socketTest() throws Exception {
Assert.assertTrue(produceSocket.getBuffer().size() > 0);
Assert.assertEquals(produceSocket.getBuffer(), consumeSocket.getBuffer());
} finally {
@Cleanup("shutdownNow")
ExecutorService executor = newFixedThreadPool(1);
try {
executor.submit(() -> {
try {
consumeClient.stop();
produceClient.stop();
log.info("proxy clients are stopped successfully");
} catch (Exception e) {
log.error(e.getMessage());
}
}).get(2, TimeUnit.SECONDS);
consumeClient.stop();
produceClient.stop();
log.info("proxy clients are stopped successfully");
} catch (Exception e) {
log.error("failed to close clients ", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,20 @@
*/
package org.apache.pulsar.websocket.proxy.v1;

import static java.util.concurrent.Executors.newFixedThreadPool;
import static org.apache.pulsar.broker.BrokerTestUtil.spyWithClassAndConstructorArgs;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import com.google.common.collect.Sets;
import java.net.URI;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import lombok.Cleanup;
import org.apache.pulsar.client.api.v1.V1_ProducerConsumerBase;
import org.apache.pulsar.metadata.impl.ZKMetadataStore;
import org.apache.pulsar.websocket.WebSocketService;
Expand Down Expand Up @@ -94,20 +90,12 @@ public void setup() throws Exception {

@AfterMethod(alwaysRun = true)
public void cleanup() throws Exception {
@Cleanup("shutdownNow")
ExecutorService executor = newFixedThreadPool(1);
try {
executor.submit(() -> {
try {
consumeClient.stop();
produceClient.stop();
log.info("proxy clients are stopped successfully");
} catch (Exception e) {
log.error(e.getMessage());
}
}).get(2, TimeUnit.SECONDS);
consumeClient.stop();
produceClient.stop();
log.info("proxy clients are stopped successfully");
} catch (Exception e) {
log.error("failed to close clients ", e);
log.error(e.getMessage());
}

super.internalCleanup();
Expand Down