GeezerVison is showing github.com — Auto-port 4.1: Consolidate fake exceptions in HTTP/2 tests into Http2… · netty/netty@64fb275
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 |
|---|
@@ -486,7 +486,7 @@ public Void answer(InvocationOnMock in) throws Throwable { | 486 | 486 | @Override | 487 | 487 | public Integer answer(InvocationOnMock in) throws Throwable { | 488 | 488 | localFlow.consumeBytes(stream, 4); | 489 | | - throw new RuntimeException("Fake Exception"); | | 489 | + throw Http2TestUtil.FAKE_EXCEPTION; | 490 | 490 | } | 491 | 491 | }).when(listener).onDataRead(eq(ctx), eq(STREAM_ID), any(ByteBuf.class), eq(10), eq(true)); | 492 | 492 | try { | |
Collapse file Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionEncoderTest.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -352,7 +352,7 @@ public void emptyFrameShouldSplitPadding() throws Exception { | 352 | 352 |
| 353 | 353 | @Test | 354 | 354 | public void writeHeadersUsingVoidPromise() throws Exception { | 355 | | - final Throwable cause = new RuntimeException("fake exception"); | | 355 | + final Throwable cause = Http2TestUtil.FAKE_EXCEPTION; | 356 | 356 | when(writer.writeHeaders(eq(ctx), eq(STREAM_ID), any(Http2Headers.class), | 357 | 357 | anyInt(), anyBoolean(), any(ChannelPromise.class))) | 358 | 358 | .then(new Answer<ChannelFuture>() { | |
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 |
|---|
@@ -718,7 +718,6 @@ private static void incrementAndGetStreamShouldSucceed(Endpoint<?> endpoint) thr | 718 | 718 | } | 719 | 719 |
| 720 | 720 | private static final class ListenerExceptionThrower implements Answer<Void> { | 721 | | - private static final RuntimeException FAKE_EXCEPTION = new RuntimeException("Fake Exception"); | 722 | 721 | private final boolean[] array; | 723 | 722 | private final int index; | 724 | 723 |
| @@ -730,7 +729,7 @@ private static final class ListenerExceptionThrower implements Answer<Void> { | 730 | 729 | @Override | 731 | 730 | public Void answer(InvocationOnMock invocation) throws Throwable { | 732 | 731 | array[index] = true; | 733 | | - throw FAKE_EXCEPTION; | | 732 | + throw Http2TestUtil.FAKE_EXCEPTION; | 734 | 733 | } | 735 | 734 | } | 736 | 735 |
| |
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 |
|---|
@@ -724,11 +724,10 @@ public Void answer(InvocationOnMock invocationOnMock) { | 724 | 724 | public void flowControlledWriteAndErrorThrowAnException() throws Exception { | 725 | 725 | final Http2RemoteFlowController.FlowControlled flowControlled = mockedFlowControlledThatThrowsOnWrite(); | 726 | 726 | final Http2Stream stream = stream(STREAM_A); | 727 | | - final RuntimeException fakeException = new RuntimeException("error failed"); | 728 | 727 | doAnswer(new Answer<Void>() { | 729 | 728 | @Override | 730 | 729 | public Void answer(InvocationOnMock invocationOnMock) { | 731 | | - throw fakeException; | | 730 | + throw Http2TestUtil.FAKE_EXCEPTION; | 732 | 731 | } | 733 | 732 | }).when(flowControlled).error(any(ChannelHandlerContext.class), any(Throwable.class)); | 734 | 733 |
| @@ -741,7 +740,7 @@ public void execute() throws Throwable { | 741 | 740 | controller.writePendingBytes(); | 742 | 741 | } | 743 | 742 | }); | 744 | | - assertSame(fakeException, e.getCause()); | | 743 | + assertSame(Http2TestUtil.FAKE_EXCEPTION, e.getCause()); | 745 | 744 |
| 746 | 745 | verify(flowControlled, atLeastOnce()).write(any(ChannelHandlerContext.class), anyInt()); | 747 | 746 | 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 +5-7Lines changed: 5 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -157,7 +157,7 @@ public void setup() throws Exception { | 157 | 157 | DefaultChannelConfig config = new DefaultChannelConfig(channel); | 158 | 158 | when(channel.config()).thenReturn(config); | 159 | 159 |
| 160 | | - Throwable fakeException = new RuntimeException("Fake exception"); | | 160 | + Throwable fakeException = Http2TestUtil.FAKE_EXCEPTION; | 161 | 161 | when(encoder.connection()).thenReturn(connection); | 162 | 162 | when(decoder.connection()).thenReturn(connection); | 163 | 163 | when(encoder.frameWriter()).thenReturn(frameWriter); | @@ -726,7 +726,6 @@ public void canSendGoAwayUsingVoidPromise() throws Exception { | 726 | 726 | ByteBuf data = dummyData(); | 727 | 727 | long errorCode = Http2Error.INTERNAL_ERROR.code(); | 728 | 728 | handler = newHandler(); | 729 | | - final Throwable cause = new RuntimeException("fake exception"); | 730 | 729 | doAnswer(new Answer<ChannelFuture>() { | 731 | 730 | @Override | 732 | 731 | public ChannelFuture answer(InvocationOnMock invocation) throws Throwable { | @@ -737,12 +736,12 @@ public ChannelFuture answer(InvocationOnMock invocation) throws Throwable { | 737 | 736 | new SimpleChannelPromiseAggregator(promise, channel, ImmediateEventExecutor.INSTANCE); | 738 | 737 | aggregatedPromise.newPromise(); | 739 | 738 | aggregatedPromise.doneAllocatingPromises(); | 740 | | - return aggregatedPromise.setFailure(cause); | | 739 | + return aggregatedPromise.setFailure(Http2TestUtil.FAKE_EXCEPTION); | 741 | 740 | } | 742 | 741 | }).when(frameWriter).writeGoAway( | 743 | 742 | any(ChannelHandlerContext.class), anyInt(), anyLong(), any(ByteBuf.class), any(ChannelPromise.class)); | 744 | 743 | handler.goAway(ctx, STREAM_ID, errorCode, data, newVoidPromise(channel)); | 745 | | - verify(pipeline).fireExceptionCaught(cause); | | 744 | + verify(pipeline).fireExceptionCaught(Http2TestUtil.FAKE_EXCEPTION); | 746 | 745 | } | 747 | 746 |
| 748 | 747 | @Test | @@ -894,20 +893,19 @@ public void operationComplete(ChannelFuture future) { | 894 | 893 |
| 895 | 894 | private void writeRstStreamUsingVoidPromise(int streamId) throws Exception { | 896 | 895 | handler = newHandler(); | 897 | | - final Throwable cause = new RuntimeException("fake exception"); | 898 | 896 | when(stream.id()).thenReturn(STREAM_ID); | 899 | 897 | when(frameWriter.writeRstStream(eq(ctx), eq(streamId), anyLong(), any(ChannelPromise.class))) | 900 | 898 | .then(new Answer<ChannelFuture>() { | 901 | 899 | @Override | 902 | 900 | public ChannelFuture answer(InvocationOnMock invocationOnMock) throws Throwable { | 903 | 901 | ChannelPromise promise = invocationOnMock.getArgument(3); | 904 | 902 | assertFalse(promise.isVoid()); | 905 | | - return promise.setFailure(cause); | | 903 | + return promise.setFailure(Http2TestUtil.FAKE_EXCEPTION); | 906 | 904 | } | 907 | 905 | }); | 908 | 906 | handler.resetStream(ctx, streamId, STREAM_CLOSED.code(), newVoidPromise(channel)); | 909 | 907 | verify(frameWriter).writeRstStream(eq(ctx), eq(streamId), anyLong(), any(ChannelPromise.class)); | 910 | | - verify(pipeline).fireExceptionCaught(cause); | | 908 | + verify(pipeline).fireExceptionCaught(Http2TestUtil.FAKE_EXCEPTION); | 911 | 909 | } | 912 | 910 |
| 913 | 911 | private static ByteBuf dummyData() { | |
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 |
|---|
@@ -624,7 +624,7 @@ public void handlerAdded(ChannelHandlerContext ctx) throws Exception { | 624 | 624 | @Test | 625 | 625 | public void listenerExceptionShouldCloseConnection() throws Exception { | 626 | 626 | final Http2Headers headers = dummyHeaders(); | 627 | | - doThrow(new RuntimeException("Fake Exception")).when(serverListener).onHeadersRead( | | 627 | + doThrow(Http2TestUtil.FAKE_EXCEPTION).when(serverListener).onHeadersRead( | 628 | 628 | any(ChannelHandlerContext.class), eq(3), eq(headers), eq(0), eq((short) 16), | 629 | 629 | eq(false), eq(0), eq(false)); | 630 | 630 |
| @@ -817,7 +817,7 @@ public void run() throws Http2Exception { | 817 | 817 | clientChannel.pipeline().addFirst(new ChannelHandlerAdapter() { | 818 | 818 | @Override | 819 | 819 | public void handlerAdded(ChannelHandlerContext ctx) throws Exception { | 820 | | - throw new RuntimeException("Fake Exception"); | | 820 | + throw Http2TestUtil.FAKE_EXCEPTION; | 821 | 821 | } | 822 | 822 | }); | 823 | 823 |
| |
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 |
|---|
| 57 | 57 | * Utilities for the integration tests. | 58 | 58 | */ | 59 | 59 | public final class Http2TestUtil { | | 60 | + /** | | 61 | + * A fake exception that can be used in tests to simulate errors. The stack trace is not filled in to avoid | | 62 | + * unnecessary overhead. | | 63 | + */ | | 64 | + static final RuntimeException FAKE_EXCEPTION = new RuntimeException("Fake exception") { | | 65 | + private static final long serialVersionUID = -8316972447187527869L; | | 66 | + | | 67 | + @Override | | 68 | + public Throwable fillInStackTrace() { | | 69 | + return this; | | 70 | + } | | 71 | + }; | | 72 | + | 60 | 73 | /** | 61 | 74 | * Interface that allows for running a operation that throws a {@link Http2Exception}. | 62 | 75 | */ | |
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); | |
|