Repository: incubator-ratis Updated Branches: refs/heads/master 1d2ebee02 -> 27c2dfe6e
RATIS-262. Fix compilation warning and deprecated api usage. Project: http://git-wip-us.apache.org/repos/asf/incubator-ratis/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ratis/commit/27c2dfe6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ratis/tree/27c2dfe6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ratis/diff/27c2dfe6 Branch: refs/heads/master Commit: 27c2dfe6e30fb51f209e57ee9d40c14bb5c14f9a Parents: 1d2ebee Author: Tsz Wo Nicholas Sze <[email protected]> Authored: Fri Nov 2 07:09:34 2018 +0800 Committer: Tsz Wo Nicholas Sze <[email protected]> Committed: Fri Nov 2 07:09:34 2018 +0800 ---------------------------------------------------------------------- pom.xml | 1 - .../main/java/org/apache/ratis/util/JavaUtils.java | 6 ++++++ .../main/java/org/apache/ratis/util/LogUtils.java | 3 ++- .../java/org/apache/ratis/util/TimeoutScheduler.java | 2 +- .../src/test/java/org/apache/ratis/BaseTest.java | 9 +++++++-- ratis-examples/pom.xml | 15 --------------- .../examples/arithmetic/ArithmeticStateMachine.java | 3 ++- .../ratis/grpc/server/GrpcServerProtocolClient.java | 4 +++- .../apache/hadoop/ipc/ProtobufRpcEngineShaded.java | 6 +++--- .../test/java/org/apache/ratis/RaftBasicTests.java | 2 +- .../apache/ratis/server/simulation/SimulatedRpc.java | 4 ++-- 11 files changed, 27 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/27c2dfe6/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index b5c7bdd..0295dff 100644 --- a/pom.xml +++ b/pom.xml @@ -472,7 +472,6 @@ <fork>true</fork> <meminitial>512m</meminitial> <maxmem>2048m</maxmem> - <showWarnings>true</showWarnings> <showDeprecation>false</showDeprecation> <useIncrementalCompilation>false</useIncrementalCompilation> <compilerArgs> http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/27c2dfe6/ratis-common/src/main/java/org/apache/ratis/util/JavaUtils.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/main/java/org/apache/ratis/util/JavaUtils.java b/ratis-common/src/main/java/org/apache/ratis/util/JavaUtils.java index ceca8b8..923e03d 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/JavaUtils.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/JavaUtils.java @@ -63,6 +63,12 @@ public interface JavaUtils { return clazz.isInstance(obj)? clazz.cast(obj): null; } + static <T> T cast(Object obj) { + @SuppressWarnings("unchecked") + final T t = (T)obj; + return t; + } + /** * Invoke {@link Callable#call()} and, if there any, * wrap the checked exception by {@link RuntimeException}. http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/27c2dfe6/ratis-common/src/main/java/org/apache/ratis/util/LogUtils.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/main/java/org/apache/ratis/util/LogUtils.java b/ratis-common/src/main/java/org/apache/ratis/util/LogUtils.java index 280aaab..f76852e 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/LogUtils.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/LogUtils.java @@ -76,7 +76,8 @@ public interface LogUtils { } else if (log.isWarnEnabled()){ log.warn("Failed to " + name.get() + ": " + t); } - throw (THROWABLE)t; + final THROWABLE throwable = JavaUtils.cast(t); + throw throwable; } if (log.isTraceEnabled()) { http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/27c2dfe6/ratis-common/src/main/java/org/apache/ratis/util/TimeoutScheduler.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/main/java/org/apache/ratis/util/TimeoutScheduler.java b/ratis-common/src/main/java/org/apache/ratis/util/TimeoutScheduler.java index 62e74e5..a298cea 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/TimeoutScheduler.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/TimeoutScheduler.java @@ -83,7 +83,7 @@ public final class TimeoutScheduler { try { task.run(); } catch(Throwable t) { - errorHandler.accept((THROWABLE) t); + errorHandler.accept(JavaUtils.cast(t)); } finally { onTaskCompleted(); } http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/27c2dfe6/ratis-common/src/test/java/org/apache/ratis/BaseTest.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/test/java/org/apache/ratis/BaseTest.java b/ratis-common/src/test/java/org/apache/ratis/BaseTest.java index 7efd9a7..fa15d55 100644 --- a/ratis-common/src/test/java/org/apache/ratis/BaseTest.java +++ b/ratis-common/src/test/java/org/apache/ratis/BaseTest.java @@ -77,6 +77,7 @@ public abstract class BaseTest { return new File(getClassTestDir(), testName.getMethodName()); } + @SafeVarargs public static void assertThrowable( String description, Throwable t, Class<? extends Throwable> exceptedThrowableClass, Logger log, @@ -94,6 +95,7 @@ public abstract class BaseTest { } } + @SafeVarargs public static void testFailureCase( String description, CheckedRunnable<?> testCode, Class<? extends Throwable> exceptedThrowableClass, Logger log, @@ -110,13 +112,15 @@ public abstract class BaseTest { } } - public void testFailureCase( + @SafeVarargs + public final void testFailureCase( String description, CheckedRunnable<?> testCode, Class<? extends Throwable> exceptedThrowableClass, Class<? extends Throwable>... exceptedCauseClasses) { testFailureCase(description, testCode, exceptedThrowableClass, LOG, exceptedCauseClasses); } + @SafeVarargs public static void testFailureCaseAsync( String description, Supplier<CompletableFuture<?>> testCode, Class<? extends Throwable> exceptedThrowableClass, Logger log, @@ -130,7 +134,8 @@ public abstract class BaseTest { } } - public void testFailureCaseAsync( + @SafeVarargs + public final void testFailureCaseAsync( String description, Supplier<CompletableFuture<?>> testCode, Class<? extends Throwable> exceptedThrowableClass, Class<? extends Throwable>... exceptedCauseClasses) { testFailureCaseAsync(description, testCode, exceptedThrowableClass, LOG, exceptedCauseClasses); http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/27c2dfe6/ratis-examples/pom.xml ---------------------------------------------------------------------- diff --git a/ratis-examples/pom.xml b/ratis-examples/pom.xml index 52839dd..e56a2dd 100644 --- a/ratis-examples/pom.xml +++ b/ratis-examples/pom.xml @@ -178,21 +178,6 @@ <root>${project.basedir}</root> </roots> </configuration> - <executions> - <execution> - <id>update-pom-license</id> - <goals> - <goal>update-file-header</goal> - </goals> - <phase>package</phase> - <configuration> - <licenseName>apache_v2</licenseName> - <includes> - <include>dependency-reduced-pom.xml</include> - </includes> - </configuration> - </execution> - </executions> </plugin> </plugins> </build> http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/27c2dfe6/ratis-examples/src/main/java/org/apache/ratis/examples/arithmetic/ArithmeticStateMachine.java ---------------------------------------------------------------------- diff --git a/ratis-examples/src/main/java/org/apache/ratis/examples/arithmetic/ArithmeticStateMachine.java b/ratis-examples/src/main/java/org/apache/ratis/examples/arithmetic/ArithmeticStateMachine.java index 4e8dd18..c873aa3 100644 --- a/ratis-examples/src/main/java/org/apache/ratis/examples/arithmetic/ArithmeticStateMachine.java +++ b/ratis-examples/src/main/java/org/apache/ratis/examples/arithmetic/ArithmeticStateMachine.java @@ -32,6 +32,7 @@ import org.apache.ratis.statemachine.impl.BaseStateMachine; import org.apache.ratis.statemachine.impl.SimpleStateMachineStorage; import org.apache.ratis.statemachine.impl.SingleFileSnapshotInfo; import org.apache.ratis.util.AutoCloseableLock; +import org.apache.ratis.util.JavaUtils; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -127,7 +128,7 @@ public class ArithmeticStateMachine extends BaseStateMachine { reset(); } setLastAppliedTermIndex(last); - variables.putAll((Map<String, Double>) in.readObject()); + variables.putAll(JavaUtils.cast(in.readObject())); } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/27c2dfe6/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolClient.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolClient.java b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolClient.java index 0848e65..89675db 100644 --- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolClient.java +++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolClient.java @@ -18,6 +18,7 @@ package org.apache.ratis.grpc.server; import org.apache.ratis.thirdparty.io.grpc.ManagedChannel; +import org.apache.ratis.thirdparty.io.grpc.netty.NegotiationType; import org.apache.ratis.thirdparty.io.grpc.netty.NettyChannelBuilder; import org.apache.ratis.thirdparty.io.grpc.stub.StreamObserver; import org.apache.ratis.proto.RaftProtos.*; @@ -42,7 +43,8 @@ public class GrpcServerProtocolClient implements Closeable { public GrpcServerProtocolClient(RaftPeer target, int flowControlWindow, TimeDuration requestTimeoutDuration) { channel = NettyChannelBuilder.forTarget(target.getAddress()) - .usePlaintext(true).flowControlWindow(flowControlWindow) + .negotiationType(NegotiationType.PLAINTEXT) + .flowControlWindow(flowControlWindow) .build(); blockingStub = RaftServerProtocolServiceGrpc.newBlockingStub(channel); asyncStub = RaftServerProtocolServiceGrpc.newStub(channel); http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/27c2dfe6/ratis-hadoop/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngineShaded.java ---------------------------------------------------------------------- diff --git a/ratis-hadoop/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngineShaded.java b/ratis-hadoop/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngineShaded.java index 79ebff6..9223562 100644 --- a/ratis-hadoop/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngineShaded.java +++ b/ratis-hadoop/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngineShaded.java @@ -348,8 +348,8 @@ public class ProtobufRpcEngineShaded implements RpcEngine { throw new IllegalArgumentException( "getLength on uninitialized RpcWrapper"); } - return CodedOutputStream.computeRawVarint32Size(headerLen) + headerLen - + CodedOutputStream.computeRawVarint32Size(reqLen) + reqLen; + return CodedOutputStream.computeUInt32SizeNoTag(headerLen) + headerLen + + CodedOutputStream.computeUInt32SizeNoTag(reqLen) + reqLen; } } @@ -462,7 +462,7 @@ public class ProtobufRpcEngineShaded implements RpcEngine { throw new IllegalArgumentException( "getLength on uninitialized RpcWrapper"); } - return CodedOutputStream.computeRawVarint32Size(resLen) + resLen; + return CodedOutputStream.computeUInt32SizeNoTag(resLen) + resLen; } } http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/27c2dfe6/ratis-server/src/test/java/org/apache/ratis/RaftBasicTests.java ---------------------------------------------------------------------- diff --git a/ratis-server/src/test/java/org/apache/ratis/RaftBasicTests.java b/ratis-server/src/test/java/org/apache/ratis/RaftBasicTests.java index 9cd7b7a..fabd29a 100644 --- a/ratis-server/src/test/java/org/apache/ratis/RaftBasicTests.java +++ b/ratis-server/src/test/java/org/apache/ratis/RaftBasicTests.java @@ -280,7 +280,7 @@ public abstract class RaftBasicTests<CLUSTER extends MiniRaftCluster> @Override public void run() { try (RaftClient client = cluster.createClient()) { - final CompletableFuture f = new CompletableFuture(); + final CompletableFuture<Void> f = new CompletableFuture<>(); for (int i = 0; i < messages.length; i++) { if (!useAsync) { final RaftClientReply reply = http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/27c2dfe6/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedRpc.java ---------------------------------------------------------------------- diff --git a/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedRpc.java b/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedRpc.java index bbf0a3e..11fe2ee 100644 --- a/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedRpc.java +++ b/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedRpc.java @@ -24,6 +24,7 @@ import org.apache.ratis.protocol.ClientId; import org.apache.ratis.rpc.RpcType; import org.apache.ratis.server.RaftServer; import org.apache.ratis.server.impl.ServerFactory; +import org.apache.ratis.util.JavaUtils; import java.util.Objects; @@ -57,8 +58,7 @@ class SimulatedRpc implements RpcType { private final SimulatedClientRpc client2serverRequestReply; Factory(Parameters parameters) { - serverRequestReply = parameters.getNonNull( - SERVER_REQUEST_REPLY_KEY, SimulatedRequestReply.class); + serverRequestReply = JavaUtils.cast(parameters.getNonNull(SERVER_REQUEST_REPLY_KEY, SimulatedRequestReply.class)); client2serverRequestReply = parameters.getNonNull( CLIENT_TO_SERVER_REQUEST_REPLY_KEY, SimulatedClientRpc.class); }
