From 59ccf27d119222c3e2ededda203566209c4ded7c Mon Sep 17 00:00:00 2001 From: Jisha Abubaker Date: Mon, 27 Feb 2017 17:07:56 -0800 Subject: [PATCH] code review fixes --- .../snippets/PublisherClientSnippets.java | 28 ++++++++-------- .../snippets/SubscriberClientSnippets.java | 32 +++++++++---------- .../examples/pubsub/snippets/Cleanup.java | 12 +++---- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/PublisherClientSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/PublisherClientSnippets.java index 2b37d2e9d158..2eaf88022acf 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/PublisherClientSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/PublisherClientSnippets.java @@ -42,10 +42,10 @@ public PublisherClientSnippets(String projectId) { } /** Example of creating a topic. */ - public Topic createTopic(String myTopic) throws Exception { + public Topic createTopic(String topicId) throws Exception { try (PublisherClient publisherClient = PublisherClient.create()) { // [START createTopic] - TopicName topicName = TopicName.create(projectId, myTopic); + TopicName topicName = TopicName.create(projectId, topicId); Topic topic = publisherClient.createTopic(topicName); // [END createTopic] return topic; @@ -71,11 +71,11 @@ public ListTopicsPagedResponse listTopics() throws Exception { } /** Example of listing topics for a subscription. */ - public ListTopicSubscriptionsPagedResponse listTopicSubscriptions(String myTopic) + public ListTopicSubscriptionsPagedResponse listTopicSubscriptions(String topicId) throws Exception { try (PublisherClient publisherClient = PublisherClient.create()) { // [START listTopicSubscriptions] - TopicName topicName = TopicName.create(projectId, myTopic); + TopicName topicName = TopicName.create(projectId, topicId); ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder() .setTopicWithTopicName(topicName) @@ -92,10 +92,10 @@ public ListTopicSubscriptionsPagedResponse listTopicSubscriptions(String myTopic } /** Example of deleting a topic. */ - public TopicName deleteTopic(String myTopic) throws Exception { + public TopicName deleteTopic(String topicId) throws Exception { try (PublisherClient publisherClient = PublisherClient.create()) { // [START deleteTopic] - TopicName topicName = TopicName.create(projectId, myTopic); + TopicName topicName = TopicName.create(projectId, topicId); publisherClient.deleteTopic(topicName); // [END deleteTopic] return topicName; @@ -103,10 +103,10 @@ public TopicName deleteTopic(String myTopic) throws Exception { } /** Example of getting a topic policy. */ - public Policy getTopicPolicy(String myTopic) throws Exception { + public Policy getTopicPolicy(String topicId) throws Exception { try (PublisherClient publisherClient = PublisherClient.create()) { // [START getTopicPolicy] - TopicName topicName = TopicName.create(projectId, myTopic); + TopicName topicName = TopicName.create(projectId, topicId); Policy policy = publisherClient.getIamPolicy(topicName.toString()); if (policy == null) { // topic iam policy was not found @@ -117,10 +117,10 @@ public Policy getTopicPolicy(String myTopic) throws Exception { } /** Example of replacing a topic policy. */ - public Policy replaceTopicPolicy(String myTopic) throws Exception { + public Policy replaceTopicPolicy(String topicId) throws Exception { try (PublisherClient publisherClient = PublisherClient.create()) { // [START replaceTopicPolicy] - String topicName = TopicName.create(projectId, myTopic).toString(); + String topicName = TopicName.create(projectId, topicId).toString(); Policy policy = publisherClient.getIamPolicy(topicName); // add role -> members binding Binding binding = @@ -138,12 +138,12 @@ public Policy replaceTopicPolicy(String myTopic) throws Exception { /** Example of testing whether the caller has the provided permissions on a topic. * Only viewer, editor or admin/owner can view results of pubsub.topics.get */ - public TestIamPermissionsResponse testTopicPermissions(String myTopic) throws Exception { + public TestIamPermissionsResponse testTopicPermissions(String topicId) throws Exception { try (PublisherClient publisherClient = PublisherClient.create()) { // [START testTopicPermissions] List permissions = new LinkedList<>(); permissions.add("pubsub.topics.get"); - TopicName topicName = TopicName.create(projectId, myTopic); + TopicName topicName = TopicName.create(projectId, topicId); TestIamPermissionsResponse testedPermissions = publisherClient.testIamPermissions(topicName.toString(), permissions); // [END testTopicPermissions] @@ -152,10 +152,10 @@ public TestIamPermissionsResponse testTopicPermissions(String myTopic) throws Ex } /** Example of getting a topic. */ - public Topic getTopic(String myTopic) throws Exception { + public Topic getTopic(String topicId) throws Exception { try (PublisherClient publisherClient = PublisherClient.create()) { // [START getTopic] - TopicName topicName = TopicName.create(projectId, myTopic); + TopicName topicName = TopicName.create(projectId, topicId); Topic topic = publisherClient.getTopic(topicName); // [END createTopic] return topic; diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriberClientSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriberClientSnippets.java index 44153462fe6c..eff3a7f206e5 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriberClientSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriberClientSnippets.java @@ -48,12 +48,12 @@ public SubscriberClientSnippets(String projectId) { } /** Example of creating a pull subscription for a topic. */ - public Subscription createSubscription(String topic, String mySubscription) throws Exception { + public Subscription createSubscription(String topic, String subscriptionId) throws Exception { try (SubscriberClient subscriberClient = SubscriberClient.create()) { // [START createSubscription] TopicName topicName = TopicName.create(projectId, topic); SubscriptionName subscriptionName = - SubscriptionName.create(projectId, mySubscription); + SubscriptionName.create(projectId, subscriptionId); Subscription subscription = subscriberClient.createSubscription( subscriptionName, topicName, PushConfig.getDefaultInstance(), 0); @@ -63,10 +63,10 @@ public Subscription createSubscription(String topic, String mySubscription) thro } /** Example of pulling a maximum number of messages from a subscription. */ - public PullResponse pull(String mySubscription) throws Exception { + public PullResponse pull(String subscriptionId) throws Exception { try (SubscriberClient subscriberClient = SubscriberClient.create()) { // [START pull] - SubscriptionName subscriptionName = SubscriptionName.create(projectId, mySubscription); + SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId); PullResponse response = subscriberClient.pull(subscriptionName, true, 100); for (ReceivedMessage message : response.getReceivedMessagesList()) { // do something with message, then ack or nack @@ -79,10 +79,10 @@ public PullResponse pull(String mySubscription) throws Exception { } /** Example of replacing the push configuration of a subscription, setting the push endpoint. */ - public void replacePushConfig(String mySubscription, String endpoint) throws Exception { + public void replacePushConfig(String subscriptionId, String endpoint) throws Exception { try (SubscriberClient subscriberClient = SubscriberClient.create()) { // [START replacePushConfig] - SubscriptionName subscriptionName = SubscriptionName.create(projectId, mySubscription); + SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId); PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(endpoint).build(); subscriberClient.modifyPushConfig(subscriptionName, pushConfig); // [END replacePushConfig] @@ -109,10 +109,10 @@ public ListSubscriptionsPagedResponse listSubscriptions() throws Exception { } /** Example of deleting a subscription. */ - public SubscriptionName deleteSubscription(String mySubscription) throws Exception { + public SubscriptionName deleteSubscription(String subscriptionId) throws Exception { try (SubscriberClient subscriberClient = SubscriberClient.create()) { // [START deleteSubscription] - SubscriptionName subscriptionName = SubscriptionName.create(projectId, mySubscription); + SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId); subscriberClient.deleteSubscription(subscriptionName); // [END deleteSubscription] return subscriptionName; @@ -120,10 +120,10 @@ public SubscriptionName deleteSubscription(String mySubscription) throws Excepti } /** Example of getting a subscription policy. */ - public Policy getSubscriptionPolicy(String mySubscription) throws Exception { + public Policy getSubscriptionPolicy(String subscriptionId) throws Exception { try (SubscriberClient subscriberClient = SubscriberClient.create()) { // [START getSubscriptionPolicy] - SubscriptionName subscriptionName = SubscriptionName.create(projectId, mySubscription); + SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId); Policy policy = subscriberClient.getIamPolicy(subscriptionName.toString()); if (policy == null) { // subscription was not found @@ -134,10 +134,10 @@ public Policy getSubscriptionPolicy(String mySubscription) throws Exception { } /** Example of replacing a subscription policy. */ - public Policy replaceSubscriptionPolicy(String mySubscription) throws Exception { + public Policy replaceSubscriptionPolicy(String subscriptionId) throws Exception { try (SubscriberClient subscriberClient = SubscriberClient.create()) { // [START replaceSubscriptionPolicy] - SubscriptionName subscriptionName = SubscriptionName.create(projectId, mySubscription); + SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId); Policy policy = subscriberClient.getIamPolicy(subscriptionName.toString()); // Create a role => members binding Binding binding = @@ -155,13 +155,13 @@ public Policy replaceSubscriptionPolicy(String mySubscription) throws Exception } /** Example of testing whether the caller has the provided permissions on a subscription. */ - public TestIamPermissionsResponse testSubscriptionPermissions(String mySubscription) + public TestIamPermissionsResponse testSubscriptionPermissions(String subscriptionId) throws Exception { try (PublisherClient publisherClient = PublisherClient.create()) { // [START testSubscriptionPermissions] List permissions = new LinkedList<>(); permissions.add("pubsub.subscriptions.get"); - SubscriptionName subscriptionName = SubscriptionName.create(projectId, mySubscription); + SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId); TestIamPermissionsResponse testedPermissions = publisherClient.testIamPermissions(subscriptionName.toString(), permissions); // [END testSubscriptionPermissions] @@ -170,10 +170,10 @@ public TestIamPermissionsResponse testSubscriptionPermissions(String mySubscript } /** Example of getting a subscription. */ - public Subscription getSubscription(String mySubscription) throws Exception { + public Subscription getSubscription(String subscriptionId) throws Exception { try (SubscriberClient subscriberClient = SubscriberClient.create()) { // [START getSubscription] - SubscriptionName subscriptionName = SubscriptionName.create(projectId, mySubscription); + SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId); Subscription subscription = subscriberClient.getSubscription(subscriptionName); // [END getSubscription] return subscription; diff --git a/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/Cleanup.java b/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/Cleanup.java index fccdf51824ca..c9911fd392a3 100644 --- a/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/Cleanup.java +++ b/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/Cleanup.java @@ -31,10 +31,10 @@ protected static void deleteTestTopicsAndSubscriptions( private static void deleteTestTopics(String projectId, String[] testTopics) throws Exception { try (PublisherClient publisherClient = PublisherClient.create()) { - for (String name : testTopics) { + for (String topicId : testTopics) { try { - publisherClient.deleteTopic(TopicName.create(projectId, name)); - System.out.println("Topic deleted : " + name); + publisherClient.deleteTopic(TopicName.create(projectId, topicId)); + System.out.println("Topic deleted : " + topicId); } catch (Exception e) { //do nothing catch clause } @@ -45,11 +45,11 @@ private static void deleteTestTopics(String projectId, String[] testTopics) thro private static void deleteTestSubscriptions(String projectId, String[] subscriptions) throws Exception { try (SubscriberClient subscriberClient = SubscriberClient.create()) { - for (String name : subscriptions) { + for (String subscriptionId : subscriptions) { try { subscriberClient.deleteSubscription( - SubscriptionName.create(projectId, name)); - System.out.println("Subscription deleted : " + name); + SubscriptionName.create(projectId, subscriptionId)); + System.out.println("Subscription deleted : " + subscriptionId); } catch (Exception e) { //do nothing catch clause }