Skip to content

Commit c3e8dae

Browse files
committed
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.
1 parent c5bcbc6 commit c3e8dae

File tree

61 files changed

+465
-522
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+465
-522
lines changed

auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ public class ClientAuthInterceptorTests {
6161

6262
ClientAuthInterceptor interceptor;
6363

64+
/** Set up for test. */
6465
@Before
65-
public void startup() throws IOException {
66+
public void startUp() throws IOException {
6667
MockitoAnnotations.initMocks(this);
6768
when(channel.newCall(descriptor)).thenReturn(call);
6869
interceptor = new ClientAuthInterceptor(credentials,

benchmarks/src/main/java/io/grpc/benchmarks/qps/QpsClient.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131

3232
package io.grpc.benchmarks.qps;
3333

34-
import static grpc.testing.TestServiceGrpc.TestServiceStub;
3534
import static grpc.testing.Qpstest.SimpleRequest;
3635
import static grpc.testing.Qpstest.SimpleResponse;
37-
import static java.lang.Math.max;
36+
import static grpc.testing.TestServiceGrpc.TestServiceStub;
3837
import static io.grpc.testing.integration.Util.loadCert;
38+
import static java.lang.Math.max;
3939

4040
import com.google.common.base.Preconditions;
4141
import com.google.common.util.concurrent.MoreExecutors;
@@ -63,8 +63,8 @@
6363
import java.util.concurrent.CancellationException;
6464
import java.util.concurrent.ExecutionException;
6565
import java.util.concurrent.Future;
66-
import java.util.concurrent.TimeUnit;
6766
import java.util.concurrent.TimeoutException;
67+
import java.util.concurrent.TimeUnit;
6868
import java.util.logging.Logger;
6969

7070
/**
@@ -96,6 +96,7 @@ public static void main(String... args) throws Exception {
9696
new QpsClient().run(args);
9797
}
9898

99+
/** Equivalent of "main", but non-static. */
99100
public void run(String[] args) throws Exception {
100101
if (!parseArgs(args)) {
101102
return;
@@ -161,11 +162,11 @@ private Channel newChannel() throws IOException {
161162
InetAddress address = InetAddress.getByName(serverHost);
162163
NegotiationType negotiationType = enableTls ? NegotiationType.TLS : NegotiationType.PLAINTEXT;
163164
if (enableTls && useTestCa) {
164-
// Force the hostname to match the cert the server uses.
165-
address = InetAddress.getByAddress("foo.test.google.fr", address.getAddress());
166-
File cert = loadCert("ca.pem");
167-
context = SslContext.newClientContext(cert);
168-
}
165+
// Force the hostname to match the cert the server uses.
166+
address = InetAddress.getByAddress("foo.test.google.fr", address.getAddress());
167+
File cert = loadCert("ca.pem");
168+
context = SslContext.newClientContext(cert);
169+
}
169170

170171
return NettyChannelBuilder.forAddress(new InetSocketAddress(address, serverPort))
171172
.negotiationType(negotiationType)
@@ -254,21 +255,21 @@ private int parseDuration(String value) {
254255
private void printUsage() {
255256
QpsClient c = new QpsClient();
256257
System.out.println(
257-
"Usage: [ARGS...]"
258-
+ "\n"
259-
+ "\n --server_port=INT Port of the server. Required. No default."
260-
+ "\n --server_host=STR Hostname of the server. Default " + c.serverHost
261-
+ "\n --client_channels=INT Number of client channels. Default " + c.clientChannels
262-
+ "\n --concurrent_calls=INT Number of concurrent calls. Default " + c.concurrentCalls
263-
+ "\n --payload_size=INT Payload size in bytes. Default " + c.payloadSize
264-
+ "\n --enable_tls Enable TLS. Default disabled."
265-
+ "\n --use_testca Use the provided test certificate for TLS."
266-
+ "\n --okhttp Use OkHttp as the transport. Default netty"
267-
+ "\n --duration=TIME Duration of the benchmark in either seconds or minutes."
268-
+ "\n For N seconds duration specify Ns and for minutes Nm. "
269-
+ "\n Default " + c.duration + "s."
270-
+ "\n --warmup_duration=TIME How long to run the warmup."
271-
+ "\n Default " + c.warmupDuration + "s."
258+
"Usage: [ARGS...]"
259+
+ "\n"
260+
+ "\n --server_port=INT Port of the server. Required. No default."
261+
+ "\n --server_host=STR Hostname of the server. Default " + c.serverHost
262+
+ "\n --client_channels=INT Number of client channels. Default " + c.clientChannels
263+
+ "\n --concurrent_calls=INT Number of concurrent calls. Default " + c.concurrentCalls
264+
+ "\n --payload_size=INT Payload size in bytes. Default " + c.payloadSize
265+
+ "\n --enable_tls Enable TLS. Default disabled."
266+
+ "\n --use_testca Use the provided test certificate for TLS."
267+
+ "\n --okhttp Use OkHttp as the transport. Default netty"
268+
+ "\n --duration=TIME Duration of the benchmark in either seconds or minutes."
269+
+ "\n For N seconds duration specify Ns and for minutes Nm. "
270+
+ "\n Default " + c.duration + "s."
271+
+ "\n --warmup_duration=TIME How long to run the warmup."
272+
+ "\n Default " + c.warmupDuration + "s."
272273
);
273274
}
274275

@@ -288,13 +289,13 @@ public void onValue(SimpleResponse value) {
288289
int actualSize = value.getPayload().getBody().size();
289290

290291
if (!PayloadType.COMPRESSABLE.equals(type)) {
291-
throw new RuntimeException("type was '" + type + "', expected '" +
292-
PayloadType.COMPRESSABLE + "'.");
292+
throw new RuntimeException("type was '" + type + "', expected '"
293+
+ PayloadType.COMPRESSABLE + "'.");
293294
}
294295

295296
if (payloadSize != actualSize) {
296-
throw new RuntimeException("size was '" + actualSize + "', expected '" +
297-
payloadSize + "'");
297+
throw new RuntimeException("size was '" + actualSize + "', expected '"
298+
+ payloadSize + "'");
298299
}
299300
}
300301

@@ -336,7 +337,7 @@ private Histogram merge(List<Histogram> histograms) {
336337
}
337338

338339
private void printStats(Histogram histogram, long elapsedTime) {
339-
double percentiles[] = {50, 90, 95, 99, 99.9, 99.99};
340+
double[] percentiles = {50, 90, 95, 99, 99.9, 99.99};
340341

341342
// Generate a comma-separated string of percentiles
342343
StringBuilder header = new StringBuilder();

benchmarks/src/main/java/io/grpc/benchmarks/qps/QpsServer.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@
3131

3232
package io.grpc.benchmarks.qps;
3333

34-
import static grpc.testing.Qpstest.StatsRequest;
35-
import static grpc.testing.Qpstest.ServerStats;
3634
import static grpc.testing.Qpstest.Latencies;
37-
import static grpc.testing.Qpstest.StartArgs;
3835
import static grpc.testing.Qpstest.Payload;
3936
import static grpc.testing.Qpstest.PayloadType;
40-
import static grpc.testing.Qpstest.SimpleResponse;
37+
import static grpc.testing.Qpstest.ServerStats;
4138
import static grpc.testing.Qpstest.SimpleRequest;
42-
import static grpc.testing.Qpstest.StreamingInputCallResponse;
43-
import static grpc.testing.Qpstest.StreamingOutputCallResponse;
39+
import static grpc.testing.Qpstest.SimpleResponse;
40+
import static grpc.testing.Qpstest.StartArgs;
41+
import static grpc.testing.Qpstest.StatsRequest;
4442
import static grpc.testing.Qpstest.StreamingInputCallRequest;
43+
import static grpc.testing.Qpstest.StreamingInputCallResponse;
4544
import static grpc.testing.Qpstest.StreamingOutputCallRequest;
46-
import static java.lang.Math.max;
45+
import static grpc.testing.Qpstest.StreamingOutputCallResponse;
4746
import static io.grpc.testing.integration.Util.loadCert;
4847
import static io.grpc.testing.integration.Util.pickUnusedPort;
48+
import static java.lang.Math.max;
4949

5050
import com.google.common.util.concurrent.MoreExecutors;
5151
import com.google.protobuf.ByteString;
@@ -65,20 +65,21 @@
6565

6666
public class QpsServer {
6767

68-
private boolean enable_tls;
68+
private boolean enableTls;
6969
private int port = 0;
7070

7171
public static void main(String... args) throws Exception {
7272
new QpsServer().run(args);
7373
}
7474

75+
/** Equivalent of "main", but non-static. */
7576
public void run(String[] args) throws Exception {
7677
if (!parseArgs(args)) {
7778
return;
7879
}
7980

8081
SslContext sslContext = null;
81-
if (enable_tls) {
82+
if (enableTls) {
8283
System.out.println("Using fake CA for TLS certificate.\n"
8384
+ "Run the Java client with --enable_tls --use_testca");
8485

@@ -136,7 +137,7 @@ private boolean parseArgs(String[] args) {
136137
} else if ("port".equals(key)) {
137138
port = Integer.parseInt(value);
138139
} else if ("enable_tls".equals(key)) {
139-
enable_tls = true;
140+
enableTls = true;
140141
} else {
141142
System.err.println("Unrecognized argument '" + key + "'.");
142143
}
@@ -215,20 +216,20 @@ public void streamingOutputCall(StreamingOutputCallRequest request,
215216
}
216217

217218
@Override
218-
public StreamObserver<StreamingInputCallRequest>
219-
streamingInputCall(StreamObserver<StreamingInputCallResponse> responseObserver) {
219+
public StreamObserver<StreamingInputCallRequest> streamingInputCall(
220+
StreamObserver<StreamingInputCallResponse> responseObserver) {
220221
throw Status.UNIMPLEMENTED.asRuntimeException();
221222
}
222223

223224
@Override
224-
public StreamObserver<StreamingOutputCallRequest>
225-
fullDuplexCall(StreamObserver<StreamingOutputCallResponse> responseObserver) {
225+
public StreamObserver<StreamingOutputCallRequest> fullDuplexCall(
226+
StreamObserver<StreamingOutputCallResponse> responseObserver) {
226227
throw Status.UNIMPLEMENTED.asRuntimeException();
227228
}
228229

229230
@Override
230-
public StreamObserver<StreamingOutputCallRequest>
231-
halfDuplexCall(StreamObserver<StreamingOutputCallResponse> responseObserver) {
231+
public StreamObserver<StreamingOutputCallRequest> halfDuplexCall(
232+
StreamObserver<StreamingOutputCallResponse> responseObserver) {
232233
throw Status.UNIMPLEMENTED.asRuntimeException();
233234
}
234235
}

build.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import org.apache.tools.ant.taskdefs.condition.Os
22

33
subprojects {
4+
apply plugin: "checkstyle"
45
apply plugin: "java"
56
apply plugin: "maven"
67
apply plugin: "idea"
@@ -87,6 +88,21 @@ subprojects {
8788
}
8889
}
8990

91+
checkstyle {
92+
configFile = file("$rootDir/checkstyle.xml")
93+
toolVersion = "6.2"
94+
}
95+
96+
checkstyleMain {
97+
source = fileTree(dir: "src", include: "**/*.java",
98+
excludes: ["${buildDir}/generated-sources", "**/TestServiceGrpc.java"])
99+
}
100+
101+
checkstyleTest {
102+
source = fileTree(dir: "test", include: "**/*.java",
103+
exclude: "${buildDir}/generated-sources")
104+
}
105+
90106
task javadocJar(type: Jar) {
91107
classifier = 'javadoc'
92108
from javadoc

0 commit comments

Comments
 (0)