Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#noissue] Cleanup #11203

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.mapstruct.factory.Mappers;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;

Expand All @@ -53,6 +52,8 @@ class MetadataGrpcDataSenderTest {
private static final String UNKNOWN_METADATA = "status code UNKNOWN";
private static final String FAIL_METADATA = "success=false";

private static final Context.Key<Metadata> GRPC_METADATA_CONTEXT_KEY = Context.key("test-grpc-metadata");

private static final Metadata.Key<String> TEST_ID_KEY = Metadata.Key.of("test-id", Metadata.ASCII_STRING_MARSHALLER);
private static final Metadata.Key<String> GRPC_PREVIOUS_RPC_ATTEMPTS_KEY = Metadata.Key.of("grpc-previous-rpc-attempts", Metadata.ASCII_STRING_MARSHALLER);

Expand Down Expand Up @@ -97,7 +98,8 @@ public void resetCounter() {
public static class MetadataGrpcService extends MetadataGrpc.MetadataImplBase {
@Override
public void requestApiMetaData(PApiMetaData request, StreamObserver<PResult> responseObserver) {
System.out.println(request);
countAndPrint(request);

switch (request.getApiInfo()) {
case DELAY_METADATA:
try {
Expand Down Expand Up @@ -127,29 +129,33 @@ public void requestApiMetaData(PApiMetaData request, StreamObserver<PResult> res
break;
}
}
}

public static class TestServerInterceptor implements ServerInterceptor {
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> serverCall, Metadata metadata, ServerCallHandler<ReqT, RespT> serverCallHandler) {
private void countAndPrint(PApiMetaData request) {
int totalAttempts = -1;
String callTestId = metadata.get(TEST_ID_KEY);
if (callTestId != null && callTestId.equals(Integer.toString(testId))) {
requestCounter++;
Metadata metadata = GRPC_METADATA_CONTEXT_KEY.get(Context.current());
String requestTestId = metadata.get(TEST_ID_KEY);
String previousAttempts = metadata.get(GRPC_PREVIOUS_RPC_ATTEMPTS_KEY);

String previousAttempts = metadata.get(GRPC_PREVIOUS_RPC_ATTEMPTS_KEY);
if (requestTestId != null && requestTestId.equals(Integer.toString(testId))) {
requestCounter++;
if (previousAttempts == null) {
totalAttempts = 1;
} else {
totalAttempts = Integer.parseInt(previousAttempts) + 1;
}
//Assertions.assertThat(requestCounter).isEqualTo(totalAttempts);
}

System.out.println("---- server time: " + new Timestamp(System.currentTimeMillis()));
System.out.println("testId: " + callTestId);
System.out.println("testId: " + requestTestId);
System.out.println("total attempts: " + totalAttempts);
return Contexts.interceptCall(Context.current(), serverCall, metadata, serverCallHandler);
System.out.println(request);
}
}

public static class TestServerInterceptor implements ServerInterceptor {
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> serverCall, Metadata metadata, ServerCallHandler<ReqT, RespT> serverCallHandler) {
Context newContext = Context.current().withValue(GRPC_METADATA_CONTEXT_KEY, metadata);
return Contexts.interceptCall(newContext, serverCall, metadata, serverCallHandler);
}
}

Expand Down Expand Up @@ -294,11 +300,6 @@ public void start(Listener<RespT> responseListener, Metadata headers) {
private HedgingServiceConfigBuilder getTestServiceConfigBuilder() {
HedgingServiceConfigBuilder serviceConfigBuilder = new HedgingServiceConfigBuilder();
serviceConfigBuilder.setHedgingDelayMillis(DEFAULT_TEST_HEDGING_DELAY_MILLIS);
serviceConfigBuilder.setNonFatalStatusCodes(Arrays.asList(
Status.Code.UNKNOWN.name(),
Status.Code.INTERNAL.name(),
Status.Code.UNAVAILABLE.name()
));
return serviceConfigBuilder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class HedgingServiceConfigBuilder implements ServiceConfigBuilder {
public static final long DEFAULT_HEDGING_DELAY_MILLIS = 1000L;
public static final List<String> DEFAULT_STATUS_CODES = Arrays.asList(
Status.Code.UNKNOWN.name(),
Status.Code.INTERNAL.name(),
Status.Code.UNAVAILABLE.name()
);

Expand Down