Search in sources :

Example 1 with Traces

use of com.google.devtools.cloudtrace.v1.Traces in project google-cloud-java by GoogleCloudPlatform.

the class TraceServiceClientTest method listTracesTest.

@Test
@SuppressWarnings("all")
public void listTracesTest() {
    String nextPageToken = "";
    Trace tracesElement = Trace.newBuilder().build();
    List<Trace> traces = Arrays.asList(tracesElement);
    ListTracesResponse expectedResponse = ListTracesResponse.newBuilder().setNextPageToken(nextPageToken).addAllTraces(traces).build();
    mockTraceService.addResponse(expectedResponse);
    String projectId = "projectId-1969970175";
    ListTracesPagedResponse pagedListResponse = client.listTraces(projectId);
    List<Trace> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTracesList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockTraceService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTracesRequest actualRequest = (ListTracesRequest) actualRequests.get(0);
    Assert.assertEquals(projectId, actualRequest.getProjectId());
}
Also used : Trace(com.google.devtools.cloudtrace.v1.Trace) ListTracesResponse(com.google.devtools.cloudtrace.v1.ListTracesResponse) ListTracesPagedResponse(com.google.cloud.trace.spi.v1.PagedResponseWrappers.ListTracesPagedResponse) ListTracesRequest(com.google.devtools.cloudtrace.v1.ListTracesRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 2 with Traces

use of com.google.devtools.cloudtrace.v1.Traces in project google-cloud-java by GoogleCloudPlatform.

the class TraceServiceClientTest method patchTracesExceptionTest.

@Test
@SuppressWarnings("all")
public void patchTracesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockTraceService.addException(exception);
    try {
        String projectId = "projectId-1969970175";
        Traces traces = Traces.newBuilder().build();
        client.patchTraces(projectId, traces);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : Traces(com.google.devtools.cloudtrace.v1.Traces) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 3 with Traces

use of com.google.devtools.cloudtrace.v1.Traces in project google-cloud-java by GoogleCloudPlatform.

the class TraceServiceClientTest method patchTracesTest.

@Test
@SuppressWarnings("all")
public void patchTracesTest() {
    Empty expectedResponse = Empty.newBuilder().build();
    mockTraceService.addResponse(expectedResponse);
    String projectId = "projectId-1969970175";
    Traces traces = Traces.newBuilder().build();
    client.patchTraces(projectId, traces);
    List<GeneratedMessageV3> actualRequests = mockTraceService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    PatchTracesRequest actualRequest = (PatchTracesRequest) actualRequests.get(0);
    Assert.assertEquals(projectId, actualRequest.getProjectId());
    Assert.assertEquals(traces, actualRequest.getTraces());
}
Also used : Empty(com.google.protobuf.Empty) Traces(com.google.devtools.cloudtrace.v1.Traces) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) PatchTracesRequest(com.google.devtools.cloudtrace.v1.PatchTracesRequest) Test(org.junit.Test)

Example 4 with Traces

use of com.google.devtools.cloudtrace.v1.Traces in project google-cloud-java by GoogleCloudPlatform.

the class TraceServiceClient method patchTraces.

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
   * Sends new traces to Stackdriver Trace or updates existing traces. If the ID of a trace that you
   * send matches that of an existing trace, any fields in the existing trace and its spans are
   * overwritten by the provided values, and any new fields provided are merged with the existing
   * trace data. If the ID does not match, a new trace is created.
   *
   * <p>Sample code:
   *
   * <pre><code>
   * try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) {
   *   String projectId = "";
   *   Traces traces = Traces.newBuilder().build();
   *   traceServiceClient.patchTraces(projectId, traces);
   * }
   * </code></pre>
   *
   * @param projectId ID of the Cloud project where the trace data is stored.
   * @param traces The body of the message.
   * @throws com.google.api.gax.grpc.ApiException if the remote call fails
   */
public final void patchTraces(String projectId, Traces traces) {
    PatchTracesRequest request = PatchTracesRequest.newBuilder().setProjectId(projectId).setTraces(traces).build();
    patchTraces(request);
}
Also used : PatchTracesRequest(com.google.devtools.cloudtrace.v1.PatchTracesRequest)

Aggregations

Test (org.junit.Test)3 PatchTracesRequest (com.google.devtools.cloudtrace.v1.PatchTracesRequest)2 Traces (com.google.devtools.cloudtrace.v1.Traces)2 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)2 ApiException (com.google.api.gax.grpc.ApiException)1 ListTracesPagedResponse (com.google.cloud.trace.spi.v1.PagedResponseWrappers.ListTracesPagedResponse)1 ListTracesRequest (com.google.devtools.cloudtrace.v1.ListTracesRequest)1 ListTracesResponse (com.google.devtools.cloudtrace.v1.ListTracesResponse)1 Trace (com.google.devtools.cloudtrace.v1.Trace)1 Empty (com.google.protobuf.Empty)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1