|
29 | 29 | import io.netty.handler.ssl.SslContext;
|
30 | 30 | import io.netty.handler.ssl.SslContextBuilder;
|
31 | 31 | import io.netty.handler.ssl.SslHandler;
|
| 32 | +import io.netty.handler.timeout.ReadTimeoutException; |
| 33 | +import io.netty.handler.timeout.WriteTimeoutException; |
32 | 34 | import io.netty.util.Attribute;
|
33 | 35 | import io.netty.util.AttributeKey;
|
34 | 36 | import io.netty.util.concurrent.EventExecutor;
|
35 | 37 | import io.netty.util.concurrent.Future;
|
36 | 38 | import io.netty.util.concurrent.GenericFutureListener;
|
37 | 39 | import io.netty.util.concurrent.Promise;
|
| 40 | +import java.io.IOException; |
| 41 | +import java.nio.channels.ClosedChannelException; |
38 | 42 | import java.time.Duration;
|
| 43 | +import java.util.concurrent.TimeoutException; |
39 | 44 | import java.util.concurrent.atomic.AtomicBoolean;
|
40 | 45 | import java.util.concurrent.atomic.AtomicReference;
|
41 | 46 | import javax.net.ssl.SSLEngine;
|
@@ -268,4 +273,109 @@ public void closedChannelMessage_with_nullParentChannelAttribute() throws Except
|
268 | 273 | assertThat(NettyUtils.closedChannelMessage(channel))
|
269 | 274 | .isEqualTo(NettyUtils.CLOSED_CHANNEL_ERROR_MESSAGE);
|
270 | 275 | }
|
| 276 | + |
| 277 | + @Test |
| 278 | + public void decorateException_with_TimeoutException() { |
| 279 | + |
| 280 | + Channel channel = mock(Channel.class); |
| 281 | + Throwable timeoutException = new TimeoutException("...Acquire operation took longer..."); |
| 282 | + Throwable output = NettyUtils.decorateException(channel, timeoutException); |
| 283 | + |
| 284 | + assertThat(output).isInstanceOf(Throwable.class); |
| 285 | + assertThat(output.getCause()).isInstanceOf(TimeoutException.class); |
| 286 | + assertThat(output.getMessage()).isNotNull(); |
| 287 | + } |
| 288 | + |
| 289 | + @Test |
| 290 | + public void decorateException_with_TimeoutException_noMsg() { |
| 291 | + |
| 292 | + Channel channel = mock(Channel.class); |
| 293 | + Throwable timeoutException = new TimeoutException(); |
| 294 | + Throwable output = NettyUtils.decorateException(channel, timeoutException); |
| 295 | + |
| 296 | + assertThat(output).isInstanceOf(TimeoutException.class); |
| 297 | + assertThat(output.getCause()).isNull(); |
| 298 | + } |
| 299 | + |
| 300 | + @Test |
| 301 | + public void decorateException_with_IllegalStateException() { |
| 302 | + |
| 303 | + Channel channel = mock(Channel.class); |
| 304 | + Throwable illegalStateException = new IllegalStateException("...Too many outstanding acquire operations..."); |
| 305 | + Throwable output = NettyUtils.decorateException(channel, illegalStateException); |
| 306 | + |
| 307 | + assertThat(output).isInstanceOf(Throwable.class); |
| 308 | + assertThat(output.getCause()).isInstanceOf(IllegalStateException.class); |
| 309 | + assertThat(output.getMessage()).isNotNull(); |
| 310 | + } |
| 311 | + |
| 312 | + @Test |
| 313 | + public void decorateException_with_IllegalStateException_noMsg() { |
| 314 | + |
| 315 | + Channel channel = mock(Channel.class); |
| 316 | + Throwable illegalStateException = new IllegalStateException(); |
| 317 | + Throwable output = NettyUtils.decorateException(channel, illegalStateException); |
| 318 | + |
| 319 | + assertThat(output).isInstanceOf(IllegalStateException.class); |
| 320 | + assertThat(output.getCause()).isNull(); |
| 321 | + } |
| 322 | + |
| 323 | + @Test |
| 324 | + public void decorateException_with_ReadTimeoutException() { |
| 325 | + |
| 326 | + Channel channel = mock(Channel.class); |
| 327 | + Throwable readTimeoutException = new ReadTimeoutException(); |
| 328 | + Throwable output = NettyUtils.decorateException(channel, readTimeoutException); |
| 329 | + |
| 330 | + assertThat(output).isInstanceOf(IOException.class); |
| 331 | + assertThat(output.getCause()).isInstanceOf(ReadTimeoutException.class); |
| 332 | + assertThat(output.getMessage()).isNotNull(); |
| 333 | + } |
| 334 | + |
| 335 | + @Test |
| 336 | + public void decorateException_with_WriteTimeoutException() { |
| 337 | + |
| 338 | + Channel channel = mock(Channel.class); |
| 339 | + Throwable writeTimeoutException = new WriteTimeoutException(); |
| 340 | + Throwable output = NettyUtils.decorateException(channel, writeTimeoutException); |
| 341 | + |
| 342 | + assertThat(output).isInstanceOf(IOException.class); |
| 343 | + assertThat(output.getCause()).isInstanceOf(WriteTimeoutException.class); |
| 344 | + assertThat(output.getMessage()).isNotNull(); |
| 345 | + } |
| 346 | + |
| 347 | + @Test |
| 348 | + public void decorateException_with_ClosedChannelException() { |
| 349 | + |
| 350 | + Channel channel = mock(Channel.class); |
| 351 | + Throwable closedChannelException = new ClosedChannelException(); |
| 352 | + Throwable output = NettyUtils.decorateException(channel, closedChannelException); |
| 353 | + |
| 354 | + assertThat(output).isInstanceOf(IOException.class); |
| 355 | + assertThat(output.getCause()).isInstanceOf(ClosedChannelException.class); |
| 356 | + assertThat(output.getMessage()).isNotNull(); |
| 357 | + } |
| 358 | + |
| 359 | + @Test |
| 360 | + public void decorateException_with_IOException_reset() { |
| 361 | + |
| 362 | + Channel channel = mock(Channel.class); |
| 363 | + Throwable closedChannelException = new IOException("...Connection reset by peer..."); |
| 364 | + Throwable output = NettyUtils.decorateException(channel, closedChannelException); |
| 365 | + |
| 366 | + assertThat(output).isInstanceOf(IOException.class); |
| 367 | + assertThat(output.getCause()).isInstanceOf(IOException.class); |
| 368 | + assertThat(output.getMessage()).isNotNull(); |
| 369 | + } |
| 370 | + |
| 371 | + @Test |
| 372 | + public void decorateException_with_IOException_noMsg() { |
| 373 | + |
| 374 | + Channel channel = mock(Channel.class); |
| 375 | + Throwable closedChannelException = new IOException(); |
| 376 | + Throwable output = NettyUtils.decorateException(channel, closedChannelException); |
| 377 | + |
| 378 | + assertThat(output).isInstanceOf(IOException.class); |
| 379 | + assertThat(output.getCause()).isNull(); |
| 380 | + } |
271 | 381 | }
|
0 commit comments