40
40
import org .xnio .OptionMap ;
41
41
import org .xnio .Options ;
42
42
43
- import java .io .IOException ;
44
43
import java .net .URI ;
45
44
import java .util .concurrent .Executors ;
46
45
import java .util .concurrent .ScheduledExecutorService ;
47
46
import java .util .concurrent .ScheduledFuture ;
48
47
import java .util .concurrent .TimeUnit ;
49
- import java .util .concurrent .atomic .AtomicBoolean ;
50
48
51
49
@ RunWith (DefaultServer .class )
52
50
@ HttpOneOnly
@@ -64,12 +62,6 @@ public static void beforeTest() {
64
62
.set (Options .WRITE_TIMEOUT , DEFAULTS_IO_TIMEOUT_VALUE )
65
63
.set (UndertowOptions .WEB_SOCKETS_READ_TIMEOUT , TESTABLE_TIMEOUT_VALUE )
66
64
.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());*/
73
65
SCHEDULER = Executors .newScheduledThreadPool (2 );
74
66
}
75
67
@@ -85,13 +77,11 @@ protected WebSocketVersion getVersion() {
85
77
86
78
@ Test
87
79
public void testServerReadTimeout () throws Exception {
88
- final AtomicBoolean connected = new AtomicBoolean (false );
89
80
DefaultServer .setRootHandler (new WebSocketProtocolHandshakeHandler (
90
81
(WebSocketConnectionCallback ) (exchange , channel ) -> {
91
- connected .set (true );
92
82
channel .getReceiveSetter ().set (new AbstractReceiveListener () {
93
83
@ Override
94
- protected void onFullTextMessage (WebSocketChannel channel , BufferedTextMessage message ) throws IOException {
84
+ protected void onFullTextMessage (WebSocketChannel channel , BufferedTextMessage message ) {
95
85
String string = message .getData ();
96
86
97
87
if (string .equals ("hello" )) {
@@ -104,18 +94,18 @@ protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage m
104
94
channel .resumeReceives ();
105
95
}));
106
96
107
- final FutureResult <?> latch = new FutureResult ();
97
+ final FutureResult <?> latch = new FutureResult <> ();
108
98
WebSocketTestClient client = new WebSocketTestClient (getVersion (), new URI ("ws://" + NetworkUtils .formatPossibleIpv6Address (DefaultServer .getHostAddress ("default" )) + ":" + DefaultServer .getHostPort ("default" ) + "/" ));
109
99
client .connect ();
110
100
client .send (new TextWebSocketFrame (Unpooled .copiedBuffer ("hello" , CharsetUtil .US_ASCII )), new FrameChecker (TextWebSocketFrame .class , "world" .getBytes (CharsetUtil .US_ASCII ), latch ));
111
101
latch .getIoFuture ().get ();
112
102
113
103
final long watchStart = System .currentTimeMillis ();
114
104
final long watchTimeout = System .currentTimeMillis () + TESTABLE_TIMEOUT_VALUE + 1000 ;
115
- final FutureResult <Long > timeoutLatch = new FutureResult <Long >();
105
+ final FutureResult <Long > timeoutLatch = new FutureResult <>();
116
106
ReadTimeoutChannelGuard readTimeoutChannelGuard = new ReadTimeoutChannelGuard (client , timeoutLatch , watchTimeout );
117
107
118
- final ScheduledFuture sf = SCHEDULER .scheduleAtFixedRate (readTimeoutChannelGuard , 0 , 50 , TimeUnit .MILLISECONDS );
108
+ final ScheduledFuture <?> sf = SCHEDULER .scheduleAtFixedRate (readTimeoutChannelGuard , 0 , 50 , TimeUnit .MILLISECONDS );
119
109
readTimeoutChannelGuard .setTaskScheduledFuture (sf );
120
110
121
111
final Long watchTimeEnd = timeoutLatch .getIoFuture ().get ();
@@ -143,7 +133,7 @@ private static class ReadTimeoutChannelGuard implements Runnable {
143
133
this .watchEnd = watchEnd ;
144
134
}
145
135
146
- public void setTaskScheduledFuture (ScheduledFuture sf2 ) {
136
+ public void setTaskScheduledFuture (ScheduledFuture <?> sf2 ) {
147
137
this .sf = sf2 ;
148
138
}
149
139
@@ -152,7 +142,7 @@ public void run() {
152
142
if (System .currentTimeMillis () > watchEnd ) {
153
143
sf .cancel (false );
154
144
if (channelActive ()) {
155
- resultHandler .setResult (new Long (- 1 ) );
145
+ resultHandler .setResult (( long ) - 1 );
156
146
} else {
157
147
resultHandler .setResult (System .currentTimeMillis ());
158
148
}
0 commit comments