Ensure the tests complete on java7 and java9 as well.
Motivation:
379ac890f4
introduced the usage of the inline mock maker. This unfortunally not work on java7 and java9.
Modifications:
Just use reflection to create the event for now.
Result:
Netty tests pass again on java7 and java9 as well.
This commit is contained in:
parent
0fffc844d6
commit
5c572f0f63
@ -30,6 +30,7 @@ import io.netty.handler.codec.http.HttpMethod;
|
|||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
import io.netty.handler.codec.http.HttpScheme;
|
import io.netty.handler.codec.http.HttpScheme;
|
||||||
import io.netty.handler.codec.http.HttpServerUpgradeHandler;
|
import io.netty.handler.codec.http.HttpServerUpgradeHandler;
|
||||||
|
import io.netty.handler.codec.http.HttpServerUpgradeHandler.UpgradeEvent;
|
||||||
import io.netty.handler.codec.http.HttpVersion;
|
import io.netty.handler.codec.http.HttpVersion;
|
||||||
import io.netty.handler.codec.http2.Http2Exception.StreamException;
|
import io.netty.handler.codec.http2.Http2Exception.StreamException;
|
||||||
import io.netty.handler.codec.http2.Http2Stream.State;
|
import io.netty.handler.codec.http2.Http2Stream.State;
|
||||||
@ -40,13 +41,14 @@ import io.netty.util.ReferenceCounted;
|
|||||||
import io.netty.util.concurrent.DefaultPromise;
|
import io.netty.util.concurrent.DefaultPromise;
|
||||||
import io.netty.util.concurrent.GlobalEventExecutor;
|
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||||
import io.netty.util.concurrent.Promise;
|
import io.netty.util.concurrent.Promise;
|
||||||
|
import io.netty.util.internal.ReflectionUtil;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.Assume;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
|
||||||
import org.mockito.stubbing.Answer;
|
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -648,28 +650,20 @@ public class Http2FrameCodecTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void upgradeEventNoRefCntError() throws Http2Exception {
|
public void upgradeEventNoRefCntError() throws Exception {
|
||||||
frameListener.onHeadersRead(http2HandlerCtx, Http2CodecUtil.HTTP_UPGRADE_STREAM_ID, request, 31, false);
|
frameListener.onHeadersRead(http2HandlerCtx, Http2CodecUtil.HTTP_UPGRADE_STREAM_ID, request, 31, false);
|
||||||
|
|
||||||
final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
|
// Using reflect as the constructor is package-private and the class is final.
|
||||||
final HttpServerUpgradeHandler.UpgradeEvent upgradeEvent = mock(HttpServerUpgradeHandler.UpgradeEvent.class);
|
Constructor<UpgradeEvent> constructor =
|
||||||
when(upgradeEvent.retain()).thenAnswer(new Answer<HttpServerUpgradeHandler.UpgradeEvent>() {
|
UpgradeEvent.class.getDeclaredConstructor(CharSequence.class, FullHttpRequest.class);
|
||||||
@Override
|
|
||||||
public HttpServerUpgradeHandler.UpgradeEvent answer(InvocationOnMock invocationOnMock) throws Throwable {
|
|
||||||
request.retain();
|
|
||||||
return upgradeEvent;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
when(upgradeEvent.release()).thenAnswer(new Answer<Boolean>() {
|
|
||||||
@Override
|
|
||||||
public Boolean answer(InvocationOnMock invocationOnMock) throws Throwable {
|
|
||||||
return request.release();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
when(upgradeEvent.upgradeRequest()).thenReturn(request);
|
// Check if we could make it accessible which may fail on java9.
|
||||||
|
Assume.assumeTrue(ReflectionUtil.trySetAccessible(constructor) == null);
|
||||||
|
|
||||||
|
HttpServerUpgradeHandler.UpgradeEvent upgradeEvent = constructor.newInstance(
|
||||||
|
"HTTP/2", new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));
|
||||||
channel.pipeline().fireUserEventTriggered(upgradeEvent);
|
channel.pipeline().fireUserEventTriggered(upgradeEvent);
|
||||||
assertEquals(1, request.refCnt());
|
assertEquals(1, upgradeEvent.refCnt());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ChannelPromise anyChannelPromise() {
|
private static ChannelPromise anyChannelPromise() {
|
||||||
|
@ -1 +0,0 @@
|
|||||||
mock-maker-inline
|
|
Loading…
Reference in New Issue
Block a user