HttpJsonCallableFactory { @InternalApi("Visible for testing") static SpanName getSpanName(@Nonnull ApiMethodDescriptor<?, ?> methodDescriptor) { Matcher matcher = FULL_METHOD_NAME_REGEX.matcher(methodDescriptor.getFullMethodName()); Preconditions.checkArgument(matcher.matches(), "Invalid fullMethodName"); return SpanName.of(matcher.group(1), matcher.group(2)); } private  HttpJsonCallableFactory(); static UnaryCallable<RequestT, ResponseT> createBaseUnaryCallable(
      HttpJsonCallSettings<RequestT, ResponseT> httpJsonCallSettings,
      UnaryCallSettings<?, ?> callSettings,
      ClientContext clientContext); static UnaryCallable<RequestT, ResponseT> createUnaryCallable(
      HttpJsonCallSettings<RequestT, ResponseT> httpJsonCallSettings,
      UnaryCallSettings<RequestT, ResponseT> callSettings,
      ClientContext clientContext); static UnaryCallable<RequestT, PagedListResponseT> createPagedCallable(
          HttpJsonCallSettings<RequestT, ResponseT> httpJsonCallSettings,
          PagedCallSettings<RequestT, ResponseT, PagedListResponseT> pagedCallSettings,
          ClientContext clientContext); static UnaryCallable<RequestT, ResponseT> createBatchingCallable(
      HttpJsonCallSettings<RequestT, ResponseT> httpJsonCallSettings,
      BatchingCallSettings<RequestT, ResponseT> batchingCallSettings,
      ClientContext clientContext); @BetaApi( "The surface for long-running operations is not stable yet and may change in the future.") static OperationCallable<RequestT, ResponseT, MetadataT> createOperationCallable(
          OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings,
          ClientContext clientContext,
          LongRunningClient longRunningClient,
          UnaryCallable<RequestT, OperationSnapshot> operationSnapshotCallable);  }
@Test public void testGetSpanName() { Map<String, SpanName> validNames = ImmutableMap.of( "compute.projects.disableXpnHost", SpanName.of("compute.projects", "disableXpnHost"), "client.method", SpanName.of("client", "method")); for (Entry<String, SpanName> entry : validNames.entrySet()) { @SuppressWarnings("unchecked") ApiMethodDescriptor descriptor = ApiMethodDescriptor.newBuilder() .setFullMethodName(entry.getKey()) .setHttpMethod(HttpMethods.POST) .setRequestFormatter(Mockito.mock(HttpRequestFormatter.class)) .setResponseParser(Mockito.mock(HttpResponseParser.class)) .build(); SpanName actualSpanName = HttpJsonCallableFactory.getSpanName(descriptor); assertThat(actualSpanName).isEqualTo(entry.getValue()); } }
@Test public void testGetSpanNameInvalid() { List<String> invalidNames = ImmutableList.of("no_split", ".no_client"); for (String invalidName : invalidNames) { @SuppressWarnings("unchecked") ApiMethodDescriptor descriptor = ApiMethodDescriptor.newBuilder() .setFullMethodName(invalidName) .setHttpMethod(HttpMethods.POST) .setRequestFormatter(Mockito.mock(HttpRequestFormatter.class)) .setResponseParser(Mockito.mock(HttpResponseParser.class)) .build(); IllegalArgumentException actualError = null; try { SpanName spanName = HttpJsonCallableFactory.getSpanName(descriptor); assertWithMessage( "Invalid method descriptor should not have a valid span name: %s should not generate the spanName: %s", invalidName, spanName) .fail(); } catch (IllegalArgumentException e) { actualError = e; } assertThat(actualError).isNotNull(); } }