use of io.grpc.testing.integration.Messages.GrpclbRouteType in project grpc-java by grpc.
the class GrpclbFallbackTestClient method waitForFallbackAndDoRpcs.
private void waitForFallbackAndDoRpcs(Deadline fallbackDeadline) throws Exception {
int fallbackRetryCount = 0;
boolean fallBack = false;
while (!fallbackDeadline.isExpired()) {
GrpclbRouteType grpclbRouteType = doRpcAndGetPath(Deadline.after(1, TimeUnit.SECONDS));
if (grpclbRouteType == GrpclbRouteType.GRPCLB_ROUTE_TYPE_BACKEND) {
throw new AssertionError("Got grpclb route type backend. Backends are " + "supposed to be unreachable, so this test is broken");
}
if (grpclbRouteType == GrpclbRouteType.GRPCLB_ROUTE_TYPE_FALLBACK) {
logger.info("Made one successful RPC to a fallback. Now expect the " + "same for the rest.");
fallBack = true;
break;
} else {
logger.info("Retryable RPC failure on iteration: " + fallbackRetryCount);
}
fallbackRetryCount++;
}
if (!fallBack) {
throw new AssertionError("Didn't fall back within deadline");
}
for (int i = 0; i < 30; i++) {
assertEquals(GrpclbRouteType.GRPCLB_ROUTE_TYPE_FALLBACK, doRpcAndGetPath(Deadline.after(20, TimeUnit.SECONDS)));
Thread.sleep(1000);
}
}
use of io.grpc.testing.integration.Messages.GrpclbRouteType in project grpc-java by grpc.
the class GrpclbFallbackTestClient method doRpcAndGetPath.
private GrpclbRouteType doRpcAndGetPath(Deadline deadline) {
logger.info("doRpcAndGetPath deadline: " + deadline);
final SimpleRequest request = SimpleRequest.newBuilder().setFillGrpclbRouteType(true).build();
GrpclbRouteType result = GrpclbRouteType.GRPCLB_ROUTE_TYPE_UNKNOWN;
try {
SimpleResponse response = blockingStub.withDeadline(deadline).unaryCall(request);
result = response.getGrpclbRouteType();
} catch (StatusRuntimeException ex) {
logger.warning("doRpcAndGetPath failed. Status: " + ex);
return GrpclbRouteType.GRPCLB_ROUTE_TYPE_UNKNOWN;
}
logger.info("doRpcAndGetPath. GrpclbRouteType result: " + result);
if (result != GrpclbRouteType.GRPCLB_ROUTE_TYPE_FALLBACK && result != GrpclbRouteType.GRPCLB_ROUTE_TYPE_BACKEND) {
throw new AssertionError("Received invalid LB route type. This suggests " + "that the server hasn't implemented this test correctly.");
}
return result;
}
Aggregations