Http2EmptyDataFrameConnectionDecoder.frameListener() should return unwrapped Http2FrameListener (#9467)

Motivation:

As we decorate the Http2FrameListener under the covers we should ensure the user can still access the original Http2FrameListener.

Modifications:

- Unwrap the Http2FrameListener in frameListener()
- Add unit test

Result:

Less suprises for users.
This commit is contained in:
Norman Maurer 2019-08-16 08:16:15 +02:00
parent a1742d95da
commit e4d9a17ad9
2 changed files with 19 additions and 2 deletions

View File

@ -24,7 +24,7 @@ final class Http2EmptyDataFrameConnectionDecoder extends DecoratingHttp2Connecti
private final int maxConsecutiveEmptyFrames;
Http2EmptyDataFrameConnectionDecoder(Http2ConnectionDecoder delegate, int maxConsecutiveEmptyFrames) {
Http2EmptyDataFrameConnectionDecoder(Http2ConnectionDecoder delegate, int maxConsecutiveEmptyFrames) {
super(delegate);
this.maxConsecutiveEmptyFrames = ObjectUtil.checkPositive(
maxConsecutiveEmptyFrames, "maxConsecutiveEmptyFrames");
@ -38,4 +38,19 @@ final class Http2EmptyDataFrameConnectionDecoder extends DecoratingHttp2Connecti
super.frameListener(null);
}
}
@Override
public Http2FrameListener frameListener() {
Http2FrameListener frameListener = frameListener0();
// Unwrap the original Http2FrameListener as we add this decoder under the hood.
if (frameListener instanceof Http2EmptyDataFrameListener) {
return ((Http2EmptyDataFrameListener) frameListener).listener;
}
return frameListener;
}
// Package-private for testing
Http2FrameListener frameListener0() {
return super.frameListener();
}
}

View File

@ -44,7 +44,9 @@ public class Http2EmptyDataFrameConnectionDecoderTest {
decoder.frameListener(listener);
verify(delegate).frameListener(listenerArgumentCaptor.capture());
assertThat(decoder.frameListener(), CoreMatchers.instanceOf(Http2EmptyDataFrameListener.class));
assertThat(decoder.frameListener(),
CoreMatchers.not(CoreMatchers.instanceOf(Http2EmptyDataFrameListener.class)));
assertThat(decoder.frameListener0(), CoreMatchers.instanceOf(Http2EmptyDataFrameListener.class));
}
@Test