Verifying result read with retries in the remote execute unit test.
The current behavior is already correct, just adding a test to make sure we retry reads as we should.
TESTED=the unit test
RELNOTES: None
@@ -63,6 +63,7 @@ import com.google.devtools.remoteexecution.v1test.ExecutionGrpc.ExecutionImplBas
import com.google.devtools.remoteexecution.v1test.FindMissingBlobsRequest;
import com.google.devtools.remoteexecution.v1test.FindMissingBlobsResponse;
import com.google.devtools.remoteexecution.v1test.GetActionResultRequest;
+import com.google.devtools.remoteexecution.v1test.OutputFile;
import com.google.devtools.remoteexecution.v1test.RequestMetadata;
import com.google.longrunning.Operation;
import com.google.protobuf.Any;
@@ -503,10 +504,12 @@ public class GrpcRemoteExecutionClientTest {
(numErrors-- <= 0 ? Status.NOT_FOUND : Status.UNAVAILABLE).asRuntimeException());
}
});
+ final Digest resultDigest = DIGEST_UTIL.compute("bla".getBytes(UTF_8));
final ActionResult actionResult =
ActionResult.newBuilder()
.setStdoutRaw(ByteString.copyFromUtf8("stdout"))
.setStderrRaw(ByteString.copyFromUtf8("stderr"))
+ .addOutputFiles(OutputFile.newBuilder().setPath("foo").setDigest(resultDigest).build())
.build();
final String opName = "operations/xyz";
@@ -678,6 +681,26 @@ public class GrpcRemoteExecutionClientTest {
.thenAnswer(blobWriteAnswerError()) // Error on the input file.
.thenAnswer(blobWriteAnswerError()) // Error on the input file again.
.thenAnswer(blobWriteAnswer("xyz".getBytes(UTF_8))); // Upload input file successfully.
+ Mockito.doAnswer(
+ invocationOnMock -> {
+ @SuppressWarnings("unchecked")
+ StreamObserver<ReadResponse> responseObserver =
+ (StreamObserver<ReadResponse>) invocationOnMock.getArguments()[1];
+ responseObserver.onError(Status.INTERNAL.asRuntimeException()); // Will retry.
+ return null;
+ })
+ .doAnswer(
+ invocationOnMock -> {
+ @SuppressWarnings("unchecked")
+ StreamObserver<ReadResponse> responseObserver =
+ (StreamObserver<ReadResponse>) invocationOnMock.getArguments()[1];
+ responseObserver.onNext(
+ ReadResponse.newBuilder().setData(ByteString.copyFromUtf8("bla")).build());
+ responseObserver.onCompleted();
+ return null;
+ })
+ .when(mockByteStreamImpl)
+ .read(Mockito.<ReadRequest>anyObject(), Mockito.<StreamObserver<ReadResponse>>anyObject());
serviceRegistry.addService(mockByteStreamImpl);
SpawnResult result = client.exec(simpleSpawn, simplePolicy);
@@ -692,6 +715,8 @@ public class GrpcRemoteExecutionClientTest {
Mockito.verify(mockWatcherImpl, Mockito.times(4))
.watch(
Mockito.<Request>anyObject(), Mockito.<StreamObserver<ChangeBatch>>anyObject());
+ Mockito.verify(mockByteStreamImpl, Mockito.times(2))
+ .read(Mockito.<ReadRequest>anyObject(), Mockito.<StreamObserver<ReadResponse>>anyObject());
}
@Test
