services: fix lint warnings on binlog (#3927)

This commit is contained in:
zpencer 2018-01-09 12:08:58 -08:00 committed by GitHub
parent 2fb5d53d1b
commit c96ce4de20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 18 deletions

View File

@ -19,6 +19,7 @@ package io.grpc.services;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.primitives.Bytes;
import com.google.protobuf.ByteString;
import io.grpc.InternalMetadata;
@ -145,8 +146,7 @@ final class BinaryLog {
Map<String, BinaryLog> perServiceLogs = new HashMap<String, BinaryLog>();
Map<String, BinaryLog> perMethodLogs = new HashMap<String, BinaryLog>();
String[] configurations = configurationString.split(",");
for (String configuration : configurations) {
for (String configuration : Splitter.on(',').split(configurationString)) {
Matcher configMatcher = configRe.matcher(configuration);
if (!configMatcher.matches()) {
throw new IllegalArgumentException("Bad input: " + configuration);
@ -273,7 +273,8 @@ final class BinaryLog {
// TODO(zpencer): verify int64 representation with other gRPC languages
static Uint128 callIdToProto(byte[] bytes) {
Preconditions.checkArgument(
bytes.length == 16, "can only convert from 16 byte input, actual length =" + bytes.length);
bytes.length == 16,
String.format("can only convert from 16 byte input, actual length = %d", bytes.length));
ByteBuffer bb = ByteBuffer.wrap(bytes);
long high = bb.getLong();
long low = bb.getLong();

View File

@ -54,9 +54,9 @@ public final class BinaryLogTest {
private static final BinaryLog BOTH_FULL =
new Builder().header(Integer.MAX_VALUE).msg(Integer.MAX_VALUE).build();
private static final String dataA = "aaaaaaaaa";
private static final String dataB = "bbbbbbbbb";
private static final String dataC = "ccccccccc";
private static final String DATA_A = "aaaaaaaaa";
private static final String DATA_B = "bbbbbbbbb";
private static final String DATA_C = "ccccccccc";
private static final Metadata.Key<String> KEY_A =
Metadata.Key.of("a", Metadata.ASCII_STRING_MARSHALLER);
private static final Metadata.Key<String> KEY_B =
@ -67,19 +67,19 @@ public final class BinaryLogTest {
MetadataEntry
.newBuilder()
.setKey(ByteString.copyFrom(KEY_A.name(), US_ASCII))
.setValue(ByteString.copyFrom(dataA.getBytes(US_ASCII)))
.setValue(ByteString.copyFrom(DATA_A.getBytes(US_ASCII)))
.build();
private static final MetadataEntry ENTRY_B =
MetadataEntry
.newBuilder()
.setKey(ByteString.copyFrom(KEY_B.name(), US_ASCII))
.setValue(ByteString.copyFrom(dataB.getBytes(US_ASCII)))
.setValue(ByteString.copyFrom(DATA_B.getBytes(US_ASCII)))
.build();
private static final MetadataEntry ENTRY_C =
MetadataEntry
.newBuilder()
.setKey(ByteString.copyFrom(KEY_C.name(), US_ASCII))
.setValue(ByteString.copyFrom(dataC.getBytes(US_ASCII)))
.setValue(ByteString.copyFrom(DATA_C.getBytes(US_ASCII)))
.build();
private static final boolean IS_COMPRESSED = true;
private static final boolean IS_UNCOMPRESSED = false;
@ -88,9 +88,9 @@ public final class BinaryLogTest {
@Before
public void setUp() throws Exception {
metadata.put(KEY_A, dataA);
metadata.put(KEY_B, dataB);
metadata.put(KEY_C, dataC);
metadata.put(KEY_A, DATA_A);
metadata.put(KEY_B, DATA_B);
metadata.put(KEY_C, DATA_C);
}
@Test
@ -373,15 +373,11 @@ public final class BinaryLogTest {
public void metadataToProto_truncated() throws Exception {
// 0 byte limit not enough for any metadata
assertEquals(
io.grpc.binarylog.Metadata
.newBuilder()
.build(),
io.grpc.binarylog.Metadata.getDefaultInstance(),
BinaryLog.metadataToProto(metadata, 0));
// not enough bytes for first key value
assertEquals(
io.grpc.binarylog.Metadata
.newBuilder()
.build(),
io.grpc.binarylog.Metadata.getDefaultInstance(),
BinaryLog.metadataToProto(metadata, 9));
// enough for first key value
assertEquals(