Skip to content

Commit 3e400b9

Browse files
committed
test(showcase): add integration tests showing LRO drops error details
1 parent bfd98cf commit 3e400b9

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITLongRunningOperation.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
import com.google.showcase.v1beta1.WaitRequest;
2727
import com.google.showcase.v1beta1.WaitResponse;
2828
import com.google.showcase.v1beta1.it.util.TestClientInitializer;
29+
import com.google.api.gax.rpc.ApiException;
30+
import com.google.rpc.Code;
31+
import com.google.rpc.Status;
32+
import com.google.protobuf.Any;
33+
import com.google.showcase.v1beta1.PoetryError;
34+
import java.util.concurrent.ExecutionException;
2935
import java.util.concurrent.CancellationException;
3036
import java.util.concurrent.TimeUnit;
3137
import org.junit.jupiter.api.Test;
@@ -193,4 +199,68 @@ void testHttpJson_LROUnsuccessfulResponse_exceedsTotalTimeout_throwsDeadlineExce
193199
TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS);
194200
}
195201
}
202+
203+
@Test
204+
void testGRPC_LROErrorResponse_dropsErrorDetails() throws Exception {
205+
EchoClient grpcClient = TestClientInitializer.createGrpcEchoClient();
206+
try {
207+
PoetryError poetryError =
208+
PoetryError.newBuilder().setPoem("Roses are red, violets are blue").build();
209+
Status status =
210+
Status.newBuilder()
211+
.setCode(Code.ALREADY_EXISTS_VALUE)
212+
.setMessage("The resource already exists")
213+
.addDetails(Any.pack(poetryError))
214+
.build();
215+
WaitRequest waitRequest =
216+
WaitRequest.newBuilder()
217+
.setError(status)
218+
.build();
219+
OperationFuture<WaitResponse, WaitMetadata> operationFuture =
220+
grpcClient.waitOperationCallable().futureCall(waitRequest);
221+
ExecutionException exception =
222+
assertThrows(ExecutionException.class, operationFuture::get);
223+
assertThat(exception.getCause()).isInstanceOf(ApiException.class);
224+
ApiException apiException = (ApiException) exception.getCause();
225+
226+
// Current behavior: Error details are dropped during LRO error parsing
227+
assertThat(apiException.getErrorDetails()).isNull();
228+
} finally {
229+
grpcClient.close();
230+
grpcClient.awaitTermination(
231+
TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS);
232+
}
233+
}
234+
235+
@Test
236+
void testHttpJson_LROErrorResponse_dropsErrorDetails() throws Exception {
237+
EchoClient httpjsonClient = TestClientInitializer.createHttpJsonEchoClient();
238+
try {
239+
PoetryError poetryError =
240+
PoetryError.newBuilder().setPoem("Roses are red, violets are blue").build();
241+
Status status =
242+
Status.newBuilder()
243+
.setCode(Code.ALREADY_EXISTS_VALUE)
244+
.setMessage("The resource already exists")
245+
.addDetails(Any.pack(poetryError))
246+
.build();
247+
WaitRequest waitRequest =
248+
WaitRequest.newBuilder()
249+
.setError(status)
250+
.build();
251+
OperationFuture<WaitResponse, WaitMetadata> operationFuture =
252+
httpjsonClient.waitOperationCallable().futureCall(waitRequest);
253+
ExecutionException exception =
254+
assertThrows(ExecutionException.class, operationFuture::get);
255+
assertThat(exception.getCause()).isInstanceOf(ApiException.class);
256+
ApiException apiException = (ApiException) exception.getCause();
257+
258+
// Current behavior: Error details are dropped during LRO error parsing
259+
assertThat(apiException.getErrorDetails()).isNull();
260+
} finally {
261+
httpjsonClient.close();
262+
httpjsonClient.awaitTermination(
263+
TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS);
264+
}
265+
}
196266
}

0 commit comments

Comments
 (0)