mirror of https://github.com/grpc/grpc-java.git
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.
This commit is contained in:
parent
c5bcbc62fe
commit
c3e8dae6ce
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<StreamingInputCallRequest>
|
||||
streamingInputCall(StreamObserver<StreamingInputCallResponse> responseObserver) {
|
||||
public StreamObserver<StreamingInputCallRequest> streamingInputCall(
|
||||
StreamObserver<StreamingInputCallResponse> responseObserver) {
|
||||
throw Status.UNIMPLEMENTED.asRuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamObserver<StreamingOutputCallRequest>
|
||||
fullDuplexCall(StreamObserver<StreamingOutputCallResponse> responseObserver) {
|
||||
public StreamObserver<StreamingOutputCallRequest> fullDuplexCall(
|
||||
StreamObserver<StreamingOutputCallResponse> responseObserver) {
|
||||
throw Status.UNIMPLEMENTED.asRuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamObserver<StreamingOutputCallRequest>
|
||||
halfDuplexCall(StreamObserver<StreamingOutputCallResponse> responseObserver) {
|
||||
public StreamObserver<StreamingOutputCallRequest> halfDuplexCall(
|
||||
StreamObserver<StreamingOutputCallResponse> responseObserver) {
|
||||
throw Status.UNIMPLEMENTED.asRuntimeException();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
build.gradle
16
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
|
||||
|
|
|
|||
479
checkstyle.xml
479
checkstyle.xml
|
|
@ -1,328 +1,207 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE module PUBLIC
|
||||
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
||||
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
||||
|
||||
<!-- This is a checkstyle configuration file. For descriptions of
|
||||
what the following rules do, please see the checkstyle configuration
|
||||
page at http://checkstyle.sourceforge.net/config.html -->
|
||||
<!--
|
||||
|
||||
Checkstyle configuration that checks the Google coding conventions from:
|
||||
|
||||
- Google Java Style
|
||||
https://google-styleguide.googlecode.com/svn-history/r130/trunk/javaguide.html
|
||||
|
||||
Checkstyle is very configurable. Be sure to read the documentation at
|
||||
http://checkstyle.sf.net (or in your downloaded distribution).
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
|
||||
<module name = "Checker">
|
||||
<property name="charset" value="UTF-8"/>
|
||||
|
||||
<module name="RegexpHeader">
|
||||
<!-- Checks for copyright headers.
|
||||
-->
|
||||
<property name="headerFile" value="${checkstyle.header.file}"/>
|
||||
</module>
|
||||
<property name="severity" value="warning"/>
|
||||
|
||||
<!-- Checks for whitespace -->
|
||||
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
|
||||
<module name="FileTabCharacter">
|
||||
<!-- Checks that there are no tab characters in the file.
|
||||
-->
|
||||
<property name="eachLine" value="true"/>
|
||||
</module>
|
||||
|
||||
<module name="NewlineAtEndOfFile">
|
||||
<property name="lineSeparator" value="lf"/>
|
||||
</module>
|
||||
|
||||
<module name="RegexpSingleline">
|
||||
<!-- Checks that FIXME is not used in comments. TODO is preferred.
|
||||
-->
|
||||
<property name="format" value="((//.*)|(\*.*))FIXME" />
|
||||
<property name="message" value='TODO is preferred to FIXME. e.g. "TODO(johndoe): Refactor when v2 is released."' />
|
||||
</module>
|
||||
|
||||
<module name="RegexpSingleline">
|
||||
<!-- Checks that TODOs are named. (Actually, just that they are followed
|
||||
by an open paren.)
|
||||
-->
|
||||
<property name="format" value="((//.*)|(\*.*))TODO[^(]" />
|
||||
<property name="message" value='All TODOs should be named. e.g. "TODO(johndoe): Refactor when v2 is released."' />
|
||||
</module>
|
||||
|
||||
<module name="JavadocPackage">
|
||||
<!-- Checks that each Java package has a Javadoc file used for commenting.
|
||||
Only allows a package-info.java, not package.html. -->
|
||||
</module>
|
||||
|
||||
<!-- All Java AST specific tests live under TreeWalker module. -->
|
||||
<module name="TreeWalker">
|
||||
|
||||
<!--
|
||||
|
||||
IMPORT CHECKS
|
||||
|
||||
-->
|
||||
|
||||
<module name="RedundantImport">
|
||||
<!-- Checks for redundant import statements. -->
|
||||
<property name="severity" value="error"/>
|
||||
<module name="OuterTypeFilename"/>
|
||||
<module name="IllegalTokenText">
|
||||
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
|
||||
<property name="format" value="\\u00(08|09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
|
||||
<property name="message" value="Avoid using corresponding octal or Unicode escape."/>
|
||||
</module>
|
||||
|
||||
<module name="ImportOrder">
|
||||
<!-- Checks for out of order import statements. -->
|
||||
|
||||
<property name="severity" value="warning"/>
|
||||
<property name="groups" value="com.google,android,junit,net,org,java,javax"/>
|
||||
<!-- This ensures that static imports go first. -->
|
||||
<property name="option" value="top"/>
|
||||
<property name="tokens" value="STATIC_IMPORT, IMPORT"/>
|
||||
<module name="AvoidEscapedUnicodeCharacters">
|
||||
<property name="allowEscapesForControlCharacters" value="true"/>
|
||||
<property name="allowByTailComment" value="true"/>
|
||||
<property name="allowNonPrintableEscapes" value="true"/>
|
||||
</module>
|
||||
|
||||
<!--
|
||||
|
||||
JAVADOC CHECKS
|
||||
|
||||
-->
|
||||
|
||||
<!-- Checks for Javadoc comments. -->
|
||||
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
|
||||
<module name="JavadocMethod">
|
||||
<property name="scope" value="protected"/>
|
||||
<property name="severity" value="warning"/>
|
||||
<property name="allowMissingJavadoc" value="true"/>
|
||||
<property name="allowMissingParamTags" value="true"/>
|
||||
<property name="allowMissingReturnTag" value="true"/>
|
||||
<property name="allowMissingThrowsTags" value="true"/>
|
||||
<property name="allowThrowsTagsForSubclasses" value="true"/>
|
||||
<property name="allowUndeclaredRTE" value="true"/>
|
||||
</module>
|
||||
|
||||
<module name="JavadocType">
|
||||
<property name="scope" value="protected"/>
|
||||
<property name="severity" value="error"/>
|
||||
</module>
|
||||
|
||||
<module name="JavadocStyle">
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<!--
|
||||
|
||||
NAMING CHECKS
|
||||
|
||||
-->
|
||||
|
||||
<!-- Item 38 - Adhere to generally accepted naming conventions -->
|
||||
|
||||
<module name="PackageName">
|
||||
<!-- Validates identifiers for package names against the
|
||||
supplied expression. -->
|
||||
<!-- Here the default checkstyle rule restricts package name parts to
|
||||
seven characters, this is not in line with common practice at Google.
|
||||
-->
|
||||
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]{1,})*$"/>
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="TypeNameCheck">
|
||||
<!-- Validates static, final fields against the
|
||||
expression "^[A-Z][a-zA-Z0-9]*$". -->
|
||||
<metadata name="altname" value="TypeName"/>
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="ConstantNameCheck">
|
||||
<!-- Validates non-private, static, final fields against the supplied
|
||||
public/package final fields "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$". -->
|
||||
<metadata name="altname" value="ConstantName"/>
|
||||
<property name="applyToPublic" value="true"/>
|
||||
<property name="applyToProtected" value="true"/>
|
||||
<property name="applyToPackage" value="true"/>
|
||||
<property name="applyToPrivate" value="false"/>
|
||||
<property name="format" value="^([A-Z][A-Z0-9]*(_[A-Z0-9]+)*|FLAG_.*)$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Variable ''{0}'' should be in ALL_CAPS (if it is a constant) or be private (otherwise)."/>
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="StaticVariableNameCheck">
|
||||
<!-- Validates static, non-final fields against the supplied
|
||||
expression "^[a-z][a-zA-Z0-9]*_?$". -->
|
||||
<metadata name="altname" value="StaticVariableName"/>
|
||||
<property name="applyToPublic" value="true"/>
|
||||
<property name="applyToProtected" value="true"/>
|
||||
<property name="applyToPackage" value="true"/>
|
||||
<property name="applyToPrivate" value="true"/>
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]*_?$"/>
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="MemberNameCheck">
|
||||
<!-- Validates non-static members against the supplied expression. -->
|
||||
<metadata name="altname" value="MemberName"/>
|
||||
<property name="applyToPublic" value="true"/>
|
||||
<property name="applyToProtected" value="true"/>
|
||||
<property name="applyToPackage" value="true"/>
|
||||
<property name="applyToPrivate" value="true"/>
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="MethodNameCheck">
|
||||
<!-- Validates identifiers for method names. -->
|
||||
<metadata name="altname" value="MethodName"/>
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*$"/>
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="ParameterName">
|
||||
<!-- Validates identifiers for method parameters against the
|
||||
expression "^[a-z][a-zA-Z0-9]*$". -->
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="LocalFinalVariableName">
|
||||
<!-- Validates identifiers for local final variables against the
|
||||
expression "^[a-z][a-zA-Z0-9]*$". -->
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
<module name="LocalVariableName">
|
||||
<!-- Validates identifiers for local variables against the
|
||||
expression "^[a-z][a-zA-Z0-9]*$". -->
|
||||
<property name="severity" value="warning"/>
|
||||
</module>
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
LENGTH and CODING CHECKS
|
||||
|
||||
-->
|
||||
|
||||
<module name="LineLength">
|
||||
<!-- Checks if a line is too long. -->
|
||||
<property name="max" value="${com.puppycrawl.tools.checkstyle.checks.sizes.LineLength.max}" default="100"/>
|
||||
<property name="severity" value="error"/>
|
||||
|
||||
<!--
|
||||
The default ignore pattern exempts the following elements:
|
||||
- import statements
|
||||
- long URLs inside comments
|
||||
-->
|
||||
|
||||
<property name="ignorePattern"
|
||||
value="${com.puppycrawl.tools.checkstyle.checks.sizes.LineLength.ignorePattern}"
|
||||
default="^(package .*;\s*)|(import .*;\s*)|( *\* *https?://.*)$"/>
|
||||
<property name="max" value="100"/>
|
||||
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
|
||||
</module>
|
||||
|
||||
<module name="AvoidStarImport"/>
|
||||
<module name="OneTopLevelClass"/>
|
||||
<module name="NoLineWrap"/>
|
||||
<module name="EmptyBlock">
|
||||
<property name="option" value="TEXT"/>
|
||||
<property name="tokens" value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
|
||||
</module>
|
||||
<module name="NeedBraces"/>
|
||||
<module name="LeftCurly">
|
||||
<!-- Checks for placement of the left curly brace ('{'). -->
|
||||
<property name="severity" value="warning"/>
|
||||
<property name="maxLineLength" value="100"/>
|
||||
</module>
|
||||
|
||||
<module name="RightCurly"/>
|
||||
<module name="RightCurly">
|
||||
<!-- Checks right curlies on CATCH, ELSE, and TRY blocks are on
|
||||
the same line. e.g., the following example is fine:
|
||||
<pre>
|
||||
if {
|
||||
...
|
||||
} else
|
||||
</pre>
|
||||
-->
|
||||
<!-- This next example is not fine:
|
||||
<pre>
|
||||
if {
|
||||
...
|
||||
}
|
||||
else
|
||||
</pre>
|
||||
-->
|
||||
<property name="option" value="same"/>
|
||||
<property name="severity" value="warning"/>
|
||||
<property name="option" value="alone"/>
|
||||
<property name="tokens" value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/>
|
||||
</module>
|
||||
|
||||
<!-- Checks for braces around if and else blocks -->
|
||||
<module name="NeedBraces">
|
||||
<property name="severity" value="warning"/>
|
||||
<property name="tokens" value="LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO"/>
|
||||
</module>
|
||||
|
||||
<module name="UpperEll">
|
||||
<!-- Checks that long constants are defined with an upper ell.-->
|
||||
<property name="severity" value="error"/>
|
||||
</module>
|
||||
|
||||
<module name="FallThrough">
|
||||
<!-- Warn about falling through to the next case statement. Similar to
|
||||
javac -Xlint:fallthrough, but the check is suppressed if a single-line comment
|
||||
on the last non-blank line preceding the fallen-into case contains 'fall through' (or
|
||||
some other variants which we don't publicized to promote consistency).
|
||||
-->
|
||||
<property name="reliefPattern"
|
||||
value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
|
||||
<property name="severity" value="error"/>
|
||||
</module>
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
MODIFIERS CHECKS
|
||||
|
||||
-->
|
||||
|
||||
<module name="ModifierOrder">
|
||||
<!-- Warn if modifier order is inconsistent with JLS3 8.1.1, 8.3.1, and
|
||||
8.4.3. The prescribed order is:
|
||||
public, protected, private, abstract, static, final, transient, volatile,
|
||||
synchronized, native, strictfp
|
||||
-->
|
||||
</module>
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
WHITESPACE CHECKS
|
||||
|
||||
-->
|
||||
|
||||
<module name="WhitespaceAround">
|
||||
<!-- Checks that various tokens are surrounded by whitespace.
|
||||
This includes most binary operators and keywords followed
|
||||
by regular or curly braces.
|
||||
-->
|
||||
<property name="tokens" value="ASSIGN, BAND, BAND_ASSIGN, BOR,
|
||||
BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN,
|
||||
EQUAL, GE, GT, LAND, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
|
||||
LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
|
||||
LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS,
|
||||
MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION,
|
||||
SL, SL_ASSIGN, SR_ASSIGN, STAR, STAR_ASSIGN"/>
|
||||
<property name="severity" value="error"/>
|
||||
<property name="allowEmptyConstructors" value="true"/>
|
||||
<property name="allowEmptyMethods" value="true"/>
|
||||
<property name="allowEmptyTypes" value="true"/>
|
||||
<property name="allowEmptyLoops" value="true"/>
|
||||
<message key="ws.notFollowed"
|
||||
value="WhitespaceAround: ''{0}'' is not followed by whitespace."/>
|
||||
<message key="ws.notPreceded"
|
||||
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
|
||||
</module>
|
||||
|
||||
<module name="WhitespaceAfter">
|
||||
<!-- Checks that commas, semicolons and typecasts are followed by
|
||||
whitespace.
|
||||
-->
|
||||
<property name="tokens" value="COMMA, SEMI, TYPECAST"/>
|
||||
<module name="OneStatementPerLine"/>
|
||||
<module name="MultipleVariableDeclarations"/>
|
||||
<module name="ArrayTypeStyle"/>
|
||||
<module name="MissingSwitchDefault"/>
|
||||
<module name="FallThrough"/>
|
||||
<module name="UpperEll"/>
|
||||
<module name="ModifierOrder"/>
|
||||
<module name="EmptyLineSeparator">
|
||||
<property name="allowNoEmptyLineBetweenFields" value="true"/>
|
||||
</module>
|
||||
|
||||
<module name="NoWhitespaceAfter">
|
||||
<!-- Checks that there is no whitespace after various unary operators.
|
||||
Linebreaks are allowed.
|
||||
-->
|
||||
<property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS,
|
||||
UNARY_PLUS"/>
|
||||
<property name="allowLineBreaks" value="true"/>
|
||||
<property name="severity" value="error"/>
|
||||
<module name="SeparatorWrap">
|
||||
<property name="tokens" value="DOT"/>
|
||||
<property name="option" value="nl"/>
|
||||
</module>
|
||||
|
||||
<module name="NoWhitespaceBefore">
|
||||
<!-- Checks that there is no whitespace before various unary operators.
|
||||
Linebreaks are allowed.
|
||||
-->
|
||||
<property name="tokens" value="SEMI, DOT, POST_DEC, POST_INC"/>
|
||||
<property name="allowLineBreaks" value="true"/>
|
||||
<property name="severity" value="error"/>
|
||||
<module name="SeparatorWrap">
|
||||
<property name="tokens" value="COMMA"/>
|
||||
<property name="option" value="EOL"/>
|
||||
</module>
|
||||
|
||||
<module name="ParenPad">
|
||||
<!-- Checks that there is no whitespace before close parens or after
|
||||
open parens.
|
||||
-->
|
||||
<property name="severity" value="warning"/>
|
||||
<module name="PackageName">
|
||||
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Package name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
|
||||
<module name="TypeName">
|
||||
<message key="name.invalidPattern"
|
||||
value="Type name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="MemberName">
|
||||
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Member name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="ParameterName">
|
||||
<!-- TODO(ejona): too strict, as one-character parameter names are permitted
|
||||
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/-->
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="LocalVariableName">
|
||||
<property name="tokens" value="VARIABLE_DEF"/>
|
||||
<!-- TODO(ejona): too strict, as one-character parameter names are permitted.
|
||||
Add support for Unicode.
|
||||
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/-->
|
||||
<property name="format" value="^[^A-Z]"/>
|
||||
<property name="allowOneCharVarInForLoop" value="true"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="ClassTypeParameterName">
|
||||
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Class type name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="MethodTypeParameterName">
|
||||
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Method type name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="NoFinalizer"/>
|
||||
<module name="GenericWhitespace">
|
||||
<message key="ws.followed"
|
||||
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
|
||||
<message key="ws.preceded"
|
||||
value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
|
||||
<message key="ws.illegalFollow"
|
||||
value="GenericWhitespace ''{0}'' should followed by whitespace."/>
|
||||
<message key="ws.notPreceded"
|
||||
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
|
||||
</module>
|
||||
<module name="Indentation">
|
||||
<property name="basicOffset" value="2"/>
|
||||
<property name="braceAdjustment" value="0"/>
|
||||
<property name="caseIndent" value="2"/>
|
||||
<property name="throwsIndent" value="4"/>
|
||||
<property name="lineWrappingIndentation" value="4"/>
|
||||
<property name="arrayInitIndent" value="2"/>
|
||||
</module>
|
||||
<module name="AbbreviationAsWordInName">
|
||||
<property name="ignoreFinal" value="false"/>
|
||||
<property name="allowedAbbreviationLength" value="1"/>
|
||||
</module>
|
||||
<module name="OverloadMethodsDeclarationOrder"/>
|
||||
<!-- TODO(ejona): Does not consider assignment during declaration as a usage.
|
||||
<module name="VariableDeclarationUsageDistance"/-->
|
||||
<module name="CustomImportOrder">
|
||||
<property name="thirdPartyPackageRegExp" value=".*"/>
|
||||
<property name="specialImportsRegExp" value="com.google"/>
|
||||
<property name="sortImportsInGroupAlphabetically" value="true"/>
|
||||
<property name="customImportOrderRules" value="STATIC###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE"/>
|
||||
</module>
|
||||
<module name="MethodParamPad"/>
|
||||
<module name="OperatorWrap">
|
||||
<property name="option" value="NL"/>
|
||||
<property name="tokens" value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR "/>
|
||||
</module>
|
||||
<module name="AnnotationLocation">
|
||||
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
|
||||
</module>
|
||||
<module name="AnnotationLocation">
|
||||
<property name="tokens" value="VARIABLE_DEF"/>
|
||||
<property name="allowSamelineMultipleAnnotations" value="true"/>
|
||||
</module>
|
||||
<module name="NonEmptyAtclauseDescription"/>
|
||||
<module name="JavadocTagContinuationIndentation"/>
|
||||
<module name="SummaryJavadocCheck">
|
||||
<property name="forbiddenSummaryFragments" value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
|
||||
</module>
|
||||
<module name="JavadocParagraph"/>
|
||||
<module name="AtclauseOrder">
|
||||
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
|
||||
<property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
|
||||
</module>
|
||||
<module name="JavadocMethod">
|
||||
<property name="scope" value="public"/>
|
||||
<property name="allowMissingParamTags" value="true"/>
|
||||
<property name="allowMissingThrowsTags" value="true"/>
|
||||
<property name="allowMissingReturnTag" value="true"/>
|
||||
<property name="minLineCount" value="2"/>
|
||||
<property name="allowedAnnotations" value="Override, Test"/>
|
||||
<property name="allowThrowsTagsForSubclasses" value="true"/>
|
||||
</module>
|
||||
<module name="MethodName">
|
||||
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Method name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<!-- TODO(ejona86): too strict, as {@link} is permitted in single-line JavaDoc
|
||||
<module name="SingleLineJavadoc"/-->
|
||||
</module>
|
||||
</module>
|
||||
|
|
@ -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<BuilderT extends AbstractChannelBui
|
|||
@Nullable final Runnable terminationRunnable;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param transportFactory the created channel uses this factory to create transports
|
||||
* @param terminationRunnable will be called at the channel's life-cycle events
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ import io.grpc.transport.ClientStreamListener;
|
|||
import io.grpc.transport.ClientTransport;
|
||||
import io.grpc.transport.ClientTransportFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
|
@ -58,9 +58,13 @@ public final class ChannelImpl implements Channel {
|
|||
|
||||
private static class NoopClientStream implements ClientStream {
|
||||
@Override public void writeMessage(InputStream message, int length, Runnable accepted) {}
|
||||
|
||||
@Override public void flush() {}
|
||||
|
||||
@Override public void cancel() {}
|
||||
|
||||
@Override public void halfClose() {}
|
||||
|
||||
@Override public void request(int numMessages) {}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ import javax.annotation.concurrent.ThreadSafe;
|
|||
public interface ClientInterceptor {
|
||||
/**
|
||||
* Intercept {@link Call} creation by the {@code next} {@link Channel}.
|
||||
* <p>
|
||||
* Many variations of interception are possible. Complex implementations may return a wrapper
|
||||
*
|
||||
* <p>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()}.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -195,6 +195,7 @@ public final class SharedResourceHolder {
|
|||
final Object payload;
|
||||
int refcount;
|
||||
ScheduledFuture<?> destroyTask;
|
||||
|
||||
Instance(Object payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -231,13 +231,14 @@ public final class Status {
|
|||
|
||||
// Create the canonical list of Status instances indexed by their code values.
|
||||
private static List<Status> STATUS_LIST;
|
||||
|
||||
static {
|
||||
TreeMap<Integer, Status> canonicalizer = new TreeMap<Integer, Status>();
|
||||
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<Status>(canonicalizer.values());
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import java.io.InputStream;
|
|||
*/
|
||||
public class ProtoUtils {
|
||||
|
||||
/** Adapt a {@code Parser} to a {@code Marshaller}. */
|
||||
public static <T extends MessageLite> Marshaller<T> marshaller(final Parser<T> parser) {
|
||||
return new Marshaller<T>() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ public abstract class AbstractStream<IdT> 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");
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*
|
||||
* <p>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;
|
||||
|
||||
|
|
|
|||
|
|
@ -122,8 +122,8 @@ public abstract class Http2ClientStream extends AbstractClientStream<Integer> {
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<String> 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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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<ByteWritableBuffer> 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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
||||
|
|
|
|||
|
|
@ -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,7 +94,7 @@ 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]);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class RouteGuideServer {
|
|||
|
||||
private final int port;
|
||||
private final Collection<Feature> 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,7 +280,7 @@ 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);
|
||||
|
|
@ -289,7 +289,7 @@ public class RouteGuideServer {
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -151,13 +151,13 @@ public class TestServiceClient {
|
|||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<? extends MessageLite> expected,
|
||||
List<? extends MessageLite> actual) {
|
||||
if (expected == null || actual == null) {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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 <T extends MessageNano> Marshaller<T> marshaller(final Parser<T> parser) {
|
||||
return new Marshaller<T>() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for parsing nano proto messages.
|
||||
*
|
||||
* Should be implemented by generated code.
|
||||
* <p>Should be implemented by generated code.
|
||||
*/
|
||||
public interface Parser<T extends MessageNano> {
|
||||
T parse(CodedInputByteBufferNano input) throws IOException;
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ public class Http2Negotiator {
|
|||
*/
|
||||
public static ChannelHandler serverTls(SSLEngine sslEngine) {
|
||||
Preconditions.checkNotNull(sslEngine, "sslEngine");
|
||||
if (!installJettyTLSProtocolSelection(sslEngine, SettableFuture.<Void>create(), true)) {
|
||||
if (!installJettyTlsProtocolSelection(sslEngine, SettableFuture.<Void>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<Void> completeFuture = SettableFuture.create();
|
||||
if (!installJettyTLSProtocolSelection(sslEngine, completeFuture, false)) {
|
||||
if (!installJettyTlsProtocolSelection(sslEngine, completeFuture, false)) {
|
||||
throw new IllegalStateException("NPN/ALPN extensions not installed");
|
||||
}
|
||||
final ChannelInitializer<Channel> initializer = new ChannelInitializer<Channel>() {
|
||||
|
|
@ -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<Void> protocolNegotiated, boolean server) {
|
||||
for (String protocolNegoClassName : JETTY_TLS_NEGOTIATION_IMPL) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -327,15 +327,14 @@ class NettyClientHandler extends Http2ConnectionHandler {
|
|||
/**
|
||||
* Processes the pending stream creation requests. This considers several conditions:
|
||||
*
|
||||
* <p>
|
||||
* 1) The HTTP/2 connection has exhausted its stream IDs. In this case all pending streams are
|
||||
* <ol>
|
||||
* <li>The HTTP/2 connection has exhausted its stream IDs. In this case all pending streams are
|
||||
* immediately failed.
|
||||
* <p>
|
||||
* 2) The HTTP/2 connection is going away. In this case all pending streams are immediately
|
||||
* <li>The HTTP/2 connection is going away. In this case all pending streams are immediately
|
||||
* failed.
|
||||
* <p>
|
||||
* 3) The HTTP/2 connection's MAX_CONCURRENT_STREAMS limit has been reached. In this case,
|
||||
* <li>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.
|
||||
* </ol>
|
||||
*/
|
||||
private void createPendingStreams() {
|
||||
Http2Connection connection = connection();
|
||||
|
|
|
|||
|
|
@ -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<? extends ServerChannel> 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<? extends ServerChannel> channelType, EventLoopGroup bossGroup,
|
||||
EventLoopGroup workerGroup, @Nullable final SslContext sslContext) {
|
||||
this.address = address;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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<Integer> {
|
||||
|
||||
|
|
|
|||
|
|
@ -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,10 +96,6 @@ 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.
|
||||
|
|
@ -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,22 +169,23 @@ class Utils {
|
|||
|
||||
private static class DefaultEventLoopGroupResource implements Resource<EventLoopGroup> {
|
||||
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<Future<Object>>() {
|
||||
nioEventLoopGroup.terminationFuture().addListener(
|
||||
new GenericFutureListener<Future<Object>>() {
|
||||
@Override
|
||||
public void operationComplete(Future<Object> future) throws Exception {
|
||||
executor.shutdown();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -95,8 +95,9 @@ public abstract class NettyStreamTestBase {
|
|||
|
||||
protected AbstractStream<Integer> stream;
|
||||
|
||||
/** Set up for test. */
|
||||
@Before
|
||||
public void setup() {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mockChannelFuture(true);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<Integer, OkHttpClientStream>();
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -259,7 +259,8 @@ public class Calls {
|
|||
private final Call<?, RespT> call;
|
||||
private final StreamObserver<RespT> observer;
|
||||
|
||||
public StreamObserverToCallListenerAdapter(Call<?, RespT> call, StreamObserver<RespT> observer) {
|
||||
public StreamObserverToCallListenerAdapter(
|
||||
Call<?, RespT> call, StreamObserver<RespT> observer) {
|
||||
this.call = call;
|
||||
this.observer = observer;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public class Method<RequestT, ResponseT> {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue