2222import java .io .InputStream ;
2323import java .nio .ByteBuffer ;
2424import java .nio .channels .Channel ;
25+ import java .nio .channels .ClosedChannelException ;
2526import java .util .concurrent .CountDownLatch ;
2627import java .util .concurrent .TimeUnit ;
2728
3132import org .apache .http .HttpResponse ;
3233import org .apache .http .client .methods .HttpGet ;
3334import org .junit .Assert ;
34- import org .junit .Ignore ;
3535import org .junit .Test ;
3636import org .junit .runner .RunWith ;
3737import org .xnio .ChannelListener ;
4747 */
4848@ RunWith (DefaultServer .class )
4949@ HttpOneOnly
50- @ Ignore ("UNDERTOW-1859 this test freezes" ) //FIXME
50+ // @Ignore("UNDERTOW-1859 this test freezes") //FIXME
5151public class WriteTimeoutTestCase {
5252
5353 private volatile Exception exception ;
@@ -92,12 +92,10 @@ public void handleEvent(final Channel channel) {
9292 do {
9393 try {
9494 int res = response .write (buffer );
95- if (res == 0 ) {
96- return ;
97- }
9895 } catch (IOException e ) {
9996 exception = e ;
10097 errorLatch .countDown ();
98+ break ;
10199 }
102100 if (!buffer .hasRemaining ()) {
103101 count ++;
@@ -122,14 +120,20 @@ public void handleEvent(final Channel channel) {
122120 while ((r = content .read (buffer )) > 0 ) {
123121 Thread .sleep (200 );
124122 if (exception != null ) {
125- Assert .assertEquals (WriteTimeoutException .class , exception .getClass ());
123+ // Depending on whether the timeout is triggered inside XNIO or in the WriteTimeoutStreamSinkConduit,
124+ // we get either WriteTimeoutException or ClosedChannelException.
125+ Assert .assertTrue ("Unexpected exception class: " + exception .getClass (),
126+ exception instanceof WriteTimeoutException || exception instanceof ClosedChannelException );
126127 return ;
127128 }
128129 }
129130 Assert .fail ("Write did not time out" );
130131 } catch (IOException e ) {
131132 if (errorLatch .await (5 , TimeUnit .SECONDS )) {
132- Assert .assertEquals (WriteTimeoutException .class , exception .getClass ());
133+ // Depending on whether the timeout is triggered inside XNIO or in the WriteTimeoutStreamSinkConduit,
134+ // we get either WriteTimeoutException or ClosedChannelException.
135+ Assert .assertTrue ("Unexpected exception class: " + exception .getClass (),
136+ exception instanceof WriteTimeoutException || exception instanceof ClosedChannelException );
133137 } else {
134138 Assert .fail ("Write did not time out" );
135139 }
0 commit comments