GeezerVison is showing github.com — Consolidate fake exceptions in HTTP/2 tests into Http2TestUtil (#1671… · netty/netty@6a266af
File treeExpand file treeCollapse file tree Open diff view settings codec-http2/src/test/java/io/netty/handler/codec/http2
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoderTest.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -483,7 +483,7 @@ public Void answer(InvocationOnMock in) throws Throwable { | 483 | 483 | @Override | 484 | 484 | public Integer answer(InvocationOnMock in) throws Throwable { | 485 | 485 | localFlow.consumeBytes(stream, 4); | 486 | | - throw new RuntimeException("Fake Exception"); | | 486 | + throw Http2TestUtil.FAKE_EXCEPTION; | 487 | 487 | } | 488 | 488 | }).when(listener).onDataRead(eq(ctx), eq(STREAM_ID), any(ByteBuf.class), eq(10), eq(true)); | 489 | 489 | try { | |
Collapse file Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionTest.java +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -711,7 +711,6 @@ private static void incrementAndGetStreamShouldSucceed(Endpoint<?> endpoint) thr | 711 | 711 | } | 712 | 712 |
| 713 | 713 | private static final class ListenerExceptionThrower implements Answer<Void> { | 714 | | - private static final RuntimeException FAKE_EXCEPTION = new RuntimeException("Fake Exception"); | 715 | 714 | private final boolean[] array; | 716 | 715 | private final int index; | 717 | 716 |
| @@ -723,7 +722,7 @@ private static final class ListenerExceptionThrower implements Answer<Void> { | 723 | 722 | @Override | 724 | 723 | public Void answer(InvocationOnMock invocation) throws Throwable { | 725 | 724 | array[index] = true; | 726 | | - throw FAKE_EXCEPTION; | | 725 | + throw Http2TestUtil.FAKE_EXCEPTION; | 727 | 726 | } | 728 | 727 | } | 729 | 728 |
| |
Collapse file Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2RemoteFlowControllerTest.java +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -730,11 +730,10 @@ public Void answer(InvocationOnMock invocationOnMock) { | 730 | 730 | public void flowControlledWriteAndErrorThrowAnException() throws Exception { | 731 | 731 | final Http2RemoteFlowController.FlowControlled flowControlled = mockedFlowControlledThatThrowsOnWrite(); | 732 | 732 | final Http2Stream stream = stream(STREAM_A); | 733 | | - final RuntimeException fakeException = new RuntimeException("error failed"); | 734 | 733 | doAnswer(new Answer<Void>() { | 735 | 734 | @Override | 736 | 735 | public Void answer(InvocationOnMock invocationOnMock) { | 737 | | - throw fakeException; | | 736 | + throw Http2TestUtil.FAKE_EXCEPTION; | 738 | 737 | } | 739 | 738 | }).when(flowControlled).error(any(ChannelHandlerContext.class), any(Throwable.class)); | 740 | 739 |
| @@ -747,7 +746,7 @@ public void execute() throws Throwable { | 747 | 746 | controller.writePendingBytes(); | 748 | 747 | } | 749 | 748 | }); | 750 | | - assertSame(fakeException, e.getCause()); | | 749 | + assertSame(Http2TestUtil.FAKE_EXCEPTION, e.getCause()); | 751 | 750 |
| 752 | 751 | verify(flowControlled, atLeastOnce()).write(any(ChannelHandlerContext.class), anyInt()); | 753 | 752 | verify(flowControlled).error(any(ChannelHandlerContext.class), any(Throwable.class)); | |
Collapse file Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionHandlerTest.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -141,7 +141,7 @@ public void setup() throws Exception { | 141 | 141 | DefaultChannelConfig config = new DefaultChannelConfig(channel); | 142 | 142 | when(channel.config()).thenReturn(config); | 143 | 143 |
| 144 | | - Throwable fakeException = new RuntimeException("Fake exception"); | | 144 | + Throwable fakeException = Http2TestUtil.FAKE_EXCEPTION; | 145 | 145 | when(encoder.connection()).thenReturn(connection); | 146 | 146 | when(decoder.connection()).thenReturn(connection); | 147 | 147 | when(encoder.frameWriter()).thenReturn(frameWriter); | |
Collapse file Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -609,7 +609,7 @@ public void handlerAdded(ChannelHandlerContext ctx) throws Exception { | 609 | 609 | @Test | 610 | 610 | public void listenerExceptionShouldCloseConnection() throws Exception { | 611 | 611 | final Http2Headers headers = dummyHeaders(); | 612 | | - doThrow(new RuntimeException("Fake Exception")).when(serverListener).onHeadersRead( | | 612 | + doThrow(Http2TestUtil.FAKE_EXCEPTION).when(serverListener).onHeadersRead( | 613 | 613 | any(ChannelHandlerContext.class), eq(3), eq(headers), eq(0), eq((short) 16), | 614 | 614 | eq(false), eq(0), eq(false)); | 615 | 615 |
| @@ -797,7 +797,7 @@ public void run() throws Http2Exception { | 797 | 797 | clientChannel.pipeline().addFirst(new ChannelHandler() { | 798 | 798 | @Override | 799 | 799 | public void handlerAdded(ChannelHandlerContext ctx) throws Exception { | 800 | | - throw new RuntimeException("Fake Exception"); | | 800 | + throw Http2TestUtil.FAKE_EXCEPTION; | 801 | 801 | } | 802 | 802 | }); | 803 | 803 |
| |
Collapse file Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/Http2TestUtil.java +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 50 | 50 | * Utilities for the integration tests. | 51 | 51 | */ | 52 | 52 | public final class Http2TestUtil { | | 53 | + /** | | 54 | + * A fake exception that can be used in tests to simulate errors. The stack trace is not filled in to avoid | | 55 | + * unnecessary overhead. | | 56 | + */ | | 57 | + static final RuntimeException FAKE_EXCEPTION = new RuntimeException("Fake exception") { | | 58 | + private static final long serialVersionUID = -8316972447187527869L; | | 59 | + | | 60 | + @Override | | 61 | + public Throwable fillInStackTrace() { | | 62 | + return this; | | 63 | + } | | 64 | + }; | | 65 | + | 53 | 66 | /** | 54 | 67 | * Interface that allows for running a operation that throws a {@link Http2Exception}. | 55 | 68 | */ | |
Collapse file Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/UniformStreamByteDistributorTest.java +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -128,8 +128,7 @@ public void connectionErrorForWriterException() throws Http2Exception { | 128 | 128 | initState(STREAM_C, 3, true); | 129 | 129 | initState(STREAM_D, 4, true); | 130 | 130 |
| 131 | | - Exception fakeException = new RuntimeException("Fake exception"); | 132 | | - doThrow(fakeException).when(writer).write(same(stream(STREAM_C)), eq(3)); | | 131 | + doThrow(Http2TestUtil.FAKE_EXCEPTION).when(writer).write(same(stream(STREAM_C)), eq(3)); | 133 | 132 |
| 134 | 133 | Http2Exception e = assertThrows(Http2Exception.class, new Executable() { | 135 | 134 | @Override | @@ -139,7 +138,7 @@ public void execute() throws Throwable { | 139 | 138 | }); | 140 | 139 | assertFalse(Http2Exception.isStreamError(e)); | 141 | 140 | assertEquals(Http2Error.INTERNAL_ERROR, e.error()); | 142 | | - assertSame(fakeException, e.getCause()); | | 141 | + assertSame(Http2TestUtil.FAKE_EXCEPTION, e.getCause()); | 143 | 142 |
| 144 | 143 | verifyWrite(atMost(1), STREAM_A, 1); | 145 | 144 | verifyWrite(atMost(1), STREAM_B, 2); | |
Collapse file Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/WeightedFairQueueByteDistributorTest.java +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -150,8 +150,7 @@ public void connectionErrorForWriterException() throws Http2Exception { | 150 | 150 | initState(STREAM_C, 3, true); | 151 | 151 | initState(STREAM_D, 4, true); | 152 | 152 |
| 153 | | - Exception fakeException = new RuntimeException("Fake exception"); | 154 | | - doThrow(fakeException).when(writer).write(same(stream(STREAM_C)), eq(3)); | | 153 | + doThrow(Http2TestUtil.FAKE_EXCEPTION).when(writer).write(same(stream(STREAM_C)), eq(3)); | 155 | 154 |
| 156 | 155 | Http2Exception e = assertThrows(Http2Exception.class, new Executable() { | 157 | 156 | @Override | @@ -161,7 +160,7 @@ public void execute() throws Throwable { | 161 | 160 | }); | 162 | 161 | assertFalse(Http2Exception.isStreamError(e)); | 163 | 162 | assertEquals(Http2Error.INTERNAL_ERROR, e.error()); | 164 | | - assertSame(fakeException, e.getCause()); | | 163 | + assertSame(Http2TestUtil.FAKE_EXCEPTION, e.getCause()); | 165 | 164 |
| 166 | 165 | verifyWrite(atMost(1), STREAM_A, 1); | 167 | 166 | verifyWrite(atMost(1), STREAM_B, 2); | |
|