|
26 | 26 | import com.google.showcase.v1beta1.WaitRequest; |
27 | 27 | import com.google.showcase.v1beta1.WaitResponse; |
28 | 28 | 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; |
29 | 35 | import java.util.concurrent.CancellationException; |
30 | 36 | import java.util.concurrent.TimeUnit; |
31 | 37 | import org.junit.jupiter.api.Test; |
@@ -193,4 +199,68 @@ void testHttpJson_LROUnsuccessfulResponse_exceedsTotalTimeout_throwsDeadlineExce |
193 | 199 | TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); |
194 | 200 | } |
195 | 201 | } |
| 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 | + } |
196 | 266 | } |
0 commit comments