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:
Norman Maurer 2018-05-12 20:25:11 +02:00 committed by GitHub
parent c990c121ea
commit dc0cf3e099
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 3 deletions

View File

@ -139,6 +139,12 @@
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</dependency>
<!-- Needed on Java11 and later -->
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
</dependency>
</dependencies>
<build>

24
pom.xml
View File

@ -68,6 +68,23 @@
</developers>
<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 -->
<profile>
<id>java10</id>
@ -268,6 +285,13 @@
<version>${project.version}</version>
</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 -->
<dependency>
<groupId>org.javassist</groupId>

View File

@ -37,6 +37,7 @@ import io.netty.util.UncheckedBooleanSupplier;
import org.junit.Test;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@ -327,8 +328,18 @@ public class SocketHalfClosedTest extends AbstractSocketTest {
public void operationComplete(ChannelFuture future) throws Exception {
future.channel().close().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
followerCloseLatch.countDown();
public void operationComplete(final ChannelFuture future) throws Exception {
// 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);
}
});
}

View File

@ -22,6 +22,8 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.internal.PlatformDependent;
import org.junit.Test;
import java.io.IOException;
@ -89,8 +91,16 @@ public class SocketRstTest extends AbstractSocketTest {
// Verify the client received a RST.
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() + "]",
cause instanceof IOException);
cause instanceof IOException);
assertRstOnCloseException((IOException) cause, cc);
}