Skip to content

Commit 6a7d20d

Browse files
committed
Merge pull request #137 from aslakknutsen/websocket_binary
Fix Binary WebSocket Tests for WildFly
2 parents d017237 + 116ec53 commit 6a7d20d

File tree

4 files changed

+34
-31
lines changed

4 files changed

+34
-31
lines changed

pom.xml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@
245245
</properties>
246246
<dependencies>
247247
<dependency>
248-
<groupId>org.wildfly</groupId>
249-
<artifactId>wildfly-arquillian-container-managed</artifactId>
250-
<version>${org.wildfly}</version>
248+
<groupId>io.undertow</groupId>
249+
<artifactId>undertow-websockets-jsr</artifactId>
250+
<version>1.0.0.Beta25</version>
251251
<scope>test</scope>
252252
</dependency>
253253
<dependency>
@@ -262,6 +262,12 @@
262262
<version>3.0.4.Final</version>
263263
<scope>test</scope>
264264
</dependency>
265+
<dependency>
266+
<groupId>org.wildfly</groupId>
267+
<artifactId>wildfly-arquillian-container-managed</artifactId>
268+
<version>${org.wildfly}</version>
269+
<scope>test</scope>
270+
</dependency>
265271
</dependencies>
266272
<build>
267273
<testResources>
@@ -315,9 +321,9 @@
315321
<id>wildfly-remote-arquillian</id>
316322
<dependencies>
317323
<dependency>
318-
<groupId>org.wildfly</groupId>
319-
<artifactId>wildfly-arquillian-container-remote</artifactId>
320-
<version>${org.wildfly}</version>
324+
<groupId>io.undertow</groupId>
325+
<artifactId>undertow-websockets-jsr</artifactId>
326+
<version>1.0.0.Beta25</version>
321327
<scope>test</scope>
322328
</dependency>
323329
<dependency>
@@ -332,6 +338,12 @@
332338
<version>3.0.4.Final</version>
333339
<scope>test</scope>
334340
</dependency>
341+
<dependency>
342+
<groupId>org.wildfly</groupId>
343+
<artifactId>wildfly-arquillian-container-remote</artifactId>
344+
<version>${org.wildfly}</version>
345+
<scope>test</scope>
346+
</dependency>
335347
</dependencies>
336348
<build>
337349
<testResources>

websocket/binary/src/main/java/org/javaee7/websocket/binary/MyEndpointClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.IOException;
77
import java.nio.ByteBuffer;
8+
import java.util.concurrent.CountDownLatch;
89

910
import javax.websocket.ClientEndpoint;
1011
import javax.websocket.OnMessage;
@@ -17,6 +18,7 @@
1718
*/
1819
@ClientEndpoint
1920
public class MyEndpointClient {
21+
public static CountDownLatch latch;
2022
public static byte[] response;
2123

2224
@OnOpen
@@ -31,5 +33,6 @@ public void onOpen(Session session) {
3133
@OnMessage
3234
public void processMessage(byte[] message) {
3335
MyEndpointClient.response = message;
36+
latch.countDown();
3437
}
3538
}

websocket/binary/src/test/java/org/javaee7/websocket/binary/test/WebsocketBinaryEndpointTest.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
*/
44
package org.javaee7.websocket.binary.test;
55

6-
import java.io.File;
6+
import static org.junit.Assert.assertArrayEquals;
7+
import static org.junit.Assert.assertTrue;
8+
import static org.junit.Assert.assertNotNull;
9+
710
import java.io.IOException;
811
import java.net.URI;
912
import java.net.URISyntaxException;
10-
import javax.websocket.ContainerProvider;
13+
import java.util.concurrent.CountDownLatch;
14+
import java.util.concurrent.TimeUnit;
1115

16+
import javax.websocket.ContainerProvider;
1217
import javax.websocket.DeploymentException;
1318
import javax.websocket.Session;
1419
import javax.websocket.WebSocketContainer;
@@ -22,7 +27,6 @@
2227
import org.jboss.arquillian.test.api.ArquillianResource;
2328
import org.jboss.shrinkwrap.api.ShrinkWrap;
2429
import org.jboss.shrinkwrap.api.spec.WebArchive;
25-
import static org.junit.Assert.*;
2630
import org.junit.Test;
2731
import org.junit.runner.RunWith;
2832

@@ -62,10 +66,10 @@ public static WebArchive createDeployment() {
6266
*/
6367
@Test
6468
public void testEndpointByteBuffer() throws URISyntaxException, DeploymentException, IOException, InterruptedException {
69+
MyEndpointClient.latch = new CountDownLatch(1);
6570
Session session = connectToServer("bytebuffer");
6671
assertNotNull(session);
67-
System.out.println("Waiting for 2 seconds to receive response");
68-
Thread.sleep(2000);
72+
assertTrue(MyEndpointClient.latch.await(2, TimeUnit.SECONDS));
6973
assertNotNull(MyEndpointClient.response);
7074
assertArrayEquals(RESPONSE.getBytes(), MyEndpointClient.response);
7175
}
@@ -81,10 +85,10 @@ public void testEndpointByteBuffer() throws URISyntaxException, DeploymentExcept
8185
*/
8286
@Test
8387
public void testEndpointByteArray() throws DeploymentException, IOException, URISyntaxException, InterruptedException {
88+
MyEndpointClient.latch = new CountDownLatch(1);
8489
Session session = connectToServer("bytearray");
8590
assertNotNull(session);
86-
System.out.println("Waiting for 2 seconds to receive response");
87-
Thread.sleep(2000);
91+
assertTrue(MyEndpointClient.latch.await(2, TimeUnit.SECONDS));
8892
assertNotNull(MyEndpointClient.response);
8993
assertArrayEquals(RESPONSE.getBytes(), MyEndpointClient.response);
9094
}
@@ -100,10 +104,10 @@ public void testEndpointByteArray() throws DeploymentException, IOException, URI
100104
*/
101105
@Test
102106
public void testEndpointInputStream() throws DeploymentException, IOException, URISyntaxException, InterruptedException {
107+
MyEndpointClient.latch = new CountDownLatch(1);
103108
Session session = connectToServer("inputstream");
104109
assertNotNull(session);
105-
System.out.println("Waiting for 2 seconds to receive response");
106-
Thread.sleep(2000);
110+
assertTrue(MyEndpointClient.latch.await(2, TimeUnit.SECONDS));
107111
assertNotNull(MyEndpointClient.response);
108112
assertArrayEquals(RESPONSE.getBytes(), MyEndpointClient.response);
109113
}
@@ -127,8 +131,6 @@ public Session connectToServer(String endpoint) throws DeploymentException, IOEx
127131
+ "/"
128132
+ base.getPath()
129133
+ "/"
130-
131-
// "localhost:8080/binary/""
132134
+ endpoint);
133135
System.out.println("Connecting to: " + uri);
134136
return container.connectToServer(MyEndpointClient.class, uri);

websocket/pom.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,4 @@
4646
<module>whiteboard</module>
4747
<module>endpoint-singleton</module>
4848
</modules>
49-
<dependencies>
50-
<dependency>
51-
<groupId>io.undertow</groupId>
52-
<artifactId>undertow-core</artifactId>
53-
<version>1.0.0.Beta20</version>
54-
<scope>test</scope>
55-
</dependency>
56-
<dependency>
57-
<groupId>io.undertow</groupId>
58-
<artifactId>undertow-websockets-jsr</artifactId>
59-
<version>1.0.0.Beta20</version>
60-
<scope>test</scope>
61-
</dependency>
62-
</dependencies>
6349
</project>

0 commit comments

Comments
 (0)