Skip to content

Commit 6bc03e5

Browse files
chore: generate libraries at Tue Mar 24 18:41:13 UTC 2026
1 parent 29d0925 commit 6bc03e5

1 file changed

Lines changed: 109 additions & 51 deletions

File tree

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

Lines changed: 109 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import java.io.FileNotFoundException;
6666
import java.io.IOException;
6767
import java.net.BindException;
68-
import java.net.ConnectException;
6968
import java.net.NoRouteToHostException;
7069
import java.net.ServerSocket;
7170
import java.net.Socket;
@@ -228,7 +227,9 @@ void testTracing_clientConnectionError_ConnectException_grpc() throws Exception
228227
.build());
229228

230229
try (EchoClient client = EchoClient.create(echoStubSettingsBuilder.build().createStub())) {
231-
assertThrows(UnavailableException.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
230+
assertThrows(
231+
UnavailableException.class,
232+
() -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
232233
verifyErrorTypeAttribute("CLIENT_CONNECTION_ERROR");
233234
}
234235
}
@@ -249,53 +250,68 @@ void testTracing_clientConnectionError_UnknownHost_grpc() throws Exception {
249250
EchoStubSettings.Builder echoStubSettingsBuilder =
250251
(EchoStubSettings.Builder) grpcEchoSettings.getStubSettings().toBuilder();
251252
echoStubSettingsBuilder.setTracerFactory(tracingFactory);
252-
echoStubSettingsBuilder.echoSettings().setRetrySettings(
253-
echoStubSettingsBuilder.echoSettings().getRetrySettings().toBuilder()
254-
.setMaxAttempts(1)
255-
.build());
253+
echoStubSettingsBuilder
254+
.echoSettings()
255+
.setRetrySettings(
256+
echoStubSettingsBuilder.echoSettings().getRetrySettings().toBuilder()
257+
.setMaxAttempts(1)
258+
.build());
256259

257260
try (EchoClient client = EchoClient.create(echoStubSettingsBuilder.build().createStub())) {
258-
assertThrows(UnavailableException.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
261+
assertThrows(
262+
UnavailableException.class,
263+
() -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
259264
verifyErrorTypeAttribute("CLIENT_CONNECTION_ERROR");
260265
}
261266
}
262267

263268
@Test
264269
void testTracing_clientConnectionError_SSLHandshakeException_grpc() throws Exception {
265-
try (EchoClient client = createInterceptorClient(new SSLHandshakeException("Mock SSL failure"))) {
266-
assertThrows(RuntimeException.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
270+
try (EchoClient client =
271+
createInterceptorClient(new SSLHandshakeException("Mock SSL failure"))) {
272+
assertThrows(
273+
RuntimeException.class,
274+
() -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
267275
verifyErrorTypeAttribute("CLIENT_CONNECTION_ERROR");
268276
}
269277
}
270278

271279
@Test
272280
void testTracing_clientConnectionError_UnresolvedAddressException_grpc() throws Exception {
273281
try (EchoClient client = createInterceptorClient(new UnresolvedAddressException())) {
274-
assertThrows(RuntimeException.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
282+
assertThrows(
283+
RuntimeException.class,
284+
() -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
275285
verifyErrorTypeAttribute("CLIENT_CONNECTION_ERROR");
276286
}
277287
}
278288

279289
@Test
280290
void testTracing_clientConnectionError_NoRouteToHostException_grpc() throws Exception {
281291
try (EchoClient client = createInterceptorClient(new NoRouteToHostException())) {
282-
assertThrows(RuntimeException.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
292+
assertThrows(
293+
RuntimeException.class,
294+
() -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
283295
verifyErrorTypeAttribute("CLIENT_CONNECTION_ERROR");
284296
}
285297
}
286298

287299
@Test
288300
void testTracing_clientConnectionError_BindException_grpc() throws Exception {
289301
try (EchoClient client = createInterceptorClient(new BindException())) {
290-
assertThrows(RuntimeException.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
302+
assertThrows(
303+
RuntimeException.class,
304+
() -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
291305
verifyErrorTypeAttribute("CLIENT_CONNECTION_ERROR");
292306
}
293307
}
294308

295309
@Test
296310
void testTracing_clientTimeout_SocketTimeoutException_grpc() throws Exception {
297311
try (EchoClient client = createInterceptorClient(new SocketTimeoutException())) {
298-
assertThrows(RuntimeException.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
312+
assertThrows(
313+
RuntimeException.class,
314+
() -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
299315
verifyErrorTypeAttribute("CLIENT_TIMEOUT");
300316
}
301317
}
@@ -307,38 +323,44 @@ void testTracing_clientTimeout_DeadlineExceededException_grpc() throws Exception
307323

308324
try (ServerSocket serverSocket = new ServerSocket(0)) {
309325
int port = serverSocket.getLocalPort();
310-
Thread serverThread = new Thread(() -> {
311-
try {
312-
try (Socket ignored = serverSocket.accept()) {
313-
Thread.sleep(1000);
314-
}
315-
} catch (Exception ignored) {}
316-
});
326+
Thread serverThread =
327+
new Thread(
328+
() -> {
329+
try {
330+
try (Socket ignored = serverSocket.accept()) {
331+
Thread.sleep(1000);
332+
}
333+
} catch (Exception ignored) {
334+
}
335+
});
317336
serverThread.start();
318337

319338
EchoSettings grpcEchoSettings =
320339
EchoSettings.newBuilder()
321340
.setTransportChannelProvider(
322-
EchoSettings.defaultGrpcTransportProviderBuilder()
323-
.setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
324-
.build())
341+
EchoSettings.defaultGrpcTransportProviderBuilder()
342+
.setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
343+
.build())
325344
.setEndpoint("localhost:" + port)
326345
.build();
327346

328347
EchoStubSettings.Builder echoStubSettingsBuilder =
329348
(EchoStubSettings.Builder) grpcEchoSettings.getStubSettings().toBuilder();
330349
echoStubSettingsBuilder.setTracerFactory(tracingFactory);
331-
echoStubSettingsBuilder.echoSettings().setRetrySettings(
332-
echoStubSettingsBuilder.echoSettings().getRetrySettings().toBuilder()
333-
.setTotalTimeoutDuration(Duration.ofMillis(100))
334-
.setInitialRpcTimeoutDuration(Duration.ofMillis(100))
335-
.setMaxRpcTimeoutDuration(Duration.ofMillis(100))
336-
.setMaxAttempts(1)
337-
.build()
338-
);
350+
echoStubSettingsBuilder
351+
.echoSettings()
352+
.setRetrySettings(
353+
echoStubSettingsBuilder.echoSettings().getRetrySettings().toBuilder()
354+
.setTotalTimeoutDuration(Duration.ofMillis(100))
355+
.setInitialRpcTimeoutDuration(Duration.ofMillis(100))
356+
.setMaxRpcTimeoutDuration(Duration.ofMillis(100))
357+
.setMaxAttempts(1)
358+
.build());
339359

340360
try (EchoClient client = EchoClient.create(echoStubSettingsBuilder.build().createStub())) {
341-
assertThrows(DeadlineExceededException.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
361+
assertThrows(
362+
DeadlineExceededException.class,
363+
() -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
342364
verifyErrorTypeAttribute("CLIENT_TIMEOUT");
343365
} finally {
344366
serverThread.join();
@@ -348,15 +370,31 @@ void testTracing_clientTimeout_DeadlineExceededException_grpc() throws Exception
348370

349371
@Test
350372
void testTracing_clientAuthenticationError_GeneralSecurityException_grpc() throws Exception {
351-
Credentials credentials = new Credentials() {
352-
@Override public String getAuthenticationType() { return "mock"; }
353-
@Override public Map<String, List<String>> getRequestMetadata(URI uri) throws IOException {
373+
Credentials credentials =
374+
new Credentials() {
375+
@Override
376+
public String getAuthenticationType() {
377+
return "mock";
378+
}
379+
380+
@Override
381+
public Map<String, List<String>> getRequestMetadata(URI uri) throws IOException {
354382
throw new IOException("Mock auth failure", new GeneralSecurityException("Root cause"));
355-
}
356-
@Override public boolean hasRequestMetadata() { return true; }
357-
@Override public boolean hasRequestMetadataOnly() { return true; }
358-
@Override public void refresh() throws IOException {}
359-
};
383+
}
384+
385+
@Override
386+
public boolean hasRequestMetadata() {
387+
return true;
388+
}
389+
390+
@Override
391+
public boolean hasRequestMetadataOnly() {
392+
return true;
393+
}
394+
395+
@Override
396+
public void refresh() throws IOException {}
397+
};
360398

361399
SpanTracerFactory tracingFactory =
362400
new SpanTracerFactory(new OpenTelemetryTraceManager(openTelemetrySdk));
@@ -375,15 +413,18 @@ void testTracing_clientAuthenticationError_GeneralSecurityException_grpc() throw
375413
echoStubSettingsBuilder.setTracerFactory(tracingFactory);
376414

377415
try (EchoClient client = EchoClient.create(echoStubSettingsBuilder.build().createStub())) {
378-
assertThrows(Exception.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
416+
assertThrows(
417+
Exception.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
379418
verifyErrorTypeAttribute("CLIENT_AUTHENTICATION_ERROR");
380419
}
381420
}
382421

383422
@Test
384423
void testTracing_clientAuthenticationError_FileNotFoundException_grpc() throws Exception {
385424
try (EchoClient client = createInterceptorClient(new FileNotFoundException("Key not found"))) {
386-
assertThrows(RuntimeException.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
425+
assertThrows(
426+
RuntimeException.class,
427+
() -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
387428
// Wrapping non-RuntimeExceptions in RuntimeException during interceptCall()
388429
// means the simple class name of the exception being recorded is "RuntimeException"
389430
verifyErrorTypeAttribute("RuntimeException");
@@ -392,13 +433,22 @@ void testTracing_clientAuthenticationError_FileNotFoundException_grpc() throws E
392433

393434
@Test
394435
void testTracing_clientRequestError_IllegalArgumentException_grpc() throws Exception {
395-
try (EchoClient client = createInterceptorClient(new IllegalArgumentException("Mock request error"))) {
396-
assertThrows(IllegalArgumentException.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
436+
try (EchoClient client =
437+
createInterceptorClient(new IllegalArgumentException("Mock request error"))) {
438+
assertThrows(
439+
IllegalArgumentException.class,
440+
() -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
397441
verifyErrorTypeAttribute("CLIENT_REQUEST_ERROR");
398-
442+
399443
SpanData errorSpan =
400444
spanExporter.getFinishedSpanItems().stream()
401-
.filter(span -> span.getAttributes().get(AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE)) != null)
445+
.filter(
446+
span ->
447+
span.getAttributes()
448+
.get(
449+
AttributeKey.stringKey(
450+
ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE))
451+
!= null)
402452
.findFirst()
403453
.orElseThrow(() -> new AssertionError("Span with error.type not found"));
404454

@@ -418,7 +468,9 @@ void testTracing_clientRequestError_IllegalArgumentException_grpc() throws Excep
418468
@Test
419469
void testTracing_clientRedirectError_grpc() throws Exception {
420470
try (EchoClient client = createInterceptorClient(new RuntimeException("Too many redirects"))) {
421-
assertThrows(RuntimeException.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
471+
assertThrows(
472+
RuntimeException.class,
473+
() -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
422474
// Heuristic mapping of "redirect" in message has been removed.
423475
// Expected result is now the simple class name of the exception.
424476
verifyErrorTypeAttribute("RuntimeException");
@@ -430,7 +482,9 @@ void testTracing_clientUnknownError_grpc() throws Exception {
430482
// Creating a custom exception class whose name contains "Unknown"
431483
class MyUnknownException extends RuntimeException {}
432484
try (EchoClient client = createInterceptorClient(new MyUnknownException())) {
433-
assertThrows(RuntimeException.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
485+
assertThrows(
486+
RuntimeException.class,
487+
() -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
434488
// Heuristic mapping of "Unknown" in class name has been removed.
435489
// Expected result is now the simple class name of the exception.
436490
verifyErrorTypeAttribute("MyUnknownException");
@@ -439,9 +493,13 @@ class MyUnknownException extends RuntimeException {}
439493

440494
@Test
441495
void testTracing_clientRequestError_RestSerializationException_httpjson() throws Exception {
442-
try (EchoClient client = createInterceptorClient(new RestSerializationException("failed to serialize", null))) {
443-
assertThrows(RuntimeException.class, () -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
444-
// RestSerializationException is not handled due to ambiguity (serialization vs deserialization).
496+
try (EchoClient client =
497+
createInterceptorClient(new RestSerializationException("failed to serialize", null))) {
498+
assertThrows(
499+
RuntimeException.class,
500+
() -> client.echo(EchoRequest.newBuilder().setContent("test").build()));
501+
// RestSerializationException is not handled due to ambiguity (serialization vs
502+
// deserialization).
445503
// Expected result is now its simple class name.
446504
verifyErrorTypeAttribute("RestSerializationException");
447505
}

0 commit comments

Comments
 (0)