GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Auto-port 4.1: Consolidate fake exceptions in HTTP/2 tests into Http2… · netty/netty@64fb275

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http2/src/test/java/io/netty/handler/codec/http2
    • DefaultHttp2ConnectionDecoderTest.java
    • DefaultHttp2ConnectionEncoderTest.java
    • DefaultHttp2ConnectionTest.java
    • DefaultHttp2RemoteFlowControllerTest.java
    • Http2ConnectionHandlerTest.java
    • Http2ConnectionRoundtripTest.java
    • Http2TestUtil.java
    • UniformStreamByteDistributorTest.java
    • WeightedFairQueueByteDistributorTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoderTest.java‎

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 numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public Void answer(InvocationOnMock in) throws Throwable {
486486
@Override
487487
public Integer answer(InvocationOnMock in) throws Throwable {
488488
localFlow.consumeBytes(stream, 4);
489-
throw new RuntimeException("Fake Exception");
489+
throw Http2TestUtil.FAKE_EXCEPTION;
490490
}
491491
}).when(listener).onDataRead(eq(ctx), eq(STREAM_ID), any(ByteBuf.class), eq(10), eq(true));
492492
try {
Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionEncoderTest.java‎

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 numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public void emptyFrameShouldSplitPadding() throws Exception {
352352

353353
@Test
354354
public void writeHeadersUsingVoidPromise() throws Exception {
355-
final Throwable cause = new RuntimeException("fake exception");
355+
final Throwable cause = Http2TestUtil.FAKE_EXCEPTION;
356356
when(writer.writeHeaders(eq(ctx), eq(STREAM_ID), any(Http2Headers.class),
357357
anyInt(), anyBoolean(), any(ChannelPromise.class)))
358358
.then(new Answer<ChannelFuture>() {
Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionTest.java‎

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 numberDiff line numberDiff line change
@@ -718,7 +718,6 @@ private static void incrementAndGetStreamShouldSucceed(Endpoint<?> endpoint) thr
718718
}
719719

720720
private static final class ListenerExceptionThrower implements Answer<Void> {
721-
private static final RuntimeException FAKE_EXCEPTION = new RuntimeException("Fake Exception");
722721
private final boolean[] array;
723722
private final int index;
724723

@@ -730,7 +729,7 @@ private static final class ListenerExceptionThrower implements Answer<Void> {
730729
@Override
731730
public Void answer(InvocationOnMock invocation) throws Throwable {
732731
array[index] = true;
733-
throw FAKE_EXCEPTION;
732+
throw Http2TestUtil.FAKE_EXCEPTION;
734733
}
735734
}
736735

Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2RemoteFlowControllerTest.java‎

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 numberDiff line numberDiff line change
@@ -724,11 +724,10 @@ public Void answer(InvocationOnMock invocationOnMock) {
724724
public void flowControlledWriteAndErrorThrowAnException() throws Exception {
725725
final Http2RemoteFlowController.FlowControlled flowControlled = mockedFlowControlledThatThrowsOnWrite();
726726
final Http2Stream stream = stream(STREAM_A);
727-
final RuntimeException fakeException = new RuntimeException("error failed");
728727
doAnswer(new Answer<Void>() {
729728
@Override
730729
public Void answer(InvocationOnMock invocationOnMock) {
731-
throw fakeException;
730+
throw Http2TestUtil.FAKE_EXCEPTION;
732731
}
733732
}).when(flowControlled).error(any(ChannelHandlerContext.class), any(Throwable.class));
734733

@@ -741,7 +740,7 @@ public void execute() throws Throwable {
741740
controller.writePendingBytes();
742741
}
743742
});
744-
assertSame(fakeException, e.getCause());
743+
assertSame(Http2TestUtil.FAKE_EXCEPTION, e.getCause());
745744

746745
verify(flowControlled, atLeastOnce()).write(any(ChannelHandlerContext.class), anyInt());
747746
verify(flowControlled).error(any(ChannelHandlerContext.class), any(Throwable.class));
Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionHandlerTest.java‎

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 numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void setup() throws Exception {
157157
DefaultChannelConfig config = new DefaultChannelConfig(channel);
158158
when(channel.config()).thenReturn(config);
159159

160-
Throwable fakeException = new RuntimeException("Fake exception");
160+
Throwable fakeException = Http2TestUtil.FAKE_EXCEPTION;
161161
when(encoder.connection()).thenReturn(connection);
162162
when(decoder.connection()).thenReturn(connection);
163163
when(encoder.frameWriter()).thenReturn(frameWriter);
@@ -726,7 +726,6 @@ public void canSendGoAwayUsingVoidPromise() throws Exception {
726726
ByteBuf data = dummyData();
727727
long errorCode = Http2Error.INTERNAL_ERROR.code();
728728
handler = newHandler();
729-
final Throwable cause = new RuntimeException("fake exception");
730729
doAnswer(new Answer<ChannelFuture>() {
731730
@Override
732731
public ChannelFuture answer(InvocationOnMock invocation) throws Throwable {
@@ -737,12 +736,12 @@ public ChannelFuture answer(InvocationOnMock invocation) throws Throwable {
737736
new SimpleChannelPromiseAggregator(promise, channel, ImmediateEventExecutor.INSTANCE);
738737
aggregatedPromise.newPromise();
739738
aggregatedPromise.doneAllocatingPromises();
740-
return aggregatedPromise.setFailure(cause);
739+
return aggregatedPromise.setFailure(Http2TestUtil.FAKE_EXCEPTION);
741740
}
742741
}).when(frameWriter).writeGoAway(
743742
any(ChannelHandlerContext.class), anyInt(), anyLong(), any(ByteBuf.class), any(ChannelPromise.class));
744743
handler.goAway(ctx, STREAM_ID, errorCode, data, newVoidPromise(channel));
745-
verify(pipeline).fireExceptionCaught(cause);
744+
verify(pipeline).fireExceptionCaught(Http2TestUtil.FAKE_EXCEPTION);
746745
}
747746

748747
@Test
@@ -894,20 +893,19 @@ public void operationComplete(ChannelFuture future) {
894893

895894
private void writeRstStreamUsingVoidPromise(int streamId) throws Exception {
896895
handler = newHandler();
897-
final Throwable cause = new RuntimeException("fake exception");
898896
when(stream.id()).thenReturn(STREAM_ID);
899897
when(frameWriter.writeRstStream(eq(ctx), eq(streamId), anyLong(), any(ChannelPromise.class)))
900898
.then(new Answer<ChannelFuture>() {
901899
@Override
902900
public ChannelFuture answer(InvocationOnMock invocationOnMock) throws Throwable {
903901
ChannelPromise promise = invocationOnMock.getArgument(3);
904902
assertFalse(promise.isVoid());
905-
return promise.setFailure(cause);
903+
return promise.setFailure(Http2TestUtil.FAKE_EXCEPTION);
906904
}
907905
});
908906
handler.resetStream(ctx, streamId, STREAM_CLOSED.code(), newVoidPromise(channel));
909907
verify(frameWriter).writeRstStream(eq(ctx), eq(streamId), anyLong(), any(ChannelPromise.class));
910-
verify(pipeline).fireExceptionCaught(cause);
908+
verify(pipeline).fireExceptionCaught(Http2TestUtil.FAKE_EXCEPTION);
911909
}
912910

913911
private static ByteBuf dummyData() {
Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java‎

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 numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
624624
@Test
625625
public void listenerExceptionShouldCloseConnection() throws Exception {
626626
final Http2Headers headers = dummyHeaders();
627-
doThrow(new RuntimeException("Fake Exception")).when(serverListener).onHeadersRead(
627+
doThrow(Http2TestUtil.FAKE_EXCEPTION).when(serverListener).onHeadersRead(
628628
any(ChannelHandlerContext.class), eq(3), eq(headers), eq(0), eq((short) 16),
629629
eq(false), eq(0), eq(false));
630630

@@ -817,7 +817,7 @@ public void run() throws Http2Exception {
817817
clientChannel.pipeline().addFirst(new ChannelHandlerAdapter() {
818818
@Override
819819
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
820-
throw new RuntimeException("Fake Exception");
820+
throw Http2TestUtil.FAKE_EXCEPTION;
821821
}
822822
});
823823

Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/Http2TestUtil.java‎

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 numberDiff line numberDiff line change
@@ -57,6 +57,19 @@
5757
* Utilities for the integration tests.
5858
*/
5959
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+
6073
/**
6174
* Interface that allows for running a operation that throws a {@link Http2Exception}.
6275
*/
Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/UniformStreamByteDistributorTest.java‎

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 numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ public void connectionErrorForWriterException() throws Http2Exception {
128128
initState(STREAM_C, 3, true);
129129
initState(STREAM_D, 4, true);
130130

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));
133132

134133
Http2Exception e = assertThrows(Http2Exception.class, new Executable() {
135134
@Override
@@ -139,7 +138,7 @@ public void execute() throws Throwable {
139138
});
140139
assertFalse(Http2Exception.isStreamError(e));
141140
assertEquals(Http2Error.INTERNAL_ERROR, e.error());
142-
assertSame(fakeException, e.getCause());
141+
assertSame(Http2TestUtil.FAKE_EXCEPTION, e.getCause());
143142

144143
verifyWrite(atMost(1), STREAM_A, 1);
145144
verifyWrite(atMost(1), STREAM_B, 2);
Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/WeightedFairQueueByteDistributorTest.java‎

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 numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ public void connectionErrorForWriterException() throws Http2Exception {
150150
initState(STREAM_C, 3, true);
151151
initState(STREAM_D, 4, true);
152152

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));
155154

156155
Http2Exception e = assertThrows(Http2Exception.class, new Executable() {
157156
@Override
@@ -161,7 +160,7 @@ public void execute() throws Throwable {
161160
});
162161
assertFalse(Http2Exception.isStreamError(e));
163162
assertEquals(Http2Error.INTERNAL_ERROR, e.error());
164-
assertSame(fakeException, e.getCause());
163+
assertSame(Http2TestUtil.FAKE_EXCEPTION, e.getCause());
165164

166165
verifyWrite(atMost(1), STREAM_A, 1);
167166
verifyWrite(atMost(1), STREAM_B, 2);

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.