From c3e8dae6ce604dfdcd8fc0eb0f7b0e2303e48a98 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Fri, 30 Jan 2015 14:58:07 -0800 Subject: [PATCH] Add checkstyle checking The checkstyle.xml is a slightly modified version of the upstream Google checkstyle configuration. All changes have comment describing them. Lots of warnings were corrected. Examples is the only project that has warnings still, as the necessary changes require some thought. --- .../grpc/auth/ClientAuthInterceptorTests.java | 3 +- .../io/grpc/benchmarks/qps/QpsClient.java | 57 +- .../io/grpc/benchmarks/qps/QpsServer.java | 33 +- build.gradle | 16 + checkstyle.xml | 521 +++++++----------- .../java/io/grpc/AbstractChannelBuilder.java | 4 +- core/src/main/java/io/grpc/ChannelImpl.java | 6 +- .../main/java/io/grpc/ClientInterceptor.java | 4 +- .../main/java/io/grpc/ClientInterceptors.java | 2 +- .../java/io/grpc/DeferredInputStream.java | 2 +- core/src/main/java/io/grpc/Metadata.java | 8 +- core/src/main/java/io/grpc/ServerImpl.java | 4 +- .../java/io/grpc/SharedResourceHolder.java | 1 + core/src/main/java/io/grpc/Status.java | 5 +- .../main/java/io/grpc/proto/ProtoUtils.java | 1 + .../io/grpc/transport/AbstractStream.java | 2 +- .../io/grpc/transport/ClientTransport.java | 5 +- .../transport/CompositeReadableBuffer.java | 14 +- .../io/grpc/transport/Http2ClientStream.java | 4 +- .../main/java/io/grpc/transport/HttpUtil.java | 5 +- .../io/grpc/transport/MessageDeframer.java | 2 +- .../java/io/grpc/transport/MessageFramer.java | 10 +- .../io/grpc/transport/ReadableBuffers.java | 10 +- core/src/test/java/io/grpc/MetadataTest.java | 2 +- .../grpc/MutableHandlerRegistryImplTest.java | 1 + .../src/test/java/io/grpc/ServerImplTest.java | 13 +- .../java/io/grpc/ServerInterceptorsTest.java | 2 + .../grpc/transport/MessageDeframerTest.java | 6 +- .../io/grpc/transport/MessageFramerTest.java | 24 +- .../transport/ReadableBuffersArrayTest.java | 3 +- .../ReadableBuffersByteBufferTest.java | 3 +- .../transport/WritableBufferTestBase.java | 6 +- .../examples/routeguide/RouteGuideServer.java | 20 +- .../examples/routeguide/RouteGuideUtil.java | 2 +- .../integration/AbstractTransportTest.java | 7 +- .../integration/TestServiceClient.java | 16 +- .../testing/integration/TestServiceImpl.java | 6 +- .../integration/TestServiceServer.java | 2 +- .../io/grpc/testing/integration/Util.java | 4 +- .../java/io/grpc/stub/StubConfigTest.java | 2 +- .../Http2NettyLocalChannelTest.java | 9 +- .../src/main/java/io/grpc/nano/NanoUtils.java | 5 +- nano/src/main/java/io/grpc/nano/Parser.java | 4 +- .../grpc/transport/netty/Http2Negotiator.java | 6 +- .../transport/netty/NettyClientHandler.java | 11 +- .../io/grpc/transport/netty/NettyServer.java | 4 +- .../transport/netty/NettyServerBuilder.java | 2 +- .../transport/netty/NettyServerHandler.java | 7 +- .../transport/netty/NettyServerStream.java | 2 +- .../java/io/grpc/transport/netty/Utils.java | 35 +- .../netty/NettyClientHandlerTest.java | 5 +- .../netty/NettyServerHandlerTest.java | 11 +- .../transport/netty/NettyStreamTestBase.java | 3 +- .../netty/NettyWritableBufferTest.java | 2 +- .../okhttp/OkHttpChannelBuilder.java | 2 +- .../okhttp/OkHttpClientTransport.java | 6 +- .../okhttp/OkHttpReadableBuffer.java | 2 +- .../okhttp/OkHttpClientTransportTest.java | 14 +- stub/src/main/java/io/grpc/stub/Calls.java | 3 +- .../main/java/io/grpc/stub/MetadataUtils.java | 2 +- stub/src/main/java/io/grpc/stub/Method.java | 2 +- 61 files changed, 459 insertions(+), 516 deletions(-) diff --git a/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java b/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java index 6bbe719f98..1737c8acc0 100644 --- a/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java +++ b/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java @@ -61,8 +61,9 @@ public class ClientAuthInterceptorTests { ClientAuthInterceptor interceptor; + /** Set up for test. */ @Before - public void startup() throws IOException { + public void startUp() throws IOException { MockitoAnnotations.initMocks(this); when(channel.newCall(descriptor)).thenReturn(call); interceptor = new ClientAuthInterceptor(credentials, diff --git a/benchmarks/src/main/java/io/grpc/benchmarks/qps/QpsClient.java b/benchmarks/src/main/java/io/grpc/benchmarks/qps/QpsClient.java index 34e4fc14c3..08d2b8d156 100644 --- a/benchmarks/src/main/java/io/grpc/benchmarks/qps/QpsClient.java +++ b/benchmarks/src/main/java/io/grpc/benchmarks/qps/QpsClient.java @@ -31,11 +31,11 @@ package io.grpc.benchmarks.qps; -import static grpc.testing.TestServiceGrpc.TestServiceStub; import static grpc.testing.Qpstest.SimpleRequest; import static grpc.testing.Qpstest.SimpleResponse; -import static java.lang.Math.max; +import static grpc.testing.TestServiceGrpc.TestServiceStub; import static io.grpc.testing.integration.Util.loadCert; +import static java.lang.Math.max; import com.google.common.base.Preconditions; import com.google.common.util.concurrent.MoreExecutors; @@ -63,8 +63,8 @@ import java.util.List; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.concurrent.TimeUnit; import java.util.logging.Logger; /** @@ -96,6 +96,7 @@ public class QpsClient { new QpsClient().run(args); } + /** Equivalent of "main", but non-static. */ public void run(String[] args) throws Exception { if (!parseArgs(args)) { return; @@ -161,11 +162,11 @@ public class QpsClient { InetAddress address = InetAddress.getByName(serverHost); NegotiationType negotiationType = enableTls ? NegotiationType.TLS : NegotiationType.PLAINTEXT; if (enableTls && useTestCa) { - // Force the hostname to match the cert the server uses. - address = InetAddress.getByAddress("foo.test.google.fr", address.getAddress()); - File cert = loadCert("ca.pem"); - context = SslContext.newClientContext(cert); - } + // Force the hostname to match the cert the server uses. + address = InetAddress.getByAddress("foo.test.google.fr", address.getAddress()); + File cert = loadCert("ca.pem"); + context = SslContext.newClientContext(cert); + } return NettyChannelBuilder.forAddress(new InetSocketAddress(address, serverPort)) .negotiationType(negotiationType) @@ -254,21 +255,21 @@ public class QpsClient { private void printUsage() { QpsClient c = new QpsClient(); System.out.println( - "Usage: [ARGS...]" - + "\n" - + "\n --server_port=INT Port of the server. Required. No default." - + "\n --server_host=STR Hostname of the server. Default " + c.serverHost - + "\n --client_channels=INT Number of client channels. Default " + c.clientChannels - + "\n --concurrent_calls=INT Number of concurrent calls. Default " + c.concurrentCalls - + "\n --payload_size=INT Payload size in bytes. Default " + c.payloadSize - + "\n --enable_tls Enable TLS. Default disabled." - + "\n --use_testca Use the provided test certificate for TLS." - + "\n --okhttp Use OkHttp as the transport. Default netty" - + "\n --duration=TIME Duration of the benchmark in either seconds or minutes." - + "\n For N seconds duration specify Ns and for minutes Nm. " - + "\n Default " + c.duration + "s." - + "\n --warmup_duration=TIME How long to run the warmup." - + "\n Default " + c.warmupDuration + "s." + "Usage: [ARGS...]" + + "\n" + + "\n --server_port=INT Port of the server. Required. No default." + + "\n --server_host=STR Hostname of the server. Default " + c.serverHost + + "\n --client_channels=INT Number of client channels. Default " + c.clientChannels + + "\n --concurrent_calls=INT Number of concurrent calls. Default " + c.concurrentCalls + + "\n --payload_size=INT Payload size in bytes. Default " + c.payloadSize + + "\n --enable_tls Enable TLS. Default disabled." + + "\n --use_testca Use the provided test certificate for TLS." + + "\n --okhttp Use OkHttp as the transport. Default netty" + + "\n --duration=TIME Duration of the benchmark in either seconds or minutes." + + "\n For N seconds duration specify Ns and for minutes Nm. " + + "\n Default " + c.duration + "s." + + "\n --warmup_duration=TIME How long to run the warmup." + + "\n Default " + c.warmupDuration + "s." ); } @@ -288,13 +289,13 @@ public class QpsClient { int actualSize = value.getPayload().getBody().size(); if (!PayloadType.COMPRESSABLE.equals(type)) { - throw new RuntimeException("type was '" + type + "', expected '" + - PayloadType.COMPRESSABLE + "'."); + throw new RuntimeException("type was '" + type + "', expected '" + + PayloadType.COMPRESSABLE + "'."); } if (payloadSize != actualSize) { - throw new RuntimeException("size was '" + actualSize + "', expected '" + - payloadSize + "'"); + throw new RuntimeException("size was '" + actualSize + "', expected '" + + payloadSize + "'"); } } @@ -336,7 +337,7 @@ public class QpsClient { } private void printStats(Histogram histogram, long elapsedTime) { - double percentiles[] = {50, 90, 95, 99, 99.9, 99.99}; + double[] percentiles = {50, 90, 95, 99, 99.9, 99.99}; // Generate a comma-separated string of percentiles StringBuilder header = new StringBuilder(); diff --git a/benchmarks/src/main/java/io/grpc/benchmarks/qps/QpsServer.java b/benchmarks/src/main/java/io/grpc/benchmarks/qps/QpsServer.java index 306925ace8..4750815637 100644 --- a/benchmarks/src/main/java/io/grpc/benchmarks/qps/QpsServer.java +++ b/benchmarks/src/main/java/io/grpc/benchmarks/qps/QpsServer.java @@ -31,21 +31,21 @@ package io.grpc.benchmarks.qps; -import static grpc.testing.Qpstest.StatsRequest; -import static grpc.testing.Qpstest.ServerStats; import static grpc.testing.Qpstest.Latencies; -import static grpc.testing.Qpstest.StartArgs; import static grpc.testing.Qpstest.Payload; import static grpc.testing.Qpstest.PayloadType; -import static grpc.testing.Qpstest.SimpleResponse; +import static grpc.testing.Qpstest.ServerStats; import static grpc.testing.Qpstest.SimpleRequest; -import static grpc.testing.Qpstest.StreamingInputCallResponse; -import static grpc.testing.Qpstest.StreamingOutputCallResponse; +import static grpc.testing.Qpstest.SimpleResponse; +import static grpc.testing.Qpstest.StartArgs; +import static grpc.testing.Qpstest.StatsRequest; import static grpc.testing.Qpstest.StreamingInputCallRequest; +import static grpc.testing.Qpstest.StreamingInputCallResponse; import static grpc.testing.Qpstest.StreamingOutputCallRequest; -import static java.lang.Math.max; +import static grpc.testing.Qpstest.StreamingOutputCallResponse; import static io.grpc.testing.integration.Util.loadCert; import static io.grpc.testing.integration.Util.pickUnusedPort; +import static java.lang.Math.max; import com.google.common.util.concurrent.MoreExecutors; import com.google.protobuf.ByteString; @@ -65,20 +65,21 @@ import java.util.concurrent.TimeUnit; public class QpsServer { - private boolean enable_tls; + private boolean enableTls; private int port = 0; public static void main(String... args) throws Exception { new QpsServer().run(args); } + /** Equivalent of "main", but non-static. */ public void run(String[] args) throws Exception { if (!parseArgs(args)) { return; } SslContext sslContext = null; - if (enable_tls) { + if (enableTls) { System.out.println("Using fake CA for TLS certificate.\n" + "Run the Java client with --enable_tls --use_testca"); @@ -136,7 +137,7 @@ public class QpsServer { } else if ("port".equals(key)) { port = Integer.parseInt(value); } else if ("enable_tls".equals(key)) { - enable_tls = true; + enableTls = true; } else { System.err.println("Unrecognized argument '" + key + "'."); } @@ -215,20 +216,20 @@ public class QpsServer { } @Override - public StreamObserver - streamingInputCall(StreamObserver responseObserver) { + public StreamObserver streamingInputCall( + StreamObserver responseObserver) { throw Status.UNIMPLEMENTED.asRuntimeException(); } @Override - public StreamObserver - fullDuplexCall(StreamObserver responseObserver) { + public StreamObserver fullDuplexCall( + StreamObserver responseObserver) { throw Status.UNIMPLEMENTED.asRuntimeException(); } @Override - public StreamObserver - halfDuplexCall(StreamObserver responseObserver) { + public StreamObserver halfDuplexCall( + StreamObserver responseObserver) { throw Status.UNIMPLEMENTED.asRuntimeException(); } } diff --git a/build.gradle b/build.gradle index 3fdc10434f..c21e1b8b11 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ import org.apache.tools.ant.taskdefs.condition.Os subprojects { + apply plugin: "checkstyle" apply plugin: "java" apply plugin: "maven" apply plugin: "idea" @@ -87,6 +88,21 @@ subprojects { } } + checkstyle { + configFile = file("$rootDir/checkstyle.xml") + toolVersion = "6.2" + } + + checkstyleMain { + source = fileTree(dir: "src", include: "**/*.java", + excludes: ["${buildDir}/generated-sources", "**/TestServiceGrpc.java"]) + } + + checkstyleTest { + source = fileTree(dir: "test", include: "**/*.java", + exclude: "${buildDir}/generated-sources") + } + task javadocJar(type: Jar) { classifier = 'javadoc' from javadoc diff --git a/checkstyle.xml b/checkstyle.xml index 8f4a9a899d..aed7e84677 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -1,328 +1,207 @@ - + + "-//Puppy Crawl//DTD Check Configuration 1.3//EN" + "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> - + - - + Most Checks are configurable, be sure to consult the documentation. - - - + To completely disable a check, just comment it out or delete it from the file. - - - - - - - - - - - - - - - - - - - - - - - - - - - - + Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov. + + --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/core/src/main/java/io/grpc/AbstractChannelBuilder.java b/core/src/main/java/io/grpc/AbstractChannelBuilder.java index 070a1574ff..50adfcc97b 100644 --- a/core/src/main/java/io/grpc/AbstractChannelBuilder.java +++ b/core/src/main/java/io/grpc/AbstractChannelBuilder.java @@ -37,8 +37,8 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder; import io.grpc.SharedResourceHolder.Resource; import io.grpc.transport.ClientTransportFactory; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; import javax.annotation.Nullable; @@ -124,6 +124,8 @@ public abstract class AbstractChannelBuilder - * Many variations of interception are possible. Complex implementations may return a wrapper + * + *

Many variations of interception are possible. Complex implementations may return a wrapper * around the result of {@code next.newCall()}, whereas a simpler implementation may just modify * the header metadata prior to returning the result of {@code next.newCall()}. * diff --git a/core/src/main/java/io/grpc/ClientInterceptors.java b/core/src/main/java/io/grpc/ClientInterceptors.java index 22e163bc34..d8966047ff 100644 --- a/core/src/main/java/io/grpc/ClientInterceptors.java +++ b/core/src/main/java/io/grpc/ClientInterceptors.java @@ -39,7 +39,7 @@ import java.util.Iterator; import java.util.List; /** - * Utility methods for working with {@link ClientInterceptor}s + * Utility methods for working with {@link ClientInterceptor}s. */ public class ClientInterceptors { diff --git a/core/src/main/java/io/grpc/DeferredInputStream.java b/core/src/main/java/io/grpc/DeferredInputStream.java index ee1cabb12f..d587f85502 100644 --- a/core/src/main/java/io/grpc/DeferredInputStream.java +++ b/core/src/main/java/io/grpc/DeferredInputStream.java @@ -31,8 +31,8 @@ package io.grpc; -import java.io.IOException; import java.io.InputStream; +import java.io.IOException; import java.io.OutputStream; import javax.annotation.Nullable; diff --git a/core/src/main/java/io/grpc/Metadata.java b/core/src/main/java/io/grpc/Metadata.java index 8f25ac6c89..4a55c4a44f 100644 --- a/core/src/main/java/io/grpc/Metadata.java +++ b/core/src/main/java/io/grpc/Metadata.java @@ -437,8 +437,12 @@ public abstract class Metadata { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } Key key = (Key) o; return !(name != null ? !name.equals(key.name) : key.name != null); } diff --git a/core/src/main/java/io/grpc/ServerImpl.java b/core/src/main/java/io/grpc/ServerImpl.java index 991d3ff1f2..c40dbcbe8b 100644 --- a/core/src/main/java/io/grpc/ServerImpl.java +++ b/core/src/main/java/io/grpc/ServerImpl.java @@ -41,8 +41,8 @@ import io.grpc.transport.ServerStream; import io.grpc.transport.ServerStreamListener; import io.grpc.transport.ServerTransportListener; -import java.io.IOException; import java.io.InputStream; +import java.io.IOException; import java.util.Collection; import java.util.HashSet; import java.util.concurrent.Executor; @@ -205,7 +205,7 @@ public class ServerImpl implements Server { * Waits for the server to become terminated. */ public synchronized void awaitTerminated() throws InterruptedException { - while(!terminated) { + while (!terminated) { wait(); } } diff --git a/core/src/main/java/io/grpc/SharedResourceHolder.java b/core/src/main/java/io/grpc/SharedResourceHolder.java index 504e18a068..6f397fb58d 100644 --- a/core/src/main/java/io/grpc/SharedResourceHolder.java +++ b/core/src/main/java/io/grpc/SharedResourceHolder.java @@ -195,6 +195,7 @@ public final class SharedResourceHolder { final Object payload; int refcount; ScheduledFuture destroyTask; + Instance(Object payload) { this.payload = payload; } diff --git a/core/src/main/java/io/grpc/Status.java b/core/src/main/java/io/grpc/Status.java index 0eaca3a546..08c16c4acb 100644 --- a/core/src/main/java/io/grpc/Status.java +++ b/core/src/main/java/io/grpc/Status.java @@ -231,13 +231,14 @@ public final class Status { // Create the canonical list of Status instances indexed by their code values. private static List STATUS_LIST; + static { TreeMap canonicalizer = new TreeMap(); for (Code code : Code.values()) { Status replaced = canonicalizer.put(code.value(), new Status(code)); if (replaced != null) { - throw new IllegalStateException("Code value duplication between " + - replaced.getCode().name() + " & " + code.name()); + throw new IllegalStateException("Code value duplication between " + + replaced.getCode().name() + " & " + code.name()); } } STATUS_LIST = new ArrayList(canonicalizer.values()); diff --git a/core/src/main/java/io/grpc/proto/ProtoUtils.java b/core/src/main/java/io/grpc/proto/ProtoUtils.java index a6498bb1c9..d638d5e03c 100644 --- a/core/src/main/java/io/grpc/proto/ProtoUtils.java +++ b/core/src/main/java/io/grpc/proto/ProtoUtils.java @@ -47,6 +47,7 @@ import java.io.InputStream; */ public class ProtoUtils { + /** Adapt a {@code Parser} to a {@code Marshaller}. */ public static Marshaller marshaller(final Parser parser) { return new Marshaller() { @Override diff --git a/core/src/main/java/io/grpc/transport/AbstractStream.java b/core/src/main/java/io/grpc/transport/AbstractStream.java index 0e4312f494..a04dc5af4a 100644 --- a/core/src/main/java/io/grpc/transport/AbstractStream.java +++ b/core/src/main/java/io/grpc/transport/AbstractStream.java @@ -108,7 +108,7 @@ public abstract class AbstractStream implements Stream { } /** - * Set the internal ID for this stream + * Set the internal ID for this stream. */ public void id(IdT id) { Preconditions.checkState(id != null, "Can only set id once"); diff --git a/core/src/main/java/io/grpc/transport/ClientTransport.java b/core/src/main/java/io/grpc/transport/ClientTransport.java index a46bd401a3..d424ae44ce 100644 --- a/core/src/main/java/io/grpc/transport/ClientTransport.java +++ b/core/src/main/java/io/grpc/transport/ClientTransport.java @@ -52,8 +52,8 @@ public interface ClientTransport { * @param method the descriptor of the remote method to be called for this stream. * @param headers to send at the beginning of the call * @param listener the listener for the newly created stream. - * @throws IllegalStateException if the service is already stopped. * @return the newly created stream. + * @throws IllegalStateException if the service is already stopped. */ // TODO(nmittler): Consider also throwing for stopping. ClientStream newStream(MethodDescriptor method, @@ -61,7 +61,8 @@ public interface ClientTransport { ClientStreamListener listener); /** - * Starts transport. Implementations must not call {@code listener} until after {@code start()} returns. + * Starts transport. Implementations must not call {@code listener} until after {@code start()} + * returns. * * @param listener non-{@code null} listener of transport events */ diff --git a/core/src/main/java/io/grpc/transport/CompositeReadableBuffer.java b/core/src/main/java/io/grpc/transport/CompositeReadableBuffer.java index 0da0ca83c7..87052cc1b2 100644 --- a/core/src/main/java/io/grpc/transport/CompositeReadableBuffer.java +++ b/core/src/main/java/io/grpc/transport/CompositeReadableBuffer.java @@ -38,8 +38,8 @@ import java.util.ArrayDeque; import java.util.Queue; /** - * A {@link ReadableBuffer} that is composed of 0 or more {@link ReadableBuffer}s. This provides a facade that - * allows multiple buffers to be treated as one. + * A {@link ReadableBuffer} that is composed of 0 or more {@link ReadableBuffer}s. This provides a + * facade that allows multiple buffers to be treated as one. * *

When a buffer is added to a composite, its life cycle is controlled by the composite. Once * the composite has read past the end of a given buffer, that buffer is automatically closed and @@ -175,8 +175,8 @@ public class CompositeReadableBuffer extends AbstractReadableBuffer { } /** - * Executes the given {@link ReadOperation} against the {@link ReadableBuffer}s required to satisfy the - * requested {@code length}. + * Executes the given {@link ReadOperation} against the {@link ReadableBuffer}s required to + * satisfy the requested {@code length}. */ private void execute(ReadOperation op, int length) { checkReadable(length); @@ -212,8 +212,8 @@ public class CompositeReadableBuffer extends AbstractReadableBuffer { } /** - * A simple read operation to perform on a single {@link ReadableBuffer}. All state management for the - * buffers is done by {@link CompositeReadableBuffer#execute(ReadOperation, int)}. + * A simple read operation to perform on a single {@link ReadableBuffer}. All state management for + * the buffers is done by {@link CompositeReadableBuffer#execute(ReadOperation, int)}. */ private abstract class ReadOperation { /** @@ -222,7 +222,7 @@ public class CompositeReadableBuffer extends AbstractReadableBuffer { int value; /** - * Only used by {@link CompositeReadableBuffer#readBytes(OutputStream, int)}; + * Only used by {@link CompositeReadableBuffer#readBytes(OutputStream, int)}. */ IOException ex; diff --git a/core/src/main/java/io/grpc/transport/Http2ClientStream.java b/core/src/main/java/io/grpc/transport/Http2ClientStream.java index 32f869ebb8..4623aed0c2 100644 --- a/core/src/main/java/io/grpc/transport/Http2ClientStream.java +++ b/core/src/main/java/io/grpc/transport/Http2ClientStream.java @@ -122,8 +122,8 @@ public abstract class Http2ClientStream extends AbstractClientStream { if (transportError != null) { // We've already detected a transport error and now we're just accumulating more detail // for it. - transportError = transportError.augmentDescription("DATA-----------------------------\n" + - ReadableBuffers.readAsString(frame, errorCharset)); + transportError = transportError.augmentDescription("DATA-----------------------------\n" + + ReadableBuffers.readAsString(frame, errorCharset)); frame.close(); if (transportError.getDescription().length() > 1000 || endOfStream) { inboundTransportError(transportError); diff --git a/core/src/main/java/io/grpc/transport/HttpUtil.java b/core/src/main/java/io/grpc/transport/HttpUtil.java index f05dd774aa..1ad5258a71 100644 --- a/core/src/main/java/io/grpc/transport/HttpUtil.java +++ b/core/src/main/java/io/grpc/transport/HttpUtil.java @@ -37,7 +37,7 @@ import io.grpc.Status; import java.net.HttpURLConnection; /** - * Constants for GRPC-over-HTTP (or HTTP/2) + * Constants for GRPC-over-HTTP (or HTTP/2). */ public final class HttpUtil { /** @@ -64,7 +64,7 @@ public final class HttpUtil { Metadata.ASCII_STRING_MARSHALLER); /** - * The TE (transport encoding) header for requests over HTTP/2 + * The TE (transport encoding) header for requests over HTTP/2. */ public static final String TE_TRAILERS = "trailers"; @@ -96,6 +96,7 @@ public final class HttpUtil { return Status.UNAVAILABLE; case HttpURLConnection.HTTP_GATEWAY_TIMEOUT: // 504 return Status.DEADLINE_EXCEEDED; + default: } // Generic HTTP code handling. if (httpStatusCode < 200) { diff --git a/core/src/main/java/io/grpc/transport/MessageDeframer.java b/core/src/main/java/io/grpc/transport/MessageDeframer.java index 638dd51dfd..f417c1090b 100644 --- a/core/src/main/java/io/grpc/transport/MessageDeframer.java +++ b/core/src/main/java/io/grpc/transport/MessageDeframer.java @@ -36,8 +36,8 @@ import com.google.common.base.Preconditions; import io.grpc.Status; import java.io.Closeable; -import java.io.IOException; import java.io.InputStream; +import java.io.IOException; import java.util.zip.GZIPInputStream; import javax.annotation.concurrent.NotThreadSafe; diff --git a/core/src/main/java/io/grpc/transport/MessageFramer.java b/core/src/main/java/io/grpc/transport/MessageFramer.java index d35e7cf994..f72483d880 100644 --- a/core/src/main/java/io/grpc/transport/MessageFramer.java +++ b/core/src/main/java/io/grpc/transport/MessageFramer.java @@ -40,8 +40,8 @@ import io.grpc.DeferredInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.io.InputStream; +import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; import java.util.zip.GZIPOutputStream; @@ -52,7 +52,8 @@ import java.util.zip.GZIPOutputStream; */ public class MessageFramer { /** - * Sink implemented by the transport layer to receive frames and forward them to their destination + * Sink implemented by the transport layer to receive frames and forward them to their + * destination. */ public interface Sink { /** @@ -98,7 +99,8 @@ public class MessageFramer { * @param maxFrameSize the maximum frame size that this framer will deliver * @param compression the compression type */ - public MessageFramer(Sink sink, WritableBufferAllocator bufferAllocator, int maxFrameSize, Compression compression) { + public MessageFramer(Sink sink, WritableBufferAllocator bufferAllocator, int maxFrameSize, + Compression compression) { this.sink = Preconditions.checkNotNull(sink, "sink"); this.bufferAllocator = bufferAllocator; this.maxFrameSize = maxFrameSize; @@ -114,7 +116,7 @@ public class MessageFramer { */ public void writePayload(InputStream message, int messageLength) { try { - switch(compression) { + switch (compression) { case NONE: writeFrame(message, messageLength, false); break; diff --git a/core/src/main/java/io/grpc/transport/ReadableBuffers.java b/core/src/main/java/io/grpc/transport/ReadableBuffers.java index 1a7a4504c0..003a303b53 100644 --- a/core/src/main/java/io/grpc/transport/ReadableBuffers.java +++ b/core/src/main/java/io/grpc/transport/ReadableBuffers.java @@ -35,8 +35,8 @@ import static com.google.common.base.Charsets.UTF_8; import com.google.common.base.Preconditions; -import java.io.IOException; import java.io.InputStream; +import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.charset.Charset; @@ -73,16 +73,16 @@ public final class ReadableBuffers { } /** - * Creates a new {@link ReadableBuffer} that is backed by the given {@link ByteBuffer}. Calls to read from - * the buffer will increment the position of the {@link ByteBuffer}. + * Creates a new {@link ReadableBuffer} that is backed by the given {@link ByteBuffer}. Calls to + * read from the buffer will increment the position of the {@link ByteBuffer}. */ public static ReadableBuffer wrap(ByteBuffer bytes) { return new ByteReadableBufferWrapper(bytes); } /** - * Reads an entire {@link ReadableBuffer} to a new array. After calling this method, the buffer will - * contain no readable bytes. + * Reads an entire {@link ReadableBuffer} to a new array. After calling this method, the buffer + * will contain no readable bytes. */ public static byte[] readArray(ReadableBuffer buffer) { Preconditions.checkNotNull(buffer, "buffer"); diff --git a/core/src/test/java/io/grpc/MetadataTest.java b/core/src/test/java/io/grpc/MetadataTest.java index 0febbb3986..347de50b8f 100644 --- a/core/src/test/java/io/grpc/MetadataTest.java +++ b/core/src/test/java/io/grpc/MetadataTest.java @@ -46,7 +46,7 @@ import org.junit.runners.JUnit4; import java.util.Iterator; /** - * Tests for {@link Metadata} + * Tests for {@link Metadata}. */ @RunWith(JUnit4.class) public class MetadataTest { diff --git a/core/src/test/java/io/grpc/MutableHandlerRegistryImplTest.java b/core/src/test/java/io/grpc/MutableHandlerRegistryImplTest.java index 1ad9daee51..87232bc6ba 100644 --- a/core/src/test/java/io/grpc/MutableHandlerRegistryImplTest.java +++ b/core/src/test/java/io/grpc/MutableHandlerRegistryImplTest.java @@ -69,6 +69,7 @@ public class MutableHandlerRegistryImplTest { @SuppressWarnings("rawtypes") private ServerMethodDefinition fewMethodDefinition = multiServiceDefinition.getMethod("few"); + /** Final checks for all tests. */ @After public void makeSureMocksUnused() { Mockito.verifyZeroInteractions(requestMarshaller); diff --git a/core/src/test/java/io/grpc/ServerImplTest.java b/core/src/test/java/io/grpc/ServerImplTest.java index 7485bd7a13..d286d98d64 100644 --- a/core/src/test/java/io/grpc/ServerImplTest.java +++ b/core/src/test/java/io/grpc/ServerImplTest.java @@ -64,13 +64,13 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; +import java.io.IOException; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -92,15 +92,17 @@ public class ServerImplTest { @Mock private ServerCall.Listener callListener; + /** Set up for test. */ @Before - public void startup() { + public void startUp() { MockitoAnnotations.initMocks(this); server.start(); } + /** Tear down after test. */ @After - public void teardown() { + public void tearDown() { executor.shutdownNow(); } @@ -125,6 +127,7 @@ public class ServerImplTest { notifyFailed(ex); } } + FailingStartupService transportServer = new FailingStartupService(); ServerImpl server = new ServerImpl(executor, registry).setTransportServer(transportServer); try { @@ -144,6 +147,7 @@ public class ServerImplTest { @Override public void doStop() {} // Don't notify. } + NoopService transportServer = new NoopService(); ServerImpl server = new ServerImpl(executor, registry).setTransportServer(transportServer) .start(); @@ -171,6 +175,7 @@ public class ServerImplTest { @Override public void doStop() {} // Don't notify. } + ManualStoppedService transportServer = new ManualStoppedService(); ServerImpl server = new ServerImpl(executor, registry).setTransportServer(transportServer) .start(); diff --git a/core/src/test/java/io/grpc/ServerInterceptorsTest.java b/core/src/test/java/io/grpc/ServerInterceptorsTest.java index f3d7ba0135..90a3ae856d 100644 --- a/core/src/test/java/io/grpc/ServerInterceptorsTest.java +++ b/core/src/test/java/io/grpc/ServerInterceptorsTest.java @@ -71,6 +71,7 @@ public class ServerInterceptorsTest { .addMethod("flow", requestMarshaller, responseMarshaller, handler).build(); private Headers headers = new Headers(); + /** Set up for test. */ @Before public void setUp() { MockitoAnnotations.initMocks(this); @@ -79,6 +80,7 @@ public class ServerInterceptorsTest { .thenReturn(listener); } + /** Final checks for all tests. */ @After public void makeSureExpectedMocksUnused() { verifyZeroInteractions(requestMarshaller); diff --git a/core/src/test/java/io/grpc/transport/MessageDeframerTest.java b/core/src/test/java/io/grpc/transport/MessageDeframerTest.java index 255245ee0c..86b355447f 100644 --- a/core/src/test/java/io/grpc/transport/MessageDeframerTest.java +++ b/core/src/test/java/io/grpc/transport/MessageDeframerTest.java @@ -51,8 +51,8 @@ import org.junit.runners.JUnit4; import org.mockito.ArgumentCaptor; import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.io.InputStream; +import java.io.IOException; import java.util.List; import java.util.zip.GZIPOutputStream; @@ -148,8 +148,8 @@ public class MessageDeframerTest { @Test public void largerFrameSize() { deframer.request(1); - deframer.deframe( - ReadableBuffers.wrap(Bytes.concat(new byte[] {0, 0, 0, 3, (byte) 232}, new byte[1000])), false); + deframer.deframe(ReadableBuffers.wrap( + Bytes.concat(new byte[] {0, 0, 0, 3, (byte) 232}, new byte[1000])), false); verify(listener).messageRead(messages.capture()); assertEquals(Bytes.asList(new byte[1000]), bytes(messages)); verify(listener, atLeastOnce()).bytesRead(anyInt()); diff --git a/core/src/test/java/io/grpc/transport/MessageFramerTest.java b/core/src/test/java/io/grpc/transport/MessageFramerTest.java index ece7a57d4a..0004bf2af5 100644 --- a/core/src/test/java/io/grpc/transport/MessageFramerTest.java +++ b/core/src/test/java/io/grpc/transport/MessageFramerTest.java @@ -31,12 +31,12 @@ package io.grpc.transport; +import static io.grpc.transport.MessageFramer.Compression; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static io.grpc.transport.MessageFramer.Compression; import com.google.common.base.Preconditions; @@ -53,7 +53,7 @@ import java.io.ByteArrayInputStream; import java.util.Arrays; /** - * Tests for {@link MessageFramer} + * Tests for {@link MessageFramer}. */ @RunWith(JUnit4.class) public class MessageFramerTest { @@ -67,8 +67,9 @@ public class MessageFramerTest { private ArgumentCaptor frameCaptor; private WritableBufferAllocator allocator = new BytesWritableBufferAllocator(); + /** Set up for test. */ @Before - public void setup() { + public void setUp() { MockitoAnnotations.initMocks(this); framer = new MessageFramer(sink, allocator, TRANSPORT_FRAME_SIZE); @@ -90,7 +91,8 @@ public class MessageFramerTest { writePayload(framer, new byte[] {14}); verifyNoMoreInteractions(sink); framer.flush(); - verify(sink).deliverFrame(toWriteBuffer(new byte[] {0, 0, 0, 0, 1, 3, 0, 0, 0, 0, 1, 14}), false); + verify(sink).deliverFrame( + toWriteBuffer(new byte[] {0, 0, 0, 0, 1, 3, 0, 0, 0, 0, 1, 14}), false); verifyNoMoreInteractions(sink); } @@ -99,7 +101,8 @@ public class MessageFramerTest { writePayload(framer, new byte[] {3, 14, 1, 5, 9, 2, 6}); verifyNoMoreInteractions(sink); framer.close(); - verify(sink).deliverFrame(toWriteBuffer(new byte[] {0, 0, 0, 0, 7, 3, 14, 1, 5, 9, 2, 6}), true); + verify(sink).deliverFrame( + toWriteBuffer(new byte[] {0, 0, 0, 0, 7, 3, 14, 1, 5, 9, 2, 6}), true); verifyNoMoreInteractions(sink); } @@ -113,7 +116,8 @@ public class MessageFramerTest { @Test public void payloadSplitBetweenSinks() { writePayload(framer, new byte[] {3, 14, 1, 5, 9, 2, 6, 5}); - verify(sink).deliverFrame(toWriteBuffer(new byte[] {0, 0, 0, 0, 8, 3, 14, 1, 5, 9, 2, 6}), false); + verify(sink).deliverFrame( + toWriteBuffer(new byte[] {0, 0, 0, 0, 8, 3, 14, 1, 5, 9, 2, 6}), false); verifyNoMoreInteractions(sink); framer.flush(); @@ -160,7 +164,7 @@ public class MessageFramerTest { ByteWritableBuffer buffer = frameCaptor.getValue(); assertEquals(1005, buffer.size()); - byte data[] = new byte[1005]; + byte[] data = new byte[1005]; data[3] = 3; data[4] = (byte) 232; @@ -242,9 +246,9 @@ public class MessageFramerTest { ByteWritableBuffer other = (ByteWritableBuffer) buffer; - return writableBytes() == other.writableBytes() && - readableBytes() == other.readableBytes() && - Arrays.equals(data, other.data); + return writableBytes() == other.writableBytes() + && readableBytes() == other.readableBytes() + && Arrays.equals(data, other.data); } @Override diff --git a/core/src/test/java/io/grpc/transport/ReadableBuffersArrayTest.java b/core/src/test/java/io/grpc/transport/ReadableBuffersArrayTest.java index 1008796e7b..d9a953d2c6 100644 --- a/core/src/test/java/io/grpc/transport/ReadableBuffersArrayTest.java +++ b/core/src/test/java/io/grpc/transport/ReadableBuffersArrayTest.java @@ -40,7 +40,8 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; /** - * Tests for the array-backed {@link ReadableBuffer} returned by {@link ReadableBuffers#wrap(byte[], int, int)}; + * Tests for the array-backed {@link ReadableBuffer} returned by {@link ReadableBuffers#wrap(byte[], + * int, int)}. */ public class ReadableBuffersArrayTest extends ReadableBufferTestBase { diff --git a/core/src/test/java/io/grpc/transport/ReadableBuffersByteBufferTest.java b/core/src/test/java/io/grpc/transport/ReadableBuffersByteBufferTest.java index c753147508..fbd8db279c 100644 --- a/core/src/test/java/io/grpc/transport/ReadableBuffersByteBufferTest.java +++ b/core/src/test/java/io/grpc/transport/ReadableBuffersByteBufferTest.java @@ -36,7 +36,8 @@ import static com.google.common.base.Charsets.UTF_8; import java.nio.ByteBuffer; /** - * Tests for the array-backed {@link ReadableBuffer} returned by {@link ReadableBuffers#wrap(ByteBuffer)}. + * Tests for the array-backed {@link ReadableBuffer} returned by {@link + * ReadableBuffers#wrap(ByteBuffer)}. */ public class ReadableBuffersByteBufferTest extends ReadableBufferTestBase { diff --git a/core/src/test/java/io/grpc/transport/WritableBufferTestBase.java b/core/src/test/java/io/grpc/transport/WritableBufferTestBase.java index 4e433dbf7e..aec2fdd36c 100644 --- a/core/src/test/java/io/grpc/transport/WritableBufferTestBase.java +++ b/core/src/test/java/io/grpc/transport/WritableBufferTestBase.java @@ -86,7 +86,7 @@ public abstract class WritableBufferTestBase { @Test public void testWriteSrcIndex() { - byte b[] = new byte[10]; + byte[] b = new byte[10]; for (byte i = 5; i < 10; i++) { b[i] = i; } @@ -94,10 +94,10 @@ public abstract class WritableBufferTestBase { buffer().write(b, 5, 5); assertEquals(5, buffer().readableBytes()); - byte writtenBytes[] = writtenBytes(); + byte[] writtenBytes = writtenBytes(); assertEquals(5, writtenBytes.length); for (int i = 0; i < writtenBytes.length; i++) { - assertEquals(5+i, writtenBytes[i]); + assertEquals(5 + i, writtenBytes[i]); } } diff --git a/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideServer.java b/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideServer.java index db457fd705..b66ffddf9d 100644 --- a/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideServer.java +++ b/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideServer.java @@ -63,7 +63,7 @@ public class RouteGuideServer { private final int port; private final Collection features; - private ServerImpl gRpcServer; + private ServerImpl grpcServer; public RouteGuideServer(int port) { this(port, RouteGuideUtil.getDefaultFeaturesFile()); @@ -79,7 +79,7 @@ public class RouteGuideServer { } public void start() { - gRpcServer = NettyServerBuilder.forPort(port) + grpcServer = NettyServerBuilder.forPort(port) .addService(RouteGuideGrpc.bindService(new RouteGuideService(features))) .build().start(); logger.info("Server started, listening on " + port); @@ -95,8 +95,8 @@ public class RouteGuideServer { } public void stop() { - if (gRpcServer != null) { - gRpcServer.shutdown(); + if (grpcServer != null) { + grpcServer.shutdown(); } } @@ -280,16 +280,16 @@ public class RouteGuideServer { double lat2 = RouteGuideUtil.getLatitude(end); double lon1 = RouteGuideUtil.getLongitude(start); double lon2 = RouteGuideUtil.getLongitude(end); - int R = 6371000; // metres + int r = 6371000; // metres double φ1 = toRadians(lat1); double φ2 = toRadians(lat2); - double Δφ = toRadians(lat2-lat1); - double Δλ = toRadians(lon2-lon1); + double Δφ = toRadians(lat2 - lat1); + double Δλ = toRadians(lon2 - lon1); - double a = sin(Δφ/2) * sin(Δφ/2) + cos(φ1) * cos(φ2) * sin(Δλ/2) * sin(Δλ/2); - double c = 2 * atan2(sqrt(a), sqrt(1-a)); + double a = sin(Δφ / 2) * sin(Δφ / 2) + cos(φ1) * cos(φ2) * sin(Δλ / 2) * sin(Δλ / 2); + double c = 2 * atan2(sqrt(a), sqrt(1 - a)); - return R * c; + return r * c; } } } diff --git a/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideUtil.java b/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideUtil.java index 65d8700dea..0c8831c5d8 100644 --- a/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideUtil.java +++ b/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideUtil.java @@ -31,8 +31,8 @@ package io.grpc.examples.routeguide; -import java.io.IOException; import java.io.InputStream; +import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.List; diff --git a/integration-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java b/integration-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java index bbb93c79b9..4276a015da 100644 --- a/integration-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java +++ b/integration-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java @@ -113,17 +113,18 @@ public abstract class AbstractTransportTest { protected TestServiceGrpc.TestService asyncStub; /** - * Must be called by the subclass setup method. + * Must be called by the subclass setup method if overriden. */ @Before - public void setup() { + public void setUp() { channel = createChannel(); blockingStub = TestServiceGrpc.newBlockingStub(channel); asyncStub = TestServiceGrpc.newStub(channel); } + /** Clean up. */ @After - public void teardown() throws Exception { + public void tearDown() throws Exception { if (channel != null) { channel.shutdown(); } diff --git a/integration-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java b/integration-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java index 002ab806b7..4e7dbf95cf 100644 --- a/integration-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java +++ b/integration-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java @@ -55,14 +55,14 @@ public class TestServiceClient { public static void main(String[] args) throws Exception { final TestServiceClient client = new TestServiceClient(); client.parseArgs(args); - client.setup(); + client.setUp(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { System.out.println("Shutting down"); try { - client.teardown(); + client.tearDown(); } catch (Exception e) { e.printStackTrace(); } @@ -72,7 +72,7 @@ public class TestServiceClient { try { client.run(); } finally { - client.teardown(); + client.tearDown(); } } @@ -146,18 +146,18 @@ public class TestServiceClient { + "\n --use_test_ca=true|false Whether to trust our fake CA. Default " + c.useTestCa + "\n --use_okhttp=true|false Whether to use OkHttp instead of Netty. Default " + c.useOkHttp - ); + ); System.exit(1); } } - private void setup() { - tester.setup(); + private void setUp() { + tester.setUp(); } - private synchronized void teardown() { + private synchronized void tearDown() { try { - tester.teardown(); + tester.tearDown(); } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { diff --git a/integration-testing/src/main/java/io/grpc/testing/integration/TestServiceImpl.java b/integration-testing/src/main/java/io/grpc/testing/integration/TestServiceImpl.java index 0261d14201..4be854927e 100644 --- a/integration-testing/src/main/java/io/grpc/testing/integration/TestServiceImpl.java +++ b/integration-testing/src/main/java/io/grpc/testing/integration/TestServiceImpl.java @@ -46,8 +46,8 @@ import io.grpc.testing.integration.Messages.StreamingInputCallResponse; import io.grpc.testing.integration.Messages.StreamingOutputCallRequest; import io.grpc.testing.integration.Messages.StreamingOutputCallResponse; -import java.io.IOException; import java.io.InputStream; +import java.io.IOException; import java.util.LinkedList; import java.util.Queue; import java.util.Random; @@ -321,8 +321,8 @@ public class TestServiceImpl implements TestServiceGrpc.TestService { // Increment the offset past this chunk. // Both buffers need to be circular. - offset = (offset + params.getSize()) % - (compressable ? compressableBuffer.size() : uncompressableBuffer.size()); + offset = (offset + params.getSize()) + % (compressable ? compressableBuffer.size() : uncompressableBuffer.size()); } return chunkQueue; } diff --git a/integration-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java b/integration-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java index 52ac9d0662..ac20d7a7b3 100644 --- a/integration-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java +++ b/integration-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java @@ -125,7 +125,7 @@ public class TestServiceServer { + "\n" + "\n --port=PORT Port to connect to. Default " + s.port + "\n --use_tls=true|false Whether to use TLS. Default " + s.useTls - ); + ); System.exit(1); } } diff --git a/integration-testing/src/main/java/io/grpc/testing/integration/Util.java b/integration-testing/src/main/java/io/grpc/testing/integration/Util.java index 1b246abcbb..bd367a1802 100644 --- a/integration-testing/src/main/java/io/grpc/testing/integration/Util.java +++ b/integration-testing/src/main/java/io/grpc/testing/integration/Util.java @@ -42,8 +42,8 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; -import java.io.IOException; import java.io.InputStream; +import java.io.IOException; import java.net.ServerSocket; import java.util.List; @@ -92,6 +92,7 @@ public class Util { return tmpFile; } + /** Assert that two messages are equal, producing a useful message if not. */ public static void assertEquals(MessageLite expected, MessageLite actual) { if (expected == null || actual == null) { Assert.assertEquals(expected, actual); @@ -106,6 +107,7 @@ public class Util { } } + /** Assert that two lists of messages are equal, producing a useful message if not. */ public static void assertEquals(List expected, List actual) { if (expected == null || actual == null) { diff --git a/integration-testing/src/test/java/io/grpc/stub/StubConfigTest.java b/integration-testing/src/test/java/io/grpc/stub/StubConfigTest.java index 9ed900c1fd..7c305469c7 100644 --- a/integration-testing/src/test/java/io/grpc/stub/StubConfigTest.java +++ b/integration-testing/src/test/java/io/grpc/stub/StubConfigTest.java @@ -45,7 +45,7 @@ import org.junit.runners.JUnit4; import java.util.concurrent.TimeUnit; /** - * Tests for stub reconfiguration + * Tests for stub reconfiguration. */ @RunWith(JUnit4.class) public class StubConfigTest { diff --git a/integration-testing/src/test/java/io/grpc/testing/integration/Http2NettyLocalChannelTest.java b/integration-testing/src/test/java/io/grpc/testing/integration/Http2NettyLocalChannelTest.java index 13c1d2d6c3..b7ac155a83 100644 --- a/integration-testing/src/test/java/io/grpc/testing/integration/Http2NettyLocalChannelTest.java +++ b/integration-testing/src/test/java/io/grpc/testing/integration/Http2NettyLocalChannelTest.java @@ -28,10 +28,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package io.grpc.testing.integration; -import org.junit.AfterClass; -import org.junit.BeforeClass; +package io.grpc.testing.integration; import io.grpc.ChannelImpl; import io.grpc.transport.netty.NegotiationType; @@ -41,11 +39,15 @@ import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalChannel; import io.netty.channel.local.LocalServerChannel; +import org.junit.AfterClass; +import org.junit.BeforeClass; + /** * Run transport tests over the Netty in-process channel. */ public class Http2NettyLocalChannelTest extends AbstractTransportTest { + /** Start server. */ @BeforeClass public static void startServer() { startStaticServer( @@ -54,6 +56,7 @@ public class Http2NettyLocalChannelTest extends AbstractTransportTest { .channelType(LocalServerChannel.class)); } + /** Stop server. */ @AfterClass public static void stopServer() { stopStaticServer(); diff --git a/nano/src/main/java/io/grpc/nano/NanoUtils.java b/nano/src/main/java/io/grpc/nano/NanoUtils.java index a82ceb654b..dd6118c318 100644 --- a/nano/src/main/java/io/grpc/nano/NanoUtils.java +++ b/nano/src/main/java/io/grpc/nano/NanoUtils.java @@ -38,8 +38,8 @@ import com.google.protobuf.nano.MessageNano; import io.grpc.Marshaller; import io.grpc.Status; -import java.io.IOException; import java.io.InputStream; +import java.io.IOException; /** * Utility methods for using nano proto with grpc. @@ -48,6 +48,7 @@ public class NanoUtils { private NanoUtils() {} + /** Adapt {@code parser} to a {@code Marshaller}. */ public static Marshaller marshaller(final Parser parser) { return new Marshaller() { @Override @@ -69,4 +70,4 @@ public class NanoUtils { } }; } -} \ No newline at end of file +} diff --git a/nano/src/main/java/io/grpc/nano/Parser.java b/nano/src/main/java/io/grpc/nano/Parser.java index aa9a235a2b..fab60e1021 100644 --- a/nano/src/main/java/io/grpc/nano/Parser.java +++ b/nano/src/main/java/io/grpc/nano/Parser.java @@ -39,8 +39,8 @@ import java.io.IOException; /** * Parser for parsing nano proto messages. * - * Should be implemented by generated code. + *

Should be implemented by generated code. */ -public interface Parser { +public interface Parser { T parse(CodedInputByteBufferNano input) throws IOException; } diff --git a/netty/src/main/java/io/grpc/transport/netty/Http2Negotiator.java b/netty/src/main/java/io/grpc/transport/netty/Http2Negotiator.java index 451517fc6f..a20b61dd81 100644 --- a/netty/src/main/java/io/grpc/transport/netty/Http2Negotiator.java +++ b/netty/src/main/java/io/grpc/transport/netty/Http2Negotiator.java @@ -102,7 +102,7 @@ public class Http2Negotiator { */ public static ChannelHandler serverTls(SSLEngine sslEngine) { Preconditions.checkNotNull(sslEngine, "sslEngine"); - if (!installJettyTLSProtocolSelection(sslEngine, SettableFuture.create(), true)) { + if (!installJettyTlsProtocolSelection(sslEngine, SettableFuture.create(), true)) { throw new IllegalStateException("NPN/ALPN extensions not installed"); } return new SslHandler(sslEngine, false); @@ -116,7 +116,7 @@ public class Http2Negotiator { Preconditions.checkNotNull(sslEngine, "sslEngine"); final SettableFuture completeFuture = SettableFuture.create(); - if (!installJettyTLSProtocolSelection(sslEngine, completeFuture, false)) { + if (!installJettyTlsProtocolSelection(sslEngine, completeFuture, false)) { throw new IllegalStateException("NPN/ALPN extensions not installed"); } final ChannelInitializer initializer = new ChannelInitializer() { @@ -279,7 +279,7 @@ public class Http2Negotiator { * * @return true if NPN/ALPN support is available. */ - private static boolean installJettyTLSProtocolSelection(final SSLEngine engine, + private static boolean installJettyTlsProtocolSelection(final SSLEngine engine, final SettableFuture protocolNegotiated, boolean server) { for (String protocolNegoClassName : JETTY_TLS_NEGOTIATION_IMPL) { try { diff --git a/netty/src/main/java/io/grpc/transport/netty/NettyClientHandler.java b/netty/src/main/java/io/grpc/transport/netty/NettyClientHandler.java index 8050ca9f9d..245f20df01 100644 --- a/netty/src/main/java/io/grpc/transport/netty/NettyClientHandler.java +++ b/netty/src/main/java/io/grpc/transport/netty/NettyClientHandler.java @@ -327,15 +327,14 @@ class NettyClientHandler extends Http2ConnectionHandler { /** * Processes the pending stream creation requests. This considers several conditions: * - *

- * 1) The HTTP/2 connection has exhausted its stream IDs. In this case all pending streams are + *

    + *
  1. The HTTP/2 connection has exhausted its stream IDs. In this case all pending streams are * immediately failed. - *

    - * 2) The HTTP/2 connection is going away. In this case all pending streams are immediately + *

  2. The HTTP/2 connection is going away. In this case all pending streams are immediately * failed. - *

    - * 3) The HTTP/2 connection's MAX_CONCURRENT_STREAMS limit has been reached. In this case, + *

  3. The HTTP/2 connection's MAX_CONCURRENT_STREAMS limit has been reached. In this case, * processing of pending streams stops until an active stream has been closed. + *
*/ private void createPendingStreams() { Http2Connection connection = connection(); diff --git a/netty/src/main/java/io/grpc/transport/netty/NettyServer.java b/netty/src/main/java/io/grpc/transport/netty/NettyServer.java index ffccab7a71..a96dce64b6 100644 --- a/netty/src/main/java/io/grpc/transport/netty/NettyServer.java +++ b/netty/src/main/java/io/grpc/transport/netty/NettyServer.java @@ -64,13 +64,13 @@ public class NettyServer extends AbstractService { private final EventLoopGroup workerGroup; private Channel channel; - public NettyServer(ServerListener serverListener, SocketAddress address, + NettyServer(ServerListener serverListener, SocketAddress address, Class channelType, EventLoopGroup bossGroup, EventLoopGroup workerGroup) { this(serverListener, address, channelType, bossGroup, workerGroup, null); } - public NettyServer(final ServerListener serverListener, SocketAddress address, + NettyServer(final ServerListener serverListener, SocketAddress address, Class channelType, EventLoopGroup bossGroup, EventLoopGroup workerGroup, @Nullable final SslContext sslContext) { this.address = address; diff --git a/netty/src/main/java/io/grpc/transport/netty/NettyServerBuilder.java b/netty/src/main/java/io/grpc/transport/netty/NettyServerBuilder.java index f5d622ccc7..38857794fd 100644 --- a/netty/src/main/java/io/grpc/transport/netty/NettyServerBuilder.java +++ b/netty/src/main/java/io/grpc/transport/netty/NettyServerBuilder.java @@ -37,13 +37,13 @@ import com.google.common.util.concurrent.Service; import io.grpc.AbstractServerBuilder; import io.grpc.HandlerRegistry; +import io.grpc.ServerImpl; import io.grpc.SharedResourceHolder; import io.grpc.transport.ServerListener; import io.netty.channel.EventLoopGroup; import io.netty.channel.ServerChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.ssl.SslContext; -import io.grpc.ServerImpl; import java.net.InetSocketAddress; import java.net.SocketAddress; diff --git a/netty/src/main/java/io/grpc/transport/netty/NettyServerHandler.java b/netty/src/main/java/io/grpc/transport/netty/NettyServerHandler.java index aea8292632..5b3bb33525 100644 --- a/netty/src/main/java/io/grpc/transport/netty/NettyServerHandler.java +++ b/netty/src/main/java/io/grpc/transport/netty/NettyServerHandler.java @@ -204,7 +204,7 @@ class NettyServerHandler extends Http2ConnectionHandler { } /** - * Handler for the Channel shutting down + * Handler for the Channel shutting down. */ @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { @@ -328,14 +328,15 @@ class NettyServerHandler extends Http2ConnectionHandler { } /** - * Returns the server stream associated to the given HTTP/2 stream object + * Returns the server stream associated to the given HTTP/2 stream object. */ private NettyServerStream serverStream(Http2Stream stream) { return stream.getProperty(NettyServerStream.class); } private Http2Exception newStreamException(int streamId, Throwable cause) { - return Http2Exception.streamError(streamId, Http2Error.INTERNAL_ERROR, cause.getMessage(), cause); + return Http2Exception.streamError( + streamId, Http2Error.INTERNAL_ERROR, cause.getMessage(), cause); } private static class LazyFrameListener extends Http2FrameAdapter { diff --git a/netty/src/main/java/io/grpc/transport/netty/NettyServerStream.java b/netty/src/main/java/io/grpc/transport/netty/NettyServerStream.java index c2e823718e..6477eec6d5 100644 --- a/netty/src/main/java/io/grpc/transport/netty/NettyServerStream.java +++ b/netty/src/main/java/io/grpc/transport/netty/NettyServerStream.java @@ -41,7 +41,7 @@ import io.netty.channel.Channel; import io.netty.handler.codec.http2.Http2Headers; /** - * Server stream for a Netty HTTP2 transport + * Server stream for a Netty HTTP2 transport. */ class NettyServerStream extends AbstractServerStream { diff --git a/netty/src/main/java/io/grpc/transport/netty/Utils.java b/netty/src/main/java/io/grpc/transport/netty/Utils.java index 53446f2ae2..83c16dca60 100644 --- a/netty/src/main/java/io/grpc/transport/netty/Utils.java +++ b/netty/src/main/java/io/grpc/transport/netty/Utils.java @@ -50,8 +50,8 @@ import io.netty.util.concurrent.GenericFutureListener; import java.nio.ByteBuffer; import java.util.Map; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadFactory; /** @@ -96,14 +96,10 @@ class Utils { return headers; } - public static Metadata.Trailers convertTrailers(Http2Headers http2Headers) { - return new Metadata.Trailers(convertHeadersToArray(http2Headers)); - } - private static byte[][] convertHeadersToArray(Http2Headers http2Headers) { // The Netty AsciiString class is really just a wrapper around a byte[] and supports // arbitrary binary data, not just ASCII. - byte[][] headerValues = new byte[http2Headers.size()*2][]; + byte[][] headerValues = new byte[http2Headers.size() * 2][]; int i = 0; for (Map.Entry entry : http2Headers) { headerValues[i++] = entry.getKey().array(); @@ -147,6 +143,10 @@ class Utils { return http2Headers; } + public static Metadata.Trailers convertTrailers(Http2Headers http2Headers) { + return new Metadata.Trailers(convertHeadersToArray(http2Headers)); + } + public static Http2Headers convertTrailers(Metadata.Trailers trailers, boolean headersSent) { Http2Headers http2Trailers = convertMetadata(trailers); if (!headersSent) { @@ -169,27 +169,28 @@ class Utils { private static class DefaultEventLoopGroupResource implements Resource { private final String name; - private final int nEventLoops; + private final int numEventLoops; - DefaultEventLoopGroupResource(int nEventLoops, String name) { + DefaultEventLoopGroupResource(int numEventLoops, String name) { this.name = name; - this.nEventLoops = nEventLoops; + this.numEventLoops = numEventLoops; } @Override public EventLoopGroup create() { // Use the executor based constructor so we can work with both Netty4 & Netty5. ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(name + "-%d").build(); - int parallelism = nEventLoops == 0 ? - Runtime.getRuntime().availableProcessors() * 2 : nEventLoops; + int parallelism = numEventLoops == 0 + ? Runtime.getRuntime().availableProcessors() * 2 : numEventLoops; final ExecutorService executor = Executors.newFixedThreadPool(parallelism, threadFactory); NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(parallelism, executor); - nioEventLoopGroup.terminationFuture().addListener(new GenericFutureListener>() { - @Override - public void operationComplete(Future future) throws Exception { - executor.shutdown(); - } - }); + nioEventLoopGroup.terminationFuture().addListener( + new GenericFutureListener>() { + @Override + public void operationComplete(Future future) throws Exception { + executor.shutdown(); + } + }); return nioEventLoopGroup; } diff --git a/netty/src/test/java/io/grpc/transport/netty/NettyClientHandlerTest.java b/netty/src/test/java/io/grpc/transport/netty/NettyClientHandlerTest.java index 7cb5e433df..d69af83d77 100644 --- a/netty/src/test/java/io/grpc/transport/netty/NettyClientHandlerTest.java +++ b/netty/src/test/java/io/grpc/transport/netty/NettyClientHandlerTest.java @@ -34,8 +34,8 @@ package io.grpc.transport.netty; import static com.google.common.base.Charsets.UTF_8; import static io.grpc.transport.netty.Utils.CONTENT_TYPE_GRPC; import static io.grpc.transport.netty.Utils.CONTENT_TYPE_HEADER; -import static io.grpc.transport.netty.Utils.HTTPS; import static io.grpc.transport.netty.Utils.HTTP_METHOD; +import static io.grpc.transport.netty.Utils.HTTPS; import static io.grpc.transport.netty.Utils.STATUS_OK; import static io.grpc.transport.netty.Utils.TE_HEADER; import static io.grpc.transport.netty.Utils.TE_TRAILERS; @@ -96,8 +96,9 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase { private ByteBuf content; private Http2Headers grpcHeaders; + /** Set up for test. */ @Before - public void setup() throws Exception { + public void setUp() throws Exception { MockitoAnnotations.initMocks(this); frameWriter = new DefaultHttp2FrameWriter(); diff --git a/netty/src/test/java/io/grpc/transport/netty/NettyServerHandlerTest.java b/netty/src/test/java/io/grpc/transport/netty/NettyServerHandlerTest.java index d8d8ca98ac..7e2b0709c8 100644 --- a/netty/src/test/java/io/grpc/transport/netty/NettyServerHandlerTest.java +++ b/netty/src/test/java/io/grpc/transport/netty/NettyServerHandlerTest.java @@ -106,8 +106,9 @@ public class NettyServerHandlerTest extends NettyHandlerTestBase { private NettyServerHandler handler; + /** Set up for test. */ @Before - public void setup() throws Exception { + public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(transportListener.streamCreated(any(ServerStream.class), @@ -156,13 +157,13 @@ public class NettyServerHandlerTest extends NettyHandlerTestBase { } @Test - public void inboundDataShouldForwardToStreamListener() throws Exception { - inboundDataShouldForwardToStreamListener(false); + public void inboundDataWithEndStreamShouldForwardToStreamListener() throws Exception { + inboundDataShouldForwardToStreamListener(true); } @Test - public void inboundDataWithEndStreamShouldForwardToStreamListener() throws Exception { - inboundDataShouldForwardToStreamListener(true); + public void inboundDataShouldForwardToStreamListener() throws Exception { + inboundDataShouldForwardToStreamListener(false); } private void inboundDataShouldForwardToStreamListener(boolean endStream) throws Exception { diff --git a/netty/src/test/java/io/grpc/transport/netty/NettyStreamTestBase.java b/netty/src/test/java/io/grpc/transport/netty/NettyStreamTestBase.java index 3360a00e01..e5d5e56978 100644 --- a/netty/src/test/java/io/grpc/transport/netty/NettyStreamTestBase.java +++ b/netty/src/test/java/io/grpc/transport/netty/NettyStreamTestBase.java @@ -95,8 +95,9 @@ public abstract class NettyStreamTestBase { protected AbstractStream stream; + /** Set up for test. */ @Before - public void setup() { + public void setUp() { MockitoAnnotations.initMocks(this); mockChannelFuture(true); diff --git a/netty/src/test/java/io/grpc/transport/netty/NettyWritableBufferTest.java b/netty/src/test/java/io/grpc/transport/netty/NettyWritableBufferTest.java index 41cdd18f18..233aad4f98 100644 --- a/netty/src/test/java/io/grpc/transport/netty/NettyWritableBufferTest.java +++ b/netty/src/test/java/io/grpc/transport/netty/NettyWritableBufferTest.java @@ -66,7 +66,7 @@ public class NettyWritableBufferTest extends WritableBufferTestBase { @Override protected byte[] writtenBytes() { - byte b[] = buffer.bytebuf().array(); + byte[] b = buffer.bytebuf().array(); int fromIdx = buffer.bytebuf().arrayOffset(); return Arrays.copyOfRange(b, fromIdx, buffer.readableBytes()); } diff --git a/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpChannelBuilder.java b/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpChannelBuilder.java index 1a62f7bdfc..cb5234d6e6 100644 --- a/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpChannelBuilder.java +++ b/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpChannelBuilder.java @@ -40,8 +40,8 @@ import io.grpc.SharedResourceHolder.Resource; import io.grpc.transport.ClientTransportFactory; import java.net.InetSocketAddress; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; import javax.net.ssl.SSLSocketFactory; diff --git a/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpClientTransport.java b/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpClientTransport.java index 20cbffc351..6f4f057cad 100644 --- a/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpClientTransport.java +++ b/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpClientTransport.java @@ -342,7 +342,7 @@ public class OkHttpClientTransport implements ClientTransport { } /** - * Runnable which reads frames and dispatches them to in flight calls + * Runnable which reads frames and dispatches them to in flight calls. */ @VisibleForTesting class ClientFrameHandler implements FrameReader.Handler, Runnable { @@ -365,7 +365,7 @@ public class OkHttpClientTransport implements ClientTransport { } /** - * Handle a HTTP2 DATA frame + * Handle a HTTP2 DATA frame. */ @Override public void data(boolean inFinished, int streamId, BufferedSource in, int length) @@ -393,7 +393,7 @@ public class OkHttpClientTransport implements ClientTransport { } /** - * Handle HTTP2 HEADER and CONTINUATION frames + * Handle HTTP2 HEADER and CONTINUATION frames. */ @Override public void headers(boolean outFinished, diff --git a/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpReadableBuffer.java b/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpReadableBuffer.java index fb372e878b..0768ae9df9 100644 --- a/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpReadableBuffer.java +++ b/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpReadableBuffer.java @@ -40,7 +40,7 @@ import java.io.OutputStream; import java.nio.ByteBuffer; /** - * A {@link io.grpc.transport.ReadableBuffer} implementation that is backed by an {@link okio.Buffer}. + * A {@link ReadableBuffer} implementation that is backed by an {@link okio.Buffer}. */ class OkHttpReadableBuffer extends AbstractReadableBuffer { private final okio.Buffer buffer; diff --git a/okhttp/src/test/java/io/grpc/transport/okhttp/OkHttpClientTransportTest.java b/okhttp/src/test/java/io/grpc/transport/okhttp/OkHttpClientTransportTest.java index 33ad46fec3..7070bfdb28 100644 --- a/okhttp/src/test/java/io/grpc/transport/okhttp/OkHttpClientTransportTest.java +++ b/okhttp/src/test/java/io/grpc/transport/okhttp/OkHttpClientTransportTest.java @@ -73,16 +73,16 @@ import org.mockito.MockitoAnnotations; import java.io.BufferedReader; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; /** @@ -107,8 +107,9 @@ public class OkHttpClientTransportTest { private ClientFrameHandler frameHandler; private ExecutorService executor; + /** Set up for test. */ @Before - public void setup() { + public void setUp() { MockitoAnnotations.initMocks(this); streams = new HashMap(); frameReader = new MockFrameReader(); @@ -121,6 +122,7 @@ public class OkHttpClientTransportTest { when(frameWriter.maxDataLength()).thenReturn(Integer.MAX_VALUE); } + /** Final test checks and clean up. */ @After public void tearDown() { clientTransport.shutdown(); @@ -133,7 +135,7 @@ public class OkHttpClientTransportTest { * When nextFrame throws IOException, the transport should be aborted. */ @Test - public void nextFrameThrowIOException() throws Exception { + public void nextFrameThrowIoException() throws Exception { MockStreamListener listener1 = new MockStreamListener(); MockStreamListener listener2 = new MockStreamListener(); clientTransport.newStream(method, new Metadata.Headers(), listener1).request(1); @@ -141,7 +143,7 @@ public class OkHttpClientTransportTest { assertEquals(2, streams.size()); assertTrue(streams.containsKey(3)); assertTrue(streams.containsKey(5)); - frameReader.throwIOExceptionForNextFrame(); + frameReader.throwIoExceptionForNextFrame(); listener1.waitUntilStreamClosed(); listener2.waitUntilStreamClosed(); assertEquals(0, streams.size()); @@ -495,7 +497,7 @@ public class OkHttpClientTransportTest { return true; } - synchronized void throwIOExceptionForNextFrame() { + synchronized void throwIoExceptionForNextFrame() { throwExceptionForNextFrame = true; notifyAll(); } diff --git a/stub/src/main/java/io/grpc/stub/Calls.java b/stub/src/main/java/io/grpc/stub/Calls.java index 5b9813ef88..ec0b2341f6 100644 --- a/stub/src/main/java/io/grpc/stub/Calls.java +++ b/stub/src/main/java/io/grpc/stub/Calls.java @@ -259,7 +259,8 @@ public class Calls { private final Call call; private final StreamObserver observer; - public StreamObserverToCallListenerAdapter(Call call, StreamObserver observer) { + public StreamObserverToCallListenerAdapter( + Call call, StreamObserver observer) { this.call = call; this.observer = observer; } diff --git a/stub/src/main/java/io/grpc/stub/MetadataUtils.java b/stub/src/main/java/io/grpc/stub/MetadataUtils.java index 552c0afb2b..ce30025f08 100644 --- a/stub/src/main/java/io/grpc/stub/MetadataUtils.java +++ b/stub/src/main/java/io/grpc/stub/MetadataUtils.java @@ -43,7 +43,7 @@ import io.grpc.Status; import java.util.concurrent.atomic.AtomicReference; /** - * Utility functions for binding and receiving headers + * Utility functions for binding and receiving headers. */ public class MetadataUtils { diff --git a/stub/src/main/java/io/grpc/stub/Method.java b/stub/src/main/java/io/grpc/stub/Method.java index a11b2ab37a..f756945159 100644 --- a/stub/src/main/java/io/grpc/stub/Method.java +++ b/stub/src/main/java/io/grpc/stub/Method.java @@ -78,7 +78,7 @@ public class Method { } /** - * The name of the method, not including the service name + * The name of the method, not including the service name. */ public String getName() { return name;