Search in sources :

Example 1 with Snapshot

use of com.google.pubsub.v1.Snapshot in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClient method deleteSnapshot.

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
   * Removes an existing snapshot. All messages retained in the snapshot are immediately dropped.
   * After a snapshot is deleted, a new one may be created with the same name, but the new one has
   * no association with the old snapshot or its subscription, unless the same subscription is
   * specified.
   *
   * <p>Sample code:
   *
   * <pre><code>
   * try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
   *   SnapshotName snapshot = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
   *   subscriptionAdminClient.deleteSnapshot(snapshot);
   * }
   * </code></pre>
   *
   * @param snapshot The name of the snapshot to delete. Format is
   *     `projects/{project}/snapshots/{snap}`.
   * @throws com.google.api.gax.grpc.ApiException if the remote call fails
   */
public final void deleteSnapshot(SnapshotName snapshot) {
    DeleteSnapshotRequest request = DeleteSnapshotRequest.newBuilder().setSnapshotWithSnapshotName(snapshot).build();
    deleteSnapshot(request);
}
Also used : DeleteSnapshotRequest(com.google.pubsub.v1.DeleteSnapshotRequest)

Example 2 with Snapshot

use of com.google.pubsub.v1.Snapshot in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method createSnapshotExceptionTest.

@Test
@SuppressWarnings("all")
public void createSnapshotExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    try {
        SnapshotName name = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
        SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
        client.createSnapshot(name, subscription);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) SubscriptionName(com.google.pubsub.v1.SubscriptionName) SnapshotName(com.google.pubsub.v1.SnapshotName) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 3 with Snapshot

use of com.google.pubsub.v1.Snapshot in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method deleteSnapshotTest.

@Test
@SuppressWarnings("all")
public void deleteSnapshotTest() {
    Empty expectedResponse = Empty.newBuilder().build();
    mockSubscriber.addResponse(expectedResponse);
    SnapshotName snapshot = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
    client.deleteSnapshot(snapshot);
    List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteSnapshotRequest actualRequest = (DeleteSnapshotRequest) actualRequests.get(0);
    Assert.assertEquals(snapshot, actualRequest.getSnapshotAsSnapshotName());
}
Also used : Empty(com.google.protobuf.Empty) DeleteSnapshotRequest(com.google.pubsub.v1.DeleteSnapshotRequest) SnapshotName(com.google.pubsub.v1.SnapshotName) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 4 with Snapshot

use of com.google.pubsub.v1.Snapshot in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method createSnapshotTest.

@Test
@SuppressWarnings("all")
public void createSnapshotTest() {
    SnapshotName name2 = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
    TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
    Snapshot expectedResponse = Snapshot.newBuilder().setNameWithSnapshotName(name2).setTopicWithTopicName(topic).build();
    mockSubscriber.addResponse(expectedResponse);
    SnapshotName name = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
    SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
    Snapshot actualResponse = client.createSnapshot(name, subscription);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateSnapshotRequest actualRequest = (CreateSnapshotRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsSnapshotName());
    Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
}
Also used : Snapshot(com.google.pubsub.v1.Snapshot) CreateSnapshotRequest(com.google.pubsub.v1.CreateSnapshotRequest) SubscriptionName(com.google.pubsub.v1.SubscriptionName) SnapshotName(com.google.pubsub.v1.SnapshotName) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) TopicName(com.google.pubsub.v1.TopicName) Test(org.junit.Test)

Example 5 with Snapshot

use of com.google.pubsub.v1.Snapshot in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method deleteSnapshotExceptionTest.

@Test
@SuppressWarnings("all")
public void deleteSnapshotExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    try {
        SnapshotName snapshot = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
        client.deleteSnapshot(snapshot);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) SnapshotName(com.google.pubsub.v1.SnapshotName) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 SnapshotName (com.google.pubsub.v1.SnapshotName)4 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)3 ApiException (com.google.api.gax.grpc.ApiException)2 DeleteSnapshotRequest (com.google.pubsub.v1.DeleteSnapshotRequest)2 Snapshot (com.google.pubsub.v1.Snapshot)2 SubscriptionName (com.google.pubsub.v1.SubscriptionName)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 ListSnapshotsPagedResponse (com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSnapshotsPagedResponse)1 ByteString (com.google.protobuf.ByteString)1 Empty (com.google.protobuf.Empty)1 CreateSnapshotRequest (com.google.pubsub.v1.CreateSnapshotRequest)1 ListSnapshotsRequest (com.google.pubsub.v1.ListSnapshotsRequest)1 ListSnapshotsResponse (com.google.pubsub.v1.ListSnapshotsResponse)1 ProjectName (com.google.pubsub.v1.ProjectName)1 TopicName (com.google.pubsub.v1.TopicName)1