Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Oct 4, 2024
1 parent 9179a0a commit 3734387
Showing 1 changed file with 22 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,11 @@
import com.google.protobuf.ByteString;
import com.google.protobuf.BytesValue;
import com.google.protobuf.StringValue;
import io.grpc.CallOptions;
import io.grpc.Channel;
import io.grpc.ClientCall;
import io.grpc.ClientInterceptor;
import io.grpc.ForwardingClientCall;
import io.grpc.ForwardingServerCall;
import io.grpc.ManagedChannelBuilder;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.ProxiedSocketAddress;
import io.grpc.ProxyDetector;
import io.grpc.Server;
import io.grpc.ServerCall;
import io.grpc.ServerCallHandler;
Expand All @@ -95,6 +91,8 @@
import io.opentelemetry.sdk.metrics.View;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import java.io.IOException;
import java.net.SocketAddress;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -104,6 +102,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -130,7 +129,7 @@ public class BuiltinMetricsTracerTest {
private static final long SLEEP_VARIABILITY = 15;
private static final String CLIENT_NAME = "java-bigtable/" + Version.VERSION;

private static final long CHANNEL_BLOCKING_LATENCY = 75;
private static final long CHANNEL_BLOCKING_LATENCY = 200;

@Rule public final MockitoRule mockitoRule = MockitoJUnit.rule();

Expand Down Expand Up @@ -196,35 +195,14 @@ public void sendHeaders(Metadata headers) {
}
};

ClientInterceptor clientInterceptor =
new ClientInterceptor() {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
MethodDescriptor<ReqT, RespT> methodDescriptor,
CallOptions callOptions,
Channel channel) {
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
channel.newCall(methodDescriptor, callOptions)) {
@Override
public void sendMessage(ReqT message) {
try {
Thread.sleep(CHANNEL_BLOCKING_LATENCY);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
super.sendMessage(message);
}
};
}
};

server = FakeServiceBuilder.create(fakeService).intercept(trailersInterceptor).start();

BigtableDataSettings settings =
BigtableDataSettings.newBuilderForEmulator(server.getPort())
.setProjectId(PROJECT_ID)
.setInstanceId(INSTANCE_ID)
.setAppProfileId(APP_PROFILE_ID)
.setRefreshingChannel(false)
.build();
EnhancedBigtableStubSettings.Builder stubSettingsBuilder =
settings.getStubSettings().toBuilder();
Expand Down Expand Up @@ -264,7 +242,7 @@ public void sendMessage(ReqT message) {
if (oldConfigurator != null) {
builder = oldConfigurator.apply(builder);
}
return builder.intercept(clientInterceptor);
return builder.proxyDetector(new DelayProxyDetector());
});
stubSettingsBuilder.setTransportChannelProvider(channelProvider.build());

Expand Down Expand Up @@ -837,4 +815,18 @@ public AtomicInteger getResponseCounter() {
return responseCounter;
}
}

class DelayProxyDetector implements ProxyDetector {

@Nullable
@Override
public ProxiedSocketAddress proxyFor(SocketAddress socketAddress) throws IOException {
try {
Thread.sleep(CHANNEL_BLOCKING_LATENCY);
} catch (InterruptedException e) {

}
return null;
}
}
}

0 comments on commit 3734387

Please sign in to comment.