Skip to content

Commit

Permalink
code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jabubake committed Feb 28, 2017
1 parent e053154 commit 59ccf27
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -92,21 +92,21 @@ 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;
}
}

/** 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
Expand All @@ -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 =
Expand All @@ -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<String> 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]
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -109,21 +109,21 @@ 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;
}
}

/** 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
Expand All @@ -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 =
Expand All @@ -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<String> 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]
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 59ccf27

Please sign in to comment.