Search in sources :

Example 26 with TopicName

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

the class TopicAdminClient method deleteTopic.

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
   * Deletes the topic with the given name. Returns `NOT_FOUND` if the topic does not exist. After a
   * topic is deleted, a new topic may be created with the same name; this is an entirely new topic
   * with none of the old configuration or subscriptions. Existing subscriptions to this topic are
   * not deleted, but their `topic` field is set to `_deleted-topic_`.
   *
   * <p>Sample code:
   *
   * <pre><code>
   * try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   *   TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
   *   topicAdminClient.deleteTopic(topic);
   * }
   * </code></pre>
   *
   * @param topic Name of the topic to delete. Format is `projects/{project}/topics/{topic}`.
   * @throws com.google.api.gax.grpc.ApiException if the remote call fails
   */
public final void deleteTopic(TopicName topic) {
    DeleteTopicRequest request = DeleteTopicRequest.newBuilder().setTopicWithTopicName(topic).build();
    deleteTopic(request);
}
Also used : DeleteTopicRequest(com.google.pubsub.v1.DeleteTopicRequest)

Example 27 with TopicName

use of com.google.pubsub.v1.TopicName 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 28 with TopicName

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

the class TopicAdminClientTest method getTopicExceptionTest.

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

Example 29 with TopicName

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

the class TopicAdminClientTest method publishTest.

@Test
@SuppressWarnings("all")
public void publishTest() {
    String messageIdsElement = "messageIdsElement-744837059";
    List<String> messageIds = Arrays.asList(messageIdsElement);
    PublishResponse expectedResponse = PublishResponse.newBuilder().addAllMessageIds(messageIds).build();
    mockPublisher.addResponse(expectedResponse);
    TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
    ByteString data = ByteString.copyFromUtf8("-86");
    PubsubMessage messagesElement = PubsubMessage.newBuilder().setData(data).build();
    List<PubsubMessage> messages = Arrays.asList(messagesElement);
    PublishResponse actualResponse = client.publish(topic, messages);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    PublishRequest actualRequest = (PublishRequest) actualRequests.get(0);
    Assert.assertEquals(topic, actualRequest.getTopicAsTopicName());
    Assert.assertEquals(messages, actualRequest.getMessagesList());
}
Also used : PublishResponse(com.google.pubsub.v1.PublishResponse) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) PublishRequest(com.google.pubsub.v1.PublishRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) PubsubMessage(com.google.pubsub.v1.PubsubMessage) TopicName(com.google.pubsub.v1.TopicName) Test(org.junit.Test)

Example 30 with TopicName

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

the class TopicAdminClientTest method deleteTopicExceptionTest.

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

Aggregations

TopicName (com.google.pubsub.v1.TopicName)28 Test (org.junit.Test)20 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 TopicAdminClient (com.google.cloud.pubsub.spi.v1.TopicAdminClient)7 ByteString (com.google.protobuf.ByteString)7 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)7 ApiException (com.google.api.gax.grpc.ApiException)6 PubsubMessage (com.google.pubsub.v1.PubsubMessage)6 Subscription (com.google.pubsub.v1.Subscription)6 Topic (com.google.pubsub.v1.Topic)6 StatusRuntimeException (io.grpc.StatusRuntimeException)6 Publisher (com.google.cloud.pubsub.spi.v1.Publisher)4 SubscriptionAdminClient (com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient)4 PushConfig (com.google.pubsub.v1.PushConfig)3 AckReplyConsumer (com.google.cloud.pubsub.spi.v1.AckReplyConsumer)2 MessageReceiver (com.google.cloud.pubsub.spi.v1.MessageReceiver)2 ListTopicSubscriptionsPagedResponse (com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicSubscriptionsPagedResponse)2 Subscriber (com.google.cloud.pubsub.spi.v1.Subscriber)2 Policy (com.google.iam.v1.Policy)2 DeleteTopicRequest (com.google.pubsub.v1.DeleteTopicRequest)2