Skip to content

Commit 03e55fd

Browse files
committed
Fix: formatting
1 parent bfa5a26 commit 03e55fd

6 files changed

Lines changed: 19 additions & 76 deletions

File tree

api/src/main/java/io/grpc/ForwardingChannelBuilder2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public T disableServiceConfigLookUp() {
258258
}
259259

260260
@Override
261-
public T addMetricSink(MetricSink metricSink) {
261+
protected T addMetricSink(MetricSink metricSink) {
262262
delegate().addMetricSink(metricSink);
263263
return thisT();
264264
}

api/src/main/java/io/grpc/ServerBuilder.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,6 @@ public T setBinaryLog(BinaryLog binaryLog) {
424424
throw new UnsupportedOperationException();
425425
}
426426

427-
428-
429-
430-
431427
/**
432428
* Builds a server using the given parameters.
433429
*

core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ public static ManagedChannelBuilder<?> forTarget(String target) {
128128

129129
private static final Method GET_CLIENT_INTERCEPTOR_METHOD;
130130

131-
132-
133131
static {
134132
Method getClientInterceptorMethod = null;
135133
try {
@@ -717,7 +715,7 @@ public ManagedChannelImplBuilder enableCheckAuthority() {
717715
}
718716

719717
@Override
720-
public ManagedChannelImplBuilder addMetricSink(MetricSink metricSink) {
718+
protected ManagedChannelImplBuilder addMetricSink(MetricSink metricSink) {
721719
metricSinks.add(checkNotNull(metricSink, "metric sink"));
722720
return this;
723721
}

rls/src/test/java/io/grpc/rls/RlsLoadBalancerTest.java

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.google.common.base.Preconditions.checkNotNull;
2020
import static com.google.common.truth.Truth.assertThat;
21+
import static org.mockito.AdditionalAnswers.delegatesTo;
2122
import static org.mockito.ArgumentMatchers.any;
2223
import static org.mockito.ArgumentMatchers.anyString;
2324
import static org.mockito.ArgumentMatchers.argThat;
@@ -52,7 +53,6 @@
5253
import io.grpc.LoadBalancer.Subchannel;
5354
import io.grpc.LoadBalancer.SubchannelPicker;
5455
import io.grpc.LoadBalancer.SubchannelStateListener;
55-
import io.grpc.LongCounterMetricInstrument;
5656
import io.grpc.ManagedChannel;
5757
import io.grpc.ManagedChannelBuilder;
5858
import io.grpc.Metadata;
@@ -61,6 +61,7 @@
6161
import io.grpc.MetricInstrument;
6262
import io.grpc.MetricRecorder;
6363
import io.grpc.MetricRecorder.Registration;
64+
import io.grpc.MetricSink;
6465
import io.grpc.NameResolver.ConfigOrError;
6566
import io.grpc.NoopMetricSink;
6667
import io.grpc.ServerCall;
@@ -94,7 +95,6 @@
9495
import java.util.Map;
9596
import java.util.concurrent.ScheduledExecutorService;
9697
import java.util.concurrent.TimeUnit;
97-
import java.util.concurrent.atomic.AtomicBoolean;
9898
import javax.annotation.Nonnull;
9999
import org.junit.After;
100100
import org.junit.Before;
@@ -361,7 +361,7 @@ public void metricsWithRealChannel() throws Exception {
361361
.directExecutor()
362362
.build()
363363
.start());
364-
VerificationMetricSink metrics = new VerificationMetricSink();
364+
MetricSink metrics = mock(MetricSink.class, delegatesTo(new NoopMetricSink()));
365365
ManagedChannel channel = grpcCleanupRule.register(
366366
InternalManagedChannelBuilder.addMetricSink(
367367
InProcessChannelBuilder.forName("fake-bigtable.googleapis.com")
@@ -379,7 +379,12 @@ public void metricsWithRealChannel() throws Exception {
379379
assertThat(recorder.awaitCompletion(10, TimeUnit.SECONDS)).isTrue();
380380
assertThat(recorder.getError()).isNull();
381381

382-
metrics.awaitCall();
382+
verify(metrics).addLongCounter(
383+
eqMetricInstrumentName("grpc.lb.rls.default_target_picks"),
384+
eq(1L),
385+
eq(Arrays.asList("directaddress:///fake-bigtable.googleapis.com", "localhost:8972",
386+
"defaultTarget", "complete")),
387+
eq(Arrays.asList("customvalue")));
383388
}
384389

385390
@Test
@@ -926,34 +931,4 @@ public void registerBackendResponse(boolean throttled) {
926931
}
927932
}
928933

929-
private static final class VerificationMetricSink extends NoopMetricSink {
930-
private final AtomicBoolean called =
931-
new AtomicBoolean();
932-
933-
@Override
934-
public void addLongCounter(
935-
LongCounterMetricInstrument metricInstrument,
936-
long value,
937-
List<String> requiredLabelValues,
938-
List<String> optionalLabelValues) {
939-
if (metricInstrument.getName().equals("grpc.lb.rls.default_target_picks")
940-
&& value == 1L
941-
&& requiredLabelValues.equals(Arrays.asList(
942-
"directaddress:///fake-bigtable.googleapis.com", "localhost:8972",
943-
"defaultTarget", "complete"))
944-
&& optionalLabelValues.equals(Arrays.asList("customvalue"))) {
945-
called.set(true);
946-
}
947-
}
948-
949-
public void awaitCall() throws InterruptedException {
950-
long start = System.currentTimeMillis();
951-
while (!called.get()) {
952-
if (System.currentTimeMillis() - start > 5000) {
953-
throw new AssertionError("Timed out waiting for metric sink call");
954-
}
955-
Thread.sleep(50);
956-
}
957-
}
958-
}
959934
}

xds/src/test/java/io/grpc/xds/FakeControlPlaneXdsOtelIntegrationTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444

4545
/**
4646
* xDS + OpenTelemetry E2E integration test using a fake control plane.
47-
* This class is skipped from Bazel builds because Bazel doesn't compile the
48-
* grpc-opentelemetry module.
4947
*/
5048
@RunWith(Parameterized.class)
5149
public class FakeControlPlaneXdsOtelIntegrationTest {

xds/src/test/java/io/grpc/xds/WeightedRoundRobinLoadBalancerTest.java

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.mockito.ArgumentMatchers.any;
2323
import static org.mockito.ArgumentMatchers.argThat;
2424
import static org.mockito.ArgumentMatchers.eq;
25+
import static org.mockito.Mockito.atLeast;
2526
import static org.mockito.Mockito.mock;
2627
import static org.mockito.Mockito.never;
2728
import static org.mockito.Mockito.reset;
@@ -59,6 +60,7 @@
5960
import io.grpc.LongCounterMetricInstrument;
6061
import io.grpc.Metadata;
6162
import io.grpc.MetricRecorder;
63+
import io.grpc.MetricSink;
6264
import io.grpc.NameResolver;
6365
import io.grpc.NoopMetricSink;
6466
import io.grpc.ServerCall;
@@ -98,7 +100,6 @@
98100
import java.util.concurrent.ConcurrentLinkedQueue;
99101
import java.util.concurrent.CyclicBarrier;
100102
import java.util.concurrent.TimeUnit;
101-
import java.util.concurrent.atomic.AtomicBoolean;
102103
import java.util.concurrent.atomic.AtomicInteger;
103104
import org.junit.Before;
104105
import org.junit.Rule;
@@ -1309,7 +1310,7 @@ public void metricWithRealChannel() throws Exception {
13091310
.directExecutor()
13101311
.build()
13111312
.start());
1312-
VerificationMetricSink metrics = new VerificationMetricSink();
1313+
MetricSink metrics = mock(MetricSink.class, delegatesTo(new NoopMetricSink()));
13131314
Channel channel = grpcCleanupRule.register(
13141315
InternalManagedChannelBuilder.addMetricSink(
13151316
InProcessChannelBuilder.forName(serverName)
@@ -1331,7 +1332,11 @@ public void metricWithRealChannel() throws Exception {
13311332

13321333
// Make sure at least one metric works. The other tests will make sure other metrics and the
13331334
// edge cases are working. Since this is racy, we just care it happened at least once.
1334-
metrics.awaitCall();
1335+
verify(metrics, atLeast(1)).addLongCounter(
1336+
argThat((instr) -> instr.getName().equals("grpc.lb.wrr.rr_fallback")),
1337+
eq(1L),
1338+
eq(Arrays.asList("directaddress:///wrr-metrics")),
1339+
eq(Arrays.asList("", "")));
13351340
}
13361341

13371342

@@ -1714,33 +1719,4 @@ public String getChannelTarget() {
17141719
return channelTarget;
17151720
}
17161721
}
1717-
1718-
private static final class VerificationMetricSink extends NoopMetricSink {
1719-
private final AtomicBoolean called =
1720-
new AtomicBoolean();
1721-
1722-
@Override
1723-
public void addLongCounter(
1724-
LongCounterMetricInstrument metricInstrument,
1725-
long value,
1726-
List<String> requiredLabelValues,
1727-
List<String> optionalLabelValues) {
1728-
if (metricInstrument.getName().equals("grpc.lb.wrr.rr_fallback")
1729-
&& value == 1L
1730-
&& requiredLabelValues.equals(Arrays.asList("directaddress:///wrr-metrics"))
1731-
&& optionalLabelValues.equals(Arrays.asList("", ""))) {
1732-
called.set(true);
1733-
}
1734-
}
1735-
1736-
public void awaitCall() throws InterruptedException {
1737-
long start = System.currentTimeMillis();
1738-
while (!called.get()) {
1739-
if (System.currentTimeMillis() - start > 5000) {
1740-
throw new AssertionError("Timed out waiting for metric sink call");
1741-
}
1742-
Thread.sleep(50);
1743-
}
1744-
}
1745-
}
17461722
}

0 commit comments

Comments
 (0)