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 — Consolidate fake exceptions in HTTP/2 tests into Http2TestUtil (#1671… · netty/netty@6a266af

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
    • 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
@@ -483,7 +483,7 @@ public Void answer(InvocationOnMock in) throws Throwable {
483483
@Override
484484
public Integer answer(InvocationOnMock in) throws Throwable {
485485
localFlow.consumeBytes(stream, 4);
486-
throw new RuntimeException("Fake Exception");
486+
throw Http2TestUtil.FAKE_EXCEPTION;
487487
}
488488
}).when(listener).onDataRead(eq(ctx), eq(STREAM_ID), any(ByteBuf.class), eq(10), eq(true));
489489
try {
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
@@ -711,7 +711,6 @@ private static void incrementAndGetStreamShouldSucceed(Endpoint<?> endpoint) thr
711711
}
712712

713713
private static final class ListenerExceptionThrower implements Answer<Void> {
714-
private static final RuntimeException FAKE_EXCEPTION = new RuntimeException("Fake Exception");
715714
private final boolean[] array;
716715
private final int index;
717716

@@ -723,7 +722,7 @@ private static final class ListenerExceptionThrower implements Answer<Void> {
723722
@Override
724723
public Void answer(InvocationOnMock invocation) throws Throwable {
725724
array[index] = true;
726-
throw FAKE_EXCEPTION;
725+
throw Http2TestUtil.FAKE_EXCEPTION;
727726
}
728727
}
729728

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
@@ -730,11 +730,10 @@ public Void answer(InvocationOnMock invocationOnMock) {
730730
public void flowControlledWriteAndErrorThrowAnException() throws Exception {
731731
final Http2RemoteFlowController.FlowControlled flowControlled = mockedFlowControlledThatThrowsOnWrite();
732732
final Http2Stream stream = stream(STREAM_A);
733-
final RuntimeException fakeException = new RuntimeException("error failed");
734733
doAnswer(new Answer<Void>() {
735734
@Override
736735
public Void answer(InvocationOnMock invocationOnMock) {
737-
throw fakeException;
736+
throw Http2TestUtil.FAKE_EXCEPTION;
738737
}
739738
}).when(flowControlled).error(any(ChannelHandlerContext.class), any(Throwable.class));
740739

@@ -747,7 +746,7 @@ public void execute() throws Throwable {
747746
controller.writePendingBytes();
748747
}
749748
});
750-
assertSame(fakeException, e.getCause());
749+
assertSame(Http2TestUtil.FAKE_EXCEPTION, e.getCause());
751750

752751
verify(flowControlled, atLeastOnce()).write(any(ChannelHandlerContext.class), anyInt());
753752
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
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void setup() throws Exception {
141141
DefaultChannelConfig config = new DefaultChannelConfig(channel);
142142
when(channel.config()).thenReturn(config);
143143

144-
Throwable fakeException = new RuntimeException("Fake exception");
144+
Throwable fakeException = Http2TestUtil.FAKE_EXCEPTION;
145145
when(encoder.connection()).thenReturn(connection);
146146
when(decoder.connection()).thenReturn(connection);
147147
when(encoder.frameWriter()).thenReturn(frameWriter);
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
@@ -609,7 +609,7 @@ public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
609609
@Test
610610
public void listenerExceptionShouldCloseConnection() throws Exception {
611611
final Http2Headers headers = dummyHeaders();
612-
doThrow(new RuntimeException("Fake Exception")).when(serverListener).onHeadersRead(
612+
doThrow(Http2TestUtil.FAKE_EXCEPTION).when(serverListener).onHeadersRead(
613613
any(ChannelHandlerContext.class), eq(3), eq(headers), eq(0), eq((short) 16),
614614
eq(false), eq(0), eq(false));
615615

@@ -797,7 +797,7 @@ public void run() throws Http2Exception {
797797
clientChannel.pipeline().addFirst(new ChannelHandler() {
798798
@Override
799799
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
800-
throw new RuntimeException("Fake Exception");
800+
throw Http2TestUtil.FAKE_EXCEPTION;
801801
}
802802
});
803803

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
@@ -50,6 +50,19 @@
5050
* Utilities for the integration tests.
5151
*/
5252
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+
5366
/**
5467
* Interface that allows for running a operation that throws a {@link Http2Exception}.
5568
*/
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.