Skip to content

Commit

Permalink
update code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
pongad committed Jan 8, 2017
1 parent 49107e2 commit 59822d0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,18 @@
import com.google.cloud.Role;
import com.google.cloud.pubsub.PubSub;
import com.google.cloud.pubsub.PubSubOptions;
import com.google.cloud.pubsub.PushConfig;
import com.google.cloud.pubsub.Subscription;
import com.google.cloud.pubsub.SubscriptionId;
import com.google.cloud.pubsub.SubscriptionInfo;
import com.google.cloud.pubsub.Topic;
import com.google.cloud.pubsub.TopicInfo;
import com.google.common.collect.ImmutableMap;

import java.util.ArrayList;
import com.google.pubsub.v1.PushConfig;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
* An example of using Google BigQuery.
Expand Down Expand Up @@ -336,7 +332,7 @@ SubscriptionInfo parse(String... args) throws Exception {
} else {
SubscriptionInfo.Builder builder = SubscriptionInfo.newBuilder(args[0], args[1]);
if (args.length == 3) {
builder.setPushConfig(PushConfig.of(args[2]));
builder.setPushConfig(PushConfig.newBuilder().setPushEndpoint(args[2]).build());
}
return builder.build();
}
Expand Down Expand Up @@ -387,7 +383,7 @@ Tuple<String, PushConfig> parse(String... args) throws Exception {
String subscription = args[0];
PushConfig pushConfig = null;
if (args.length == 2) {
pushConfig = PushConfig.of(args[1]);
pushConfig = PushConfig.newBuilder().setPushEndpoint(args[2]).build();
}
return Tuple.of(subscription, pushConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,17 @@
import com.google.cloud.Role;
import com.google.cloud.pubsub.PubSub;
import com.google.cloud.pubsub.PubSub.ListOption;
import com.google.cloud.pubsub.PushConfig;
import com.google.cloud.pubsub.Subscription;
import com.google.cloud.pubsub.SubscriptionId;
import com.google.cloud.pubsub.SubscriptionInfo;
import com.google.cloud.pubsub.Topic;
import com.google.cloud.pubsub.TopicInfo;

import com.google.pubsub.v1.PushConfig;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
* This class contains a number of snippets for the {@link PubSub} interface.
Expand Down Expand Up @@ -224,7 +222,7 @@ public Subscription createSubscriptionAsync(String topicName, String subscriptio
// [VARIABLE "https://www.example.com/push"]
public void replacePushConfig(String subscriptionName, String endpoint) {
// [START replacePushConfig]
PushConfig pushConfig = PushConfig.of(endpoint);
PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(endpoint).build();
pubsub.replacePushConfig(subscriptionName, pushConfig);
// [END replacePushConfig]
}
Expand All @@ -251,7 +249,7 @@ public void replacePushConfigToPull(String subscriptionName) {
public void replacePushConfigAsync(String subscriptionName, String endpoint)
throws ExecutionException, InterruptedException {
// [START replacePushConfigAsync]
PushConfig pushConfig = PushConfig.of(endpoint);
PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(endpoint).build();
Future<Void> future = pubsub.replacePushConfigAsync(subscriptionName, pushConfig);
// ...
future.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
import com.google.cloud.Identity;
import com.google.cloud.Policy;
import com.google.cloud.Role;
import com.google.cloud.pubsub.PushConfig;
import com.google.cloud.pubsub.Subscription;

import java.util.Iterator;
import com.google.pubsub.v1.PushConfig;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -116,7 +114,7 @@ public boolean deleteAsync() throws ExecutionException, InterruptedException {
// [VARIABLE "https://www.example.com/push"]
public void replacePushConfig(String endpoint) {
// [START replacePushConfig]
PushConfig pushConfig = PushConfig.of(endpoint);
PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(endpoint).build();
subscription.replacePushConfig(pushConfig);
// [END replacePushConfig]
}
Expand All @@ -141,7 +139,7 @@ public void replacePushConfigToPull() {
public void replacePushConfigAsync(String endpoint)
throws ExecutionException, InterruptedException {
// [START replacePushConfigAsync]
PushConfig pushConfig = PushConfig.of(endpoint);
PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(endpoint).build();
Future<Void> future = subscription.replacePushConfigAsync(pushConfig);
// ...
future.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,19 @@
import com.google.cloud.pubsub.PubSubOptions;
import com.google.cloud.pubsub.Subscription;
import com.google.cloud.pubsub.SubscriptionId;
import com.google.cloud.pubsub.SubscriptionInfo;
import com.google.cloud.pubsub.Topic;
import com.google.cloud.pubsub.TopicInfo;
import com.google.common.collect.Iterators;
import com.google.common.collect.Sets;

import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutionException;

public class ITPubSubSnippets {

private static final String NAME_SUFFIX = UUID.randomUUID().toString();
Expand Down Expand Up @@ -120,8 +114,8 @@ public void testTopicAndSubscription() throws ExecutionException, InterruptedExc
pubsubSnippets.replacePushConfigAsync(subscriptionName2, endpoint);
subscription1 = pubsubSnippets.getSubscription(subscriptionName1);
subscription2 = pubsubSnippets.getSubscriptionAsync(subscriptionName2);
assertEquals(endpoint, subscription1.getPushConfig().getEndpoint());
assertEquals(endpoint, subscription2.getPushConfig().getEndpoint());
assertEquals(endpoint, subscription1.getPushConfig().getPushEndpoint());
assertEquals(endpoint, subscription2.getPushConfig().getPushEndpoint());
pubsubSnippets.replacePushConfigToPull(subscriptionName1);
pubsubSnippets.replacePushConfigToPullAsync(subscriptionName2);
subscription1 = pubsubSnippets.getSubscription(subscriptionName1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@
import com.google.cloud.pubsub.SubscriptionInfo;
import com.google.cloud.pubsub.Topic;
import com.google.cloud.pubsub.TopicInfo;

import java.util.UUID;
import java.util.concurrent.ExecutionException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.Iterator;
import java.util.UUID;
import java.util.concurrent.ExecutionException;

public class ITSubscriptionSnippets {

private static final String TOPIC =
Expand Down Expand Up @@ -73,13 +70,13 @@ public void testPushConfig() throws ExecutionException, InterruptedException {
String endpoint = "https://" + pubsub.getOptions().getProjectId() + ".appspot.com/push";
subscriptionSnippets.replacePushConfig(endpoint);
Subscription updatedSubscription = pubsub.getSubscription(SUBSCRIPTION);
assertEquals(endpoint, updatedSubscription.getPushConfig().getEndpoint());
assertEquals(endpoint, updatedSubscription.getPushConfig().getPushEndpoint());
subscriptionSnippets.replacePushConfigToPull();
updatedSubscription = pubsub.getSubscription(SUBSCRIPTION);
assertNull(updatedSubscription.getPushConfig());
subscriptionSnippets.replacePushConfigAsync(endpoint);
updatedSubscription = pubsub.getSubscription(SUBSCRIPTION);
assertEquals(endpoint, updatedSubscription.getPushConfig().getEndpoint());
assertEquals(endpoint, updatedSubscription.getPushConfig().getPushEndpoint());
subscriptionSnippets.replacePushConfigToPullAsync();
updatedSubscription = pubsub.getSubscription(SUBSCRIPTION);
assertNull(updatedSubscription.getPushConfig());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
package com.google.cloud.pubsub;

import com.google.cloud.AsyncPage;
import com.google.cloud.GrpcServiceOptions.ExecutorFactory;
import com.google.cloud.Page;
import com.google.cloud.Policy;
import com.google.cloud.Service;
import com.google.pubsub.v1.PushConfig;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

/**
Expand Down

0 comments on commit 59822d0

Please sign in to comment.