|
53 | 53 | import com.google.api.gax.rpc.testing.FakeClientSettings; |
54 | 54 | import com.google.api.gax.rpc.testing.FakeStubSettings; |
55 | 55 | import com.google.api.gax.rpc.testing.FakeTransportChannel; |
| 56 | +import com.google.api.gax.tracing.ApiTracerFactory; |
| 57 | +import com.google.api.gax.tracing.SpanTracerFactory; |
56 | 58 | import com.google.auth.ApiKeyCredentials; |
57 | 59 | import com.google.auth.CredentialTypeForMetrics; |
58 | 60 | import com.google.auth.Credentials; |
@@ -1287,4 +1289,22 @@ void test_nullMtlsEndpointIsNotPassedToTransportChannel() throws IOException { |
1287 | 1289 | // is not passed to the TransportChannelProvider |
1288 | 1290 | ClientContext.create(clientSettings); |
1289 | 1291 | } |
| 1292 | + |
| 1293 | + @Test |
| 1294 | + void testCreate_withTracerFactoryReturningNullWithContext() throws IOException { |
| 1295 | + FakeStubSettings.Builder builder = FakeStubSettings.newBuilder(); |
| 1296 | + builder.setTransportChannelProvider(getFakeTransportChannelProvider()); |
| 1297 | + builder.setCredentialsProvider( |
| 1298 | + FixedCredentialsProvider.create(Mockito.mock(Credentials.class))); |
| 1299 | + |
| 1300 | + ApiTracerFactory apiTracerFactory = Mockito.mock(SpanTracerFactory.class); |
| 1301 | + Mockito.doReturn(apiTracerFactory).when(apiTracerFactory).withContext(Mockito.any()); |
| 1302 | + |
| 1303 | + FakeStubSettings settings = Mockito.spy(builder.build()); |
| 1304 | + Mockito.doReturn(apiTracerFactory).when(settings).getTracerFactory(); |
| 1305 | + |
| 1306 | + ClientContext context = ClientContext.create(settings); |
| 1307 | + assertThat(context.getTracerFactory()).isSameInstanceAs(apiTracerFactory); |
| 1308 | + verify(apiTracerFactory, times(1)).withContext(Mockito.any()); |
| 1309 | + } |
1290 | 1310 | } |
0 commit comments