Search in sources :

Example 1 with UpdateSnapshotRequest

use of com.google.pubsub.v1.UpdateSnapshotRequest in project gapic-generator-java by googleapis.

the class SyncUpdateSnapshot method syncUpdateSnapshot.

public static void syncUpdateSnapshot() throws Exception {
    // It may require modifications to work in your environment.
    try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
        UpdateSnapshotRequest request = UpdateSnapshotRequest.newBuilder().setSnapshot(Snapshot.newBuilder().build()).setUpdateMask(FieldMask.newBuilder().build()).build();
        Snapshot response = subscriptionAdminClient.updateSnapshot(request);
    }
}
Also used : Snapshot(com.google.pubsub.v1.Snapshot) SubscriptionAdminClient(com.google.cloud.pubsub.v1.SubscriptionAdminClient) UpdateSnapshotRequest(com.google.pubsub.v1.UpdateSnapshotRequest)

Example 2 with UpdateSnapshotRequest

use of com.google.pubsub.v1.UpdateSnapshotRequest in project java-pubsub by googleapis.

the class SubscriptionAdminClientTest method updateSnapshotTest.

@Test
public void updateSnapshotTest() throws Exception {
    Snapshot expectedResponse = Snapshot.newBuilder().setName(SnapshotName.of("[PROJECT]", "[SNAPSHOT]").toString()).setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString()).setExpireTime(Timestamp.newBuilder().build()).putAllLabels(new HashMap<String, String>()).build();
    mockSubscriber.addResponse(expectedResponse);
    UpdateSnapshotRequest request = UpdateSnapshotRequest.newBuilder().setSnapshot(Snapshot.newBuilder().build()).setUpdateMask(FieldMask.newBuilder().build()).build();
    Snapshot actualResponse = client.updateSnapshot(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSubscriber.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateSnapshotRequest actualRequest = ((UpdateSnapshotRequest) actualRequests.get(0));
    Assert.assertEquals(request.getSnapshot(), actualRequest.getSnapshot());
    Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Snapshot(com.google.pubsub.v1.Snapshot) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) UpdateSnapshotRequest(com.google.pubsub.v1.UpdateSnapshotRequest) Test(org.junit.Test)

Example 3 with UpdateSnapshotRequest

use of com.google.pubsub.v1.UpdateSnapshotRequest in project java-pubsub by googleapis.

the class SubscriptionAdminClientTest method updateSnapshotExceptionTest.

@Test
public void updateSnapshotExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    try {
        UpdateSnapshotRequest request = UpdateSnapshotRequest.newBuilder().setSnapshot(Snapshot.newBuilder().build()).setUpdateMask(FieldMask.newBuilder().build()).build();
        client.updateSnapshot(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) UpdateSnapshotRequest(com.google.pubsub.v1.UpdateSnapshotRequest) Test(org.junit.Test)

Example 4 with UpdateSnapshotRequest

use of com.google.pubsub.v1.UpdateSnapshotRequest in project gapic-generator-java by googleapis.

the class AsyncUpdateSnapshot method asyncUpdateSnapshot.

public static void asyncUpdateSnapshot() throws Exception {
    // It may require modifications to work in your environment.
    try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
        UpdateSnapshotRequest request = UpdateSnapshotRequest.newBuilder().setSnapshot(Snapshot.newBuilder().build()).setUpdateMask(FieldMask.newBuilder().build()).build();
        ApiFuture<Snapshot> future = subscriptionAdminClient.updateSnapshotCallable().futureCall(request);
        // Do something.
        Snapshot response = future.get();
    }
}
Also used : Snapshot(com.google.pubsub.v1.Snapshot) SubscriptionAdminClient(com.google.cloud.pubsub.v1.SubscriptionAdminClient) UpdateSnapshotRequest(com.google.pubsub.v1.UpdateSnapshotRequest)

Example 5 with UpdateSnapshotRequest

use of com.google.pubsub.v1.UpdateSnapshotRequest in project gapic-generator-java by googleapis.

the class SubscriptionAdminClientTest method updateSnapshotExceptionTest.

@Test
public void updateSnapshotExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    try {
        UpdateSnapshotRequest request = UpdateSnapshotRequest.newBuilder().setSnapshot(Snapshot.newBuilder().build()).setUpdateMask(FieldMask.newBuilder().build()).build();
        client.updateSnapshot(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) UpdateSnapshotRequest(com.google.pubsub.v1.UpdateSnapshotRequest) Test(org.junit.Test)

Aggregations

UpdateSnapshotRequest (com.google.pubsub.v1.UpdateSnapshotRequest)6 Snapshot (com.google.pubsub.v1.Snapshot)4 Test (org.junit.Test)4 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 SubscriptionAdminClient (com.google.cloud.pubsub.v1.SubscriptionAdminClient)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 HashMap (java.util.HashMap)2