|
1 | 1 | package hudson.remoting; |
2 | 2 |
|
| 3 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 4 | +import static org.hamcrest.Matchers.is; |
3 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; |
4 | 6 | import static org.junit.jupiter.api.Assertions.assertFalse; |
5 | 7 | import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
|
11 | 13 |
|
12 | 14 | import edu.umd.cs.findbugs.annotations.NonNull; |
13 | 15 | import hudson.remoting.util.GCTask; |
| 16 | +import java.io.EOFException; |
14 | 17 | import java.io.IOException; |
15 | 18 | import java.io.ObjectInputStream; |
16 | 19 | import java.io.ObjectStreamException; |
17 | 20 | import java.io.PrintWriter; |
18 | 21 | import java.io.StringWriter; |
19 | 22 | import java.net.URL; |
20 | 23 | import java.net.URLClassLoader; |
| 24 | +import java.nio.channels.ClosedChannelException; |
21 | 25 | import java.util.ArrayList; |
22 | 26 | import java.util.Collection; |
23 | 27 | import java.util.concurrent.ExecutorService; |
|
28 | 32 | import org.jenkinsci.remoting.RoleChecker; |
29 | 33 | import org.jenkinsci.remoting.SerializableOnlyOverRemoting; |
30 | 34 | import org.junit.jupiter.api.Disabled; |
| 35 | +import org.junit.jupiter.api.Test; |
31 | 36 | import org.junit.jupiter.params.ParameterizedTest; |
32 | 37 | import org.junit.jupiter.params.provider.MethodSource; |
33 | 38 | import org.jvnet.hudson.test.Issue; |
@@ -483,4 +488,37 @@ private void assertFailsWithChannelClosedException(Channel channel, TestRunnable |
483 | 488 | } |
484 | 489 | fail("Expected ChannelClosedException, but the call has completed without any exception"); |
485 | 490 | } |
| 491 | + |
| 492 | + @Test |
| 493 | + public void isClosedChannelException() { |
| 494 | + assertThat(Channel.isClosedChannelException(null), is(false)); |
| 495 | + assertThat(Channel.isClosedChannelException(new IOException()), is(false)); |
| 496 | + assertThat(Channel.isClosedChannelException(new ClosedChannelException()), is(true)); |
| 497 | + assertThat(Channel.isClosedChannelException(new ChannelClosedException((Channel) null, null)), is(true)); |
| 498 | + assertThat(Channel.isClosedChannelException(new EOFException()), is(true)); |
| 499 | + assertThat(Channel.isClosedChannelException(new RuntimeException(new ClosedChannelException())), is(true)); |
| 500 | + { |
| 501 | + var main = new RuntimeException(); |
| 502 | + main.addSuppressed(new ClosedChannelException()); |
| 503 | + assertThat(Channel.isClosedChannelException(main), is(true)); |
| 504 | + } |
| 505 | + { |
| 506 | + var level2 = new RuntimeException(new ClosedChannelException()); |
| 507 | + var level3 = new RuntimeException(); |
| 508 | + level3.addSuppressed(level2); |
| 509 | + assertThat(Channel.isClosedChannelException(new RuntimeException(level3)), is(true)); |
| 510 | + } |
| 511 | + { |
| 512 | + var cycle1 = new RuntimeException(); |
| 513 | + var cycle2 = new RuntimeException(cycle1); |
| 514 | + cycle1.addSuppressed(cycle2); |
| 515 | + assertThat(Channel.isClosedChannelException(cycle2), is(false)); |
| 516 | + } |
| 517 | + { |
| 518 | + var cycle1 = new ClosedChannelException(); |
| 519 | + var cycle2 = new RuntimeException(cycle1); |
| 520 | + cycle1.addSuppressed(cycle2); |
| 521 | + assertThat(Channel.isClosedChannelException(cycle2), is(true)); |
| 522 | + } |
| 523 | + } |
486 | 524 | } |
0 commit comments