3333import static com .google .common .truth .Truth .assertThat ;
3434import static org .junit .Assert .assertThrows ;
3535
36- import com .google .api .gax . core . FixedCredentialsProvider ;
36+ import com .google .api .client . http . HttpTransport ;
3737import com .google .api .gax .core .NoCredentialsProvider ;
3838import com .google .api .gax .httpjson .RestSerializationException ;
3939import com .google .api .gax .rpc .DeadlineExceededException ;
40- import com .google .api .gax .rpc .StatusCode .Code ;
4140import com .google .api .gax .rpc .TransportChannelProvider ;
4241import com .google .api .gax .rpc .UnavailableException ;
4342import com .google .api .gax .tracing .ObservabilityAttributes ;
4443import com .google .api .gax .tracing .SpanTracerFactory ;
45- import com .google .auth .Credentials ;
4644import com .google .common .collect .ImmutableList ;
4745import com .google .rpc .Status ;
4846import com .google .showcase .v1beta1 .EchoClient ;
4947import com .google .showcase .v1beta1 .EchoRequest ;
5048import com .google .showcase .v1beta1 .EchoSettings ;
5149import com .google .showcase .v1beta1 .it .util .TestClientInitializer ;
5250import com .google .showcase .v1beta1 .stub .EchoStubSettings ;
53- import com .google .api .client .http .HttpTransport ;
5451import io .grpc .CallOptions ;
5552import io .grpc .Channel ;
5653import io .grpc .ClientCall ;
5754import io .grpc .ClientInterceptor ;
5855import io .grpc .ManagedChannelBuilder ;
59- import io .grpc .MethodDescriptor ;
6056import io .grpc .Metadata ;
57+ import io .grpc .MethodDescriptor ;
6158import io .opentelemetry .api .GlobalOpenTelemetry ;
6259import io .opentelemetry .api .common .AttributeKey ;
6360import io .opentelemetry .sdk .OpenTelemetrySdk ;
7471import java .net .ServerSocket ;
7572import java .net .Socket ;
7673import java .net .SocketTimeoutException ;
77- import java .net .URI ;
7874import java .nio .channels .UnresolvedAddressException ;
7975import java .security .GeneralSecurityException ;
8076import java .time .Duration ;
8177import java .util .List ;
82- import java .util .Map ;
78+ import java .util .concurrent . TimeUnit ;
8379import javax .net .ssl .SSLHandshakeException ;
8480import org .junit .jupiter .api .AfterEach ;
8581import org .junit .jupiter .api .BeforeEach ;
8682import org .junit .jupiter .api .Test ;
8783import org .junit .jupiter .api .Timeout ;
88- import java .util .concurrent .TimeUnit ;
8984
9085@ Timeout (value = 30 , unit = TimeUnit .SECONDS )
9186class ITOtelErrorType {
@@ -177,9 +172,7 @@ void testTracing_failedEcho_grpc_recordsErrorType() throws Exception {
177172 new ClientInterceptor () {
178173 @ Override
179174 public <ReqT , RespT > ClientCall <ReqT , RespT > interceptCall (
180- MethodDescriptor <ReqT , RespT > method ,
181- CallOptions callOptions ,
182- Channel next ) {
175+ MethodDescriptor <ReqT , RespT > method , CallOptions callOptions , Channel next ) {
183176 return new ClientCall <ReqT , RespT >() {
184177 @ Override
185178 public void start (Listener <RespT > responseListener , Metadata headers ) {
@@ -213,16 +206,15 @@ public void sendMessage(ReqT message) {}
213206
214207 EchoRequest echoRequest =
215208 EchoRequest .newBuilder ()
216- .setError (Status .newBuilder ().setCode (com .google .rpc .Code .UNAVAILABLE .ordinal ()).build ())
209+ .setError (
210+ Status .newBuilder ().setCode (com .google .rpc .Code .UNAVAILABLE .ordinal ()).build ())
217211 .build ();
218212
219213 assertThrows (UnavailableException .class , () -> client .echo (echoRequest ));
220214 verifyErrorTypeAttribute ("UNAVAILABLE" );
221215 }
222-
223216 }
224217
225-
226218 @ Test
227219 void testTracing_failedEcho_httpjson_recordsErrorType () throws Exception {
228220 SpanTracerFactory tracingFactory = new SpanTracerFactory (openTelemetrySdk );
@@ -244,7 +236,6 @@ public InputStream getContent() {
244236 return new ByteArrayInputStream ("{}" .getBytes ());
245237 }
246238
247-
248239 @ Override
249240 public String getContentEncoding () {
250241 return null ;
@@ -314,16 +305,15 @@ public String getHeaderValue(int index) {
314305 try (EchoClient client = EchoClient .create (echoStubSettings .createStub ())) {
315306 EchoRequest echoRequest =
316307 EchoRequest .newBuilder ()
317- .setError (Status .newBuilder ().setCode (com .google .rpc .Code .UNAVAILABLE .ordinal ()).build ())
308+ .setError (
309+ Status .newBuilder ().setCode (com .google .rpc .Code .UNAVAILABLE .ordinal ()).build ())
318310 .build ();
319311
320-
321312 assertThrows (UnavailableException .class , () -> client .echo (echoRequest ));
322313 verifyErrorTypeAttribute ("503" );
323314 }
324315 }
325316
326-
327317 @ Test
328318 void testTracing_clientConnectionError_ConnectException_grpc () throws Exception {
329319 int port ;
@@ -493,15 +483,14 @@ void testTracing_clientTimeout_DeadlineExceededException_grpc() throws Exception
493483
494484 @ Test
495485 void testTracing_clientAuthenticationError_GeneralSecurityException_grpc () throws Exception {
496- try (EchoClient client = createInterceptorClient (new GeneralSecurityException ("Mock auth failure" ))) {
486+ try (EchoClient client =
487+ createInterceptorClient (new GeneralSecurityException ("Mock auth failure" ))) {
497488 assertThrows (
498489 Exception .class , () -> client .echo (EchoRequest .newBuilder ().setContent ("test" ).build ()));
499490 verifyErrorTypeAttribute ("CLIENT_AUTHENTICATION_ERROR" );
500491 }
501492 }
502493
503-
504-
505494 @ Test
506495 void testTracing_clientAuthenticationError_FileNotFoundException_grpc () throws Exception {
507496 try (EchoClient client = createInterceptorClient (new FileNotFoundException ("Key not found" ))) {
0 commit comments