4040import org .xnio .OptionMap ;
4141import org .xnio .Options ;
4242
43- import java .io .IOException ;
4443import java .net .URI ;
4544import java .util .concurrent .Executors ;
4645import java .util .concurrent .ScheduledExecutorService ;
4746import java .util .concurrent .ScheduledFuture ;
4847import java .util .concurrent .TimeUnit ;
49- import java .util .concurrent .atomic .AtomicBoolean ;
5048
5149@ RunWith (DefaultServer .class )
5250@ HttpOneOnly
@@ -64,12 +62,6 @@ public static void beforeTest() {
6462 .set (Options .WRITE_TIMEOUT , DEFAULTS_IO_TIMEOUT_VALUE )
6563 .set (UndertowOptions .WEB_SOCKETS_READ_TIMEOUT , TESTABLE_TIMEOUT_VALUE )
6664 .set (UndertowOptions .WEB_SOCKETS_WRITE_TIMEOUT , NON_TESTABLE_TIMEOUT_VALUE ).getMap ());
67- /*
68- DefaultServer.setUndertowOptions(OptionMap.builder()
69- .set(Options.READ_TIMEOUT, regularTimeouts)
70- .set(Options.WRITE_TIMEOUT, regularTimeouts)
71- .set(UndertowOptions.WEB_SOCKETS_READ_TIMEOUT, wsReadTimeout)
72- .set(UndertowOptions.WEB_SOCKETS_WRITE_TIMEOUT, wsWriteTimeout).getMap());*/
7365 SCHEDULER = Executors .newScheduledThreadPool (2 );
7466 }
7567
@@ -85,13 +77,11 @@ protected WebSocketVersion getVersion() {
8577
8678 @ Test
8779 public void testServerReadTimeout () throws Exception {
88- final AtomicBoolean connected = new AtomicBoolean (false );
8980 DefaultServer .setRootHandler (new WebSocketProtocolHandshakeHandler (
9081 (WebSocketConnectionCallback ) (exchange , channel ) -> {
91- connected .set (true );
9282 channel .getReceiveSetter ().set (new AbstractReceiveListener () {
9383 @ Override
94- protected void onFullTextMessage (WebSocketChannel channel , BufferedTextMessage message ) throws IOException {
84+ protected void onFullTextMessage (WebSocketChannel channel , BufferedTextMessage message ) {
9585 String string = message .getData ();
9686
9787 if (string .equals ("hello" )) {
@@ -104,18 +94,18 @@ protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage m
10494 channel .resumeReceives ();
10595 }));
10696
107- final FutureResult <?> latch = new FutureResult ();
97+ final FutureResult <?> latch = new FutureResult <> ();
10898 WebSocketTestClient client = new WebSocketTestClient (getVersion (), new URI ("ws://" + NetworkUtils .formatPossibleIpv6Address (DefaultServer .getHostAddress ("default" )) + ":" + DefaultServer .getHostPort ("default" ) + "/" ));
10999 client .connect ();
110100 client .send (new TextWebSocketFrame (Unpooled .copiedBuffer ("hello" , CharsetUtil .US_ASCII )), new FrameChecker (TextWebSocketFrame .class , "world" .getBytes (CharsetUtil .US_ASCII ), latch ));
111101 latch .getIoFuture ().get ();
112102
113103 final long watchStart = System .currentTimeMillis ();
114104 final long watchTimeout = System .currentTimeMillis () + TESTABLE_TIMEOUT_VALUE + 1000 ;
115- final FutureResult <Long > timeoutLatch = new FutureResult <Long >();
105+ final FutureResult <Long > timeoutLatch = new FutureResult <>();
116106 ReadTimeoutChannelGuard readTimeoutChannelGuard = new ReadTimeoutChannelGuard (client , timeoutLatch , watchTimeout );
117107
118- final ScheduledFuture sf = SCHEDULER .scheduleAtFixedRate (readTimeoutChannelGuard , 0 , 50 , TimeUnit .MILLISECONDS );
108+ final ScheduledFuture <?> sf = SCHEDULER .scheduleAtFixedRate (readTimeoutChannelGuard , 0 , 50 , TimeUnit .MILLISECONDS );
119109 readTimeoutChannelGuard .setTaskScheduledFuture (sf );
120110
121111 final Long watchTimeEnd = timeoutLatch .getIoFuture ().get ();
@@ -143,7 +133,7 @@ private static class ReadTimeoutChannelGuard implements Runnable {
143133 this .watchEnd = watchEnd ;
144134 }
145135
146- public void setTaskScheduledFuture (ScheduledFuture sf2 ) {
136+ public void setTaskScheduledFuture (ScheduledFuture <?> sf2 ) {
147137 this .sf = sf2 ;
148138 }
149139
@@ -152,7 +142,7 @@ public void run() {
152142 if (System .currentTimeMillis () > watchEnd ) {
153143 sf .cancel (false );
154144 if (channelActive ()) {
155- resultHandler .setResult (new Long (- 1 ) );
145+ resultHandler .setResult (( long ) - 1 );
156146 } else {
157147 resultHandler .setResult (System .currentTimeMillis ());
158148 }
0 commit comments