You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by eo...@apache.org on 2021/04/30 07:46:32 UTC

[pulsar] branch branch-2.7 updated: Issue 10452: WebSocketHttpServletRequestWrapperTest is failing consistently on branch.2-7 (#10453)

This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.7 by this push:
     new ccc850b  Issue 10452: WebSocketHttpServletRequestWrapperTest is failing consistently on branch.2-7 (#10453)
ccc850b is described below

commit ccc850b5ea1dd569ef7f7519a55e10b7b3212210
Author: Enrico Olivelli <eo...@gmail.com>
AuthorDate: Fri Apr 30 09:45:46 2021 +0200

    Issue 10452: WebSocketHttpServletRequestWrapperTest is failing consistently on branch.2-7 (#10453)
---
 pulsar-websocket/pom.xml                           | 11 ++++++-
 .../WebSocketHttpServletRequestWrapperTest.java    | 35 ++++++++++++----------
 2 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/pulsar-websocket/pom.xml b/pulsar-websocket/pom.xml
index 8b477b8..764ccff 100644
--- a/pulsar-websocket/pom.xml
+++ b/pulsar-websocket/pom.xml
@@ -98,7 +98,16 @@
       <artifactId>jul-to-slf4j</artifactId>
     </dependency>
 
-		<!-- To write basic websockets against -->
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>pulsar-zookeeper-utils</artifactId>
+      <version>${project.version}</version>
+      <classifier>tests</classifier>
+      <scope>test</scope>
+    </dependency>
+
+
+    <!-- To write basic websockets against -->
     <dependency>
       <groupId>org.eclipse.jetty.websocket</groupId>
       <artifactId>websocket-api</artifactId>
diff --git a/pulsar-websocket/src/test/java/org/apache/pulsar/websocket/WebSocketHttpServletRequestWrapperTest.java b/pulsar-websocket/src/test/java/org/apache/pulsar/websocket/WebSocketHttpServletRequestWrapperTest.java
index 52bee3f..d781ac3 100644
--- a/pulsar-websocket/src/test/java/org/apache/pulsar/websocket/WebSocketHttpServletRequestWrapperTest.java
+++ b/pulsar-websocket/src/test/java/org/apache/pulsar/websocket/WebSocketHttpServletRequestWrapperTest.java
@@ -24,6 +24,7 @@ import org.eclipse.jetty.websocket.servlet.UpgradeHttpServletRequest;
 import org.junit.Assert;
 import org.mockito.Mockito;
 import org.testng.annotations.Test;
+import org.apache.pulsar.zookeeper.ZookeeperServerTest;
 
 /**
  * WebSocketHttpServletRequestWrapper test.
@@ -63,23 +64,27 @@ public class WebSocketHttpServletRequestWrapperTest {
 
     @Test
     public void mockRequestTest() throws Exception {
-        WebSocketProxyConfiguration config = PulsarConfigurationLoader.create(
-                this.getClass().getClassLoader().getResource("websocket.conf").getFile(),
-                WebSocketProxyConfiguration.class);
-        String publicKeyPath = this.getClass().getClassLoader().getResource("my-public.key").getFile();
-        config.getProperties().setProperty("tokenPublicKey", publicKeyPath);
-        WebSocketService service = new WebSocketService(config);
-        service.start();
+        try (ZookeeperServerTest zkServer = new ZookeeperServerTest(12345)) {
+            WebSocketProxyConfiguration config = PulsarConfigurationLoader.create(
+                    this.getClass().getClassLoader().getResource("websocket.conf").getFile(),
+                    WebSocketProxyConfiguration.class);
+            zkServer.start();
+            config.setConfigurationStoreServers(zkServer.getHostPort());
+            String publicKeyPath = this.getClass().getClassLoader().getResource("my-public.key").getFile();
+            config.getProperties().setProperty("tokenPublicKey", publicKeyPath);
+            WebSocketService service = new WebSocketService(config);
+            service.start();
 
-        UpgradeHttpServletRequest httpServletRequest = Mockito.mock(UpgradeHttpServletRequest.class);
-        Mockito.when(httpServletRequest.getRemoteAddr()).thenReturn("localhost");
-        Mockito.when(httpServletRequest.getRemotePort()).thenReturn(8080);
-        Mockito.when(httpServletRequest.getParameter(WebSocketHttpServletRequestWrapper.TOKEN))
-                .thenReturn(TOKEN);
-        WebSocketHttpServletRequestWrapper webSocketHttpServletRequestWrapper =
-                new WebSocketHttpServletRequestWrapper(httpServletRequest);
+            UpgradeHttpServletRequest httpServletRequest = Mockito.mock(UpgradeHttpServletRequest.class);
+            Mockito.when(httpServletRequest.getRemoteAddr()).thenReturn("localhost");
+            Mockito.when(httpServletRequest.getRemotePort()).thenReturn(8080);
+            Mockito.when(httpServletRequest.getParameter(WebSocketHttpServletRequestWrapper.TOKEN))
+                    .thenReturn(TOKEN);
+            WebSocketHttpServletRequestWrapper webSocketHttpServletRequestWrapper =
+                    new WebSocketHttpServletRequestWrapper(httpServletRequest);
 
-        Assert.assertEquals("test-user", service.getAuthenticationService().authenticateHttpRequest(webSocketHttpServletRequestWrapper));
+            Assert.assertEquals("test-user", service.getAuthenticationService().authenticateHttpRequest(webSocketHttpServletRequestWrapper));
+        }
     }
 
 }