33 */
44package 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+
710import java .io .IOException ;
811import java .net .URI ;
912import 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 ;
1217import javax .websocket .DeploymentException ;
1318import javax .websocket .Session ;
1419import javax .websocket .WebSocketContainer ;
2227import org .jboss .arquillian .test .api .ArquillianResource ;
2328import org .jboss .shrinkwrap .api .ShrinkWrap ;
2429import org .jboss .shrinkwrap .api .spec .WebArchive ;
25- import static org .junit .Assert .*;
2630import org .junit .Test ;
2731import 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 );
0 commit comments