Skip to content

Commit 7c48fc2

Browse files
chore: Added spotless and explicit toString() impls (#33)
1 parent 2881279 commit 7c48fc2

File tree

19 files changed

+266
-169
lines changed

19 files changed

+266
-169
lines changed

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
id("org.hypertrace.ci-utils-plugin") version "0.3.0"
77
id("org.hypertrace.publish-plugin") version "1.0.2" apply false
88
id("org.hypertrace.jacoco-report-plugin") version "0.2.0" apply false
9+
id("org.hypertrace.code-style-plugin") version "1.1.2" apply false
910
}
1011

1112
subprojects {
@@ -22,4 +23,6 @@ subprojects {
2223
targetCompatibility = JavaVersion.VERSION_11
2324
}
2425
}
26+
27+
apply(plugin = "org.hypertrace.code-style-plugin")
2528
}

grpc-client-rx-utils/src/main/java/org/hypertrace/core/grpcutils/client/rx/GrpcRxExecutionContext.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@ public interface GrpcRxExecutionContext {
1818
*/
1919
<TResp> Single<TResp> call(Callable<TResp> callable);
2020

21-
/**
22-
* Creates the provided single in this execution context, returning the result.
23-
*/
21+
/** Creates the provided single in this execution context, returning the result. */
2422
<TResp> Single<TResp> wrapSingle(Supplier<Single<TResp>> singleSupplier);
2523

26-
/**
27-
* Creates the provided maybe in this execution context, returning the result.
28-
*/
24+
/** Creates the provided maybe in this execution context, returning the result. */
2925
<TResp> Maybe<TResp> wrapMaybe(Supplier<Maybe<TResp>> maybeSupplier);
3026

3127
/**

grpc-client-rx-utils/src/main/java/org/hypertrace/core/grpcutils/client/rx/StreamingClientResponseObserver.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66

77
/**
88
* Adapter class for bridging from a GRPC stream to an Rx Observable.
9+
*
910
* @param <ReqT>
1011
* @param <RespT>
1112
*/
12-
public class StreamingClientResponseObserver<ReqT, RespT> implements ClientResponseObserver<ReqT, RespT> {
13+
public class StreamingClientResponseObserver<ReqT, RespT>
14+
implements ClientResponseObserver<ReqT, RespT> {
1315

1416
private final ObservableEmitter<RespT> emitter;
1517
private ClientCallStreamObserver<ReqT> requestStream;
@@ -18,7 +20,7 @@ public class StreamingClientResponseObserver<ReqT, RespT> implements ClientRespo
1820
this.emitter = emitter;
1921
this.emitter.setCancellable(
2022
() ->
21-
this.requestStream.cancel(
23+
this.requestStream.cancel(
2224
"StreamingClientResponseObserver cancelling after emitter disposed", null));
2325
}
2426

grpc-client-utils/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
###### org.hypertrace.core.grpcutils:grpc-client-utils
33

44
This module contains some common classes that are used across all the Platform
5-
GRPC clients.
5+
GRPC clients.

grpc-client-utils/src/main/java/org/hypertrace/core/grpcutils/client/ContextKeyBasedCreds.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public ContextKeyBasedCreds(Context.Key<RequestContext> contextKey) {
1313
}
1414

1515
@Override
16-
public void applyRequestMetadata(RequestInfo requestInfo, Executor appExecutor,
17-
MetadataApplier applier) {
16+
public void applyRequestMetadata(
17+
RequestInfo requestInfo, Executor appExecutor, MetadataApplier applier) {
1818
try {
1919
applyRequestContext(applier, contextKey.get());
2020
} catch (RuntimeException e) {

grpc-client-utils/src/main/java/org/hypertrace/core/grpcutils/client/RequestContextAsCreds.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.hypertrace.core.grpcutils.client;
22

3+
import static io.grpc.Metadata.ASCII_STRING_MARSHALLER;
4+
import static io.grpc.Metadata.BINARY_BYTE_MARSHALLER;
5+
36
import io.grpc.CallCredentials;
47
import io.grpc.Metadata;
58
import io.grpc.Status;
@@ -8,20 +11,16 @@
811
import org.slf4j.Logger;
912
import org.slf4j.LoggerFactory;
1013

11-
import static io.grpc.Metadata.ASCII_STRING_MARSHALLER;
12-
import static io.grpc.Metadata.BINARY_BYTE_MARSHALLER;
13-
1414
public abstract class RequestContextAsCreds extends CallCredentials {
1515
private static Logger LOGGER = LoggerFactory.getLogger(RequestContextAsCreds.class);
1616

1717
@Override
18-
public void thisUsesUnstableApi() {
19-
}
18+
public void thisUsesUnstableApi() {}
2019

2120
/**
22-
* Adds the request headers in the request context to a Metadata object to be propagated in the client call. All the
23-
* headers are propagated so if any headers should be exempted from propagation, that should be handled separately
24-
* before this call is made.
21+
* Adds the request headers in the request context to a Metadata object to be propagated in the
22+
* client call. All the headers are propagated so if any headers should be exempted from
23+
* propagation, that should be handled separately before this call is made.
2524
*
2625
* @param applier
2726
* @param requestContext
@@ -34,9 +33,12 @@ protected void applyRequestContext(MetadataApplier applier, RequestContext reque
3433
if (entry.getValue() != null) {
3534
String key = entry.getKey();
3635
if (key.toLowerCase().endsWith(Metadata.BINARY_HEADER_SUFFIX)) {
37-
metadata.put(Metadata.Key.of(entry.getKey(), BINARY_BYTE_MARSHALLER), entry.getValue().getBytes());
36+
metadata.put(
37+
Metadata.Key.of(entry.getKey(), BINARY_BYTE_MARSHALLER),
38+
entry.getValue().getBytes());
3839
} else {
39-
metadata.put(Metadata.Key.of(entry.getKey(), ASCII_STRING_MARSHALLER), entry.getValue());
40+
metadata.put(
41+
Metadata.Key.of(entry.getKey(), ASCII_STRING_MARSHALLER), entry.getValue());
4042
}
4143
}
4244
}

grpc-client-utils/src/main/java/org/hypertrace/core/grpcutils/client/RequestContextClientCallCredsProviderFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import org.hypertrace.core.grpcutils.context.RequestContext;
55

66
public class RequestContextClientCallCredsProviderFactory {
7-
private static class DefaultRequestContextClientCallCredsProvider implements ClientCallCredentialsProvider {
7+
private static class DefaultRequestContextClientCallCredsProvider
8+
implements ClientCallCredentialsProvider {
89
private final ContextKeyBasedCreds credsProvider;
910

1011
public DefaultRequestContextClientCallCredsProvider() {
Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.hypertrace.core.grpcutils.client;
22

3+
import static org.mockito.Mockito.mock;
4+
35
import io.grpc.CallCredentials;
46
import io.grpc.Context;
57
import io.grpc.Metadata;
@@ -12,16 +14,14 @@
1214
import org.junit.jupiter.api.Assertions;
1315
import org.junit.jupiter.api.Test;
1416

15-
import static io.grpc.Metadata.BINARY_BYTE_MARSHALLER;
16-
import static org.mockito.Mockito.mock;
17-
1817
public class ContextKeyBasedCredsTest {
1918
private static final String TENANT_ID = "test-tenant-id";
2019
private static final String TEST_AUTH_HEADER = "test-auth-header";
2120

2221
@Test
2322
public void testApplyRequestMetadata_shouldApplyAllHeaders() {
24-
CallCredentials callCredentials = RequestContextClientCallCredsProviderFactory.getClientCallCredsProvider().get();
23+
CallCredentials callCredentials =
24+
RequestContextClientCallCredsProviderFactory.getClientCallCredsProvider().get();
2525

2626
Assertions.assertTrue(callCredentials instanceof ContextKeyBasedCreds);
2727

@@ -32,45 +32,57 @@ public void testApplyRequestMetadata_shouldApplyAllHeaders() {
3232
requestContext.add("x-some-tenant-header", "v1");
3333
requestContext.add("grpc-trace-bin", "AAARf5ZpQwlN/8FVe1axOPlaAQIdRU/Y8j0LAgE");
3434

35-
3635
Context ctx = Context.current().withValue(RequestContext.CURRENT, requestContext);
3736

3837
Context previous = ctx.attach();
3938
try {
40-
callCredentials.applyRequestMetadata(mock(CallCredentials.RequestInfo.class), mock(Executor.class), new CallCredentials.MetadataApplier() {
41-
@Override
42-
public void apply(Metadata headers) {
43-
Map<String, String> headersMap = headers.keys().stream()
44-
.collect(Collectors.toUnmodifiableMap(k -> k, k -> {
45-
String value;
46-
if (k.toLowerCase().endsWith(Metadata.BINARY_HEADER_SUFFIX)) {
47-
value = new String(headers.get(Metadata.Key.of(k, Metadata.BINARY_BYTE_MARSHALLER)));
48-
} else {
49-
value = headers.get(Metadata.Key.of(k, Metadata.ASCII_STRING_MARSHALLER));
50-
}
51-
return value;
52-
} ));
39+
callCredentials.applyRequestMetadata(
40+
mock(CallCredentials.RequestInfo.class),
41+
mock(Executor.class),
42+
new CallCredentials.MetadataApplier() {
43+
@Override
44+
public void apply(Metadata headers) {
45+
Map<String, String> headersMap =
46+
headers.keys().stream()
47+
.collect(
48+
Collectors.toUnmodifiableMap(
49+
k -> k,
50+
k -> {
51+
String value;
52+
if (k.toLowerCase().endsWith(Metadata.BINARY_HEADER_SUFFIX)) {
53+
value =
54+
new String(
55+
headers.get(
56+
Metadata.Key.of(k, Metadata.BINARY_BYTE_MARSHALLER)));
57+
} else {
58+
value =
59+
headers.get(
60+
Metadata.Key.of(k, Metadata.ASCII_STRING_MARSHALLER));
61+
}
62+
return value;
63+
}));
5364

54-
// Should filter out the TENANT_ID_HEADER_KEY
55-
Assertions.assertEquals(
56-
Map.of(
57-
RequestContextConstants.TENANT_ID_HEADER_KEY, TENANT_ID,
58-
RequestContextConstants.AUTHORIZATION_HEADER, TEST_AUTH_HEADER,
59-
"x-some-tenant-header", "v1",
60-
"grpc-trace-bin", "AAARf5ZpQwlN/8FVe1axOPlaAQIdRU/Y8j0LAgE"
61-
),
62-
headersMap);
63-
}
65+
// Should filter out the TENANT_ID_HEADER_KEY
66+
Assertions.assertEquals(
67+
Map.of(
68+
RequestContextConstants.TENANT_ID_HEADER_KEY,
69+
TENANT_ID,
70+
RequestContextConstants.AUTHORIZATION_HEADER,
71+
TEST_AUTH_HEADER,
72+
"x-some-tenant-header",
73+
"v1",
74+
"grpc-trace-bin",
75+
"AAARf5ZpQwlN/8FVe1axOPlaAQIdRU/Y8j0LAgE"),
76+
headersMap);
77+
}
6478

65-
@Override
66-
public void fail(Status status) {
67-
Assertions.fail("Failed in CallCredentials.MetadataApplier");
68-
}
69-
});
79+
@Override
80+
public void fail(Status status) {
81+
Assertions.fail("Failed in CallCredentials.MetadataApplier");
82+
}
83+
});
7084
} finally {
7185
ctx.detach(previous);
7286
}
7387
}
74-
75-
7688
}

grpc-client-utils/src/test/java/org/hypertrace/core/grpcutils/client/GrpcChannelRegistryTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import io.grpc.Deadline.Ticker;
1717
import io.grpc.ManagedChannel;
1818
import io.grpc.ManagedChannelBuilder;
19-
import java.util.Map;
2019
import java.util.concurrent.TimeUnit;
2120
import org.junit.jupiter.api.BeforeEach;
2221
import org.junit.jupiter.api.Test;

0 commit comments

Comments
 (0)