Ensure Netty can be build with Java 11 (#7926)
Motivation: Java 11 will be out soon, so we should be able to build (and run tests) netty. Modifications: - Add dependency that is needed till Java 11 - Adjust tests so these also pass on Java 11 (SocketChannelImpl.close() behavious a bit differently now). Result: Build also works (and tests pass) on Java 11.
This commit is contained in:
parent
c990c121ea
commit
dc0cf3e099
@ -139,6 +139,12 @@
|
|||||||
<groupId>org.bouncycastle</groupId>
|
<groupId>org.bouncycastle</groupId>
|
||||||
<artifactId>bcprov-jdk15on</artifactId>
|
<artifactId>bcprov-jdk15on</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Needed on Java11 and later -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sun.activation</groupId>
|
||||||
|
<artifactId>javax.activation</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
24
pom.xml
24
pom.xml
@ -68,6 +68,23 @@
|
|||||||
</developers>
|
</developers>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
|
<!-- JDK11 -->
|
||||||
|
<profile>
|
||||||
|
<id>java11</id>
|
||||||
|
<activation>
|
||||||
|
<jdk>11</jdk>
|
||||||
|
</activation>
|
||||||
|
<properties>
|
||||||
|
<!-- Not use alpn agent as Java11 supports alpn out of the box -->
|
||||||
|
<argLine.alpnAgent />
|
||||||
|
<forbiddenapis.skip>true</forbiddenapis.skip>
|
||||||
|
<!-- Needed because of https://issues.apache.org/jira/browse/MENFORCER-275 -->
|
||||||
|
<enforcer.plugin.version>3.0.0-M1</enforcer.plugin.version>
|
||||||
|
<!-- 1.4.x does not work in Java10+ -->
|
||||||
|
<jboss.marshalling.version>2.0.5.Final</jboss.marshalling.version>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
|
||||||
<!-- JDK10 -->
|
<!-- JDK10 -->
|
||||||
<profile>
|
<profile>
|
||||||
<id>java10</id>
|
<id>java10</id>
|
||||||
@ -268,6 +285,13 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Needed for java11 and later as javax.activation is not part of the JDK anymore -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sun.activation</groupId>
|
||||||
|
<artifactId>javax.activation</artifactId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Byte code generator - completely optional -->
|
<!-- Byte code generator - completely optional -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.javassist</groupId>
|
<groupId>org.javassist</groupId>
|
||||||
|
@ -37,6 +37,7 @@ import io.netty.util.UncheckedBooleanSupplier;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
@ -327,8 +328,18 @@ public class SocketHalfClosedTest extends AbstractSocketTest {
|
|||||||
public void operationComplete(ChannelFuture future) throws Exception {
|
public void operationComplete(ChannelFuture future) throws Exception {
|
||||||
future.channel().close().addListener(new ChannelFutureListener() {
|
future.channel().close().addListener(new ChannelFutureListener() {
|
||||||
@Override
|
@Override
|
||||||
public void operationComplete(ChannelFuture future) throws Exception {
|
public void operationComplete(final ChannelFuture future) throws Exception {
|
||||||
followerCloseLatch.countDown();
|
// This is a bit racy but there is no better way how to handle this in Java11.
|
||||||
|
// The problem is that on close() the underlying FD will not actually be closed directly
|
||||||
|
// but the close will be done after the Selector did process all events. Because of
|
||||||
|
// this we will need to give it a bit time to ensure the FD is actual closed before we
|
||||||
|
// count down the latch and try to write.
|
||||||
|
future.channel().eventLoop().schedule(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
followerCloseLatch.countDown();
|
||||||
|
}
|
||||||
|
}, 200, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
|
import io.netty.util.internal.PlatformDependent;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -89,8 +91,16 @@ public class SocketRstTest extends AbstractSocketTest {
|
|||||||
|
|
||||||
// Verify the client received a RST.
|
// Verify the client received a RST.
|
||||||
Throwable cause = throwableRef.get();
|
Throwable cause = throwableRef.get();
|
||||||
|
if (PlatformDependent.javaVersion() >= 11 && sb.config().group() instanceof NioEventLoopGroup) {
|
||||||
|
// In Java11 calling SocketChannel.close() will also call shutdown(..,SHUT_WR) before actual closing the
|
||||||
|
// fd which means we may not see the ECONNRESET at all :(
|
||||||
|
if (cause == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
assertTrue("actual [type, message]: [" + cause.getClass() + ", " + cause.getMessage() + "]",
|
assertTrue("actual [type, message]: [" + cause.getClass() + ", " + cause.getMessage() + "]",
|
||||||
cause instanceof IOException);
|
cause instanceof IOException);
|
||||||
|
|
||||||
assertRstOnCloseException((IOException) cause, cc);
|
assertRstOnCloseException((IOException) cause, cc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user