Skip to content

Commit c701671

Browse files
committed
Merge remote-tracking branch 'upstream/master' into pubsub_snippets
2 parents 59ccf27 + 365a0f7 commit c701671

File tree

88 files changed

+232
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+232
-87
lines changed

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceSettings.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -79,6 +79,9 @@ public class ErrorGroupServiceSettings extends ClientSettings {
7979
private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES =
8080
ImmutableList.<String>builder().add("https://www.googleapis.com/auth/cloud-platform").build();
8181

82+
private static final String DEFAULT_GENERATOR_NAME = "gapic";
83+
private static final String DEFAULT_GENERATOR_VERSION = "0.0.5";
84+
8285
private final SimpleCallSettings<GetGroupRequest, ErrorGroup> getGroupSettings;
8386
private final SimpleCallSettings<UpdateGroupRequest, ErrorGroup> updateGroupSettings;
8487

@@ -122,6 +125,7 @@ public static InstantiatingChannelProvider.Builder defaultChannelProviderBuilder
122125
return InstantiatingChannelProvider.newBuilder()
123126
.setServiceAddress(DEFAULT_SERVICE_ADDRESS)
124127
.setPort(DEFAULT_SERVICE_PORT)
128+
.setGeneratorHeader(DEFAULT_GENERATOR_NAME, DEFAULT_GENERATOR_VERSION)
125129
.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
126130
}
127131

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceSettings.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -92,6 +92,9 @@ public class ErrorStatsServiceSettings extends ClientSettings {
9292
private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES =
9393
ImmutableList.<String>builder().add("https://www.googleapis.com/auth/cloud-platform").build();
9494

95+
private static final String DEFAULT_GENERATOR_NAME = "gapic";
96+
private static final String DEFAULT_GENERATOR_VERSION = "0.0.5";
97+
9598
private final PagedCallSettings<
9699
ListGroupStatsRequest, ListGroupStatsResponse, ListGroupStatsPagedResponse>
97100
listGroupStatsSettings;
@@ -147,6 +150,7 @@ public static InstantiatingChannelProvider.Builder defaultChannelProviderBuilder
147150
return InstantiatingChannelProvider.newBuilder()
148151
.setServiceAddress(DEFAULT_SERVICE_ADDRESS)
149152
.setPort(DEFAULT_SERVICE_PORT)
153+
.setGeneratorHeader(DEFAULT_GENERATOR_NAME, DEFAULT_GENERATOR_VERSION)
150154
.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
151155
}
152156

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/PagedResponseWrappers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceSettings.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -78,6 +78,9 @@ public class ReportErrorsServiceSettings extends ClientSettings {
7878
private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES =
7979
ImmutableList.<String>builder().add("https://www.googleapis.com/auth/cloud-platform").build();
8080

81+
private static final String DEFAULT_GENERATOR_NAME = "gapic";
82+
private static final String DEFAULT_GENERATOR_VERSION = "0.0.5";
83+
8184
private final SimpleCallSettings<ReportErrorEventRequest, ReportErrorEventResponse>
8285
reportErrorEventSettings;
8386

@@ -117,6 +120,7 @@ public static InstantiatingChannelProvider.Builder defaultChannelProviderBuilder
117120
return InstantiatingChannelProvider.newBuilder()
118121
.setServiceAddress(DEFAULT_SERVICE_ADDRESS)
119122
.setPort(DEFAULT_SERVICE_PORT)
123+
.setGeneratorHeader(DEFAULT_GENERATOR_NAME, DEFAULT_GENERATOR_VERSION)
120124
.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
121125
}
122126

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorGroupService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorGroupServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorStatsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorStatsServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockReportErrorsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockReportErrorsServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/PublisherSnippets.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public PublisherSnippets(Publisher publisher) {
4040
/** Example of publishing a message. */
4141
// [TARGET publish(PubsubMessage)]
4242
// [VARIABLE "my_message"]
43-
public void publish(String message) {
43+
public RpcFuture<String> publish(String message) {
4444
// [START publish]
4545
ByteString data = ByteString.copyFromUtf8(message);
4646
PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();
@@ -56,6 +56,7 @@ public void onFailure(Throwable t) {
5656
}
5757
});
5858
// [END publish]
59+
return messageIdFuture;
5960
}
6061

6162
/** Example of creating a {@code Publisher}. */

google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriberSnippets.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public SubscriberSnippets(
5151
* Example of receiving a specific number of messages.
5252
*/
5353
// [TARGET startAsync()]
54-
public void startAsync() throws Exception {
54+
public void startAndWait() throws Exception {
5555
// [START startAsync]
5656
Subscriber subscriber = Subscriber.newBuilder(subscription, receiver).build();
5757
subscriber.addListener(new Subscriber.SubscriberListener() {

google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITPubSubSnippets.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import static org.junit.Assert.assertNull;
2222
import static org.junit.Assert.assertTrue;
2323

24+
import com.google.api.gax.core.RpcFutureCallback;
25+
import com.google.api.gax.core.SettableRpcFuture;
2426
import com.google.cloud.Identity;
2527
import com.google.cloud.Page;
2628
import com.google.cloud.Policy;
@@ -33,14 +35,25 @@
3335
import com.google.cloud.pubsub.deprecated.SubscriptionInfo;
3436
import com.google.cloud.pubsub.deprecated.Topic;
3537
import com.google.cloud.pubsub.deprecated.TopicInfo;
38+
import com.google.cloud.pubsub.spi.v1.Publisher;
39+
import com.google.cloud.pubsub.spi.v1.PublisherClient;
40+
import com.google.cloud.pubsub.spi.v1.SubscriberClient;
3641
import com.google.common.collect.Iterators;
3742
import com.google.common.collect.Sets;
43+
import com.google.common.util.concurrent.MoreExecutors;
44+
import com.google.pubsub.v1.PubsubMessage;
45+
import com.google.pubsub.v1.PushConfig;
46+
import com.google.pubsub.v1.SubscriptionName;
47+
import com.google.pubsub.v1.TopicName;
3848
import java.util.HashSet;
3949
import java.util.Iterator;
4050
import java.util.List;
4151
import java.util.Set;
4252
import java.util.UUID;
53+
import java.util.concurrent.ArrayBlockingQueue;
54+
import java.util.concurrent.BlockingQueue;
4355
import java.util.concurrent.ExecutionException;
56+
import java.util.concurrent.TimeUnit;
4457
import org.junit.AfterClass;
4558
import org.junit.BeforeClass;
4659
import org.junit.Rule;
@@ -264,4 +277,79 @@ public void testTopicPolicyAsync() throws ExecutionException, InterruptedExcepti
264277
topic.delete();
265278
subscription.delete();
266279
}
280+
281+
@Test
282+
public void testPublisherSubscriber() throws Exception {
283+
TopicName topicName =
284+
TopicName.create(pubsub.getOptions().getProjectId(), formatForTest("test-topic"));
285+
SubscriptionName subscriptionName =
286+
SubscriptionName.create(
287+
pubsub.getOptions().getProjectId(), formatForTest("test-subscription"));
288+
try (PublisherClient publisherClient = PublisherClient.create();
289+
SubscriberClient subscriberClient = SubscriberClient.create()) {
290+
publisherClient.createTopic(topicName);
291+
subscriberClient.createSubscription(
292+
subscriptionName, topicName, PushConfig.getDefaultInstance(), 0);
293+
294+
testPublisherSubscriberHelper(topicName, subscriptionName);
295+
296+
subscriberClient.deleteSubscription(subscriptionName);
297+
publisherClient.deleteTopic(topicName);
298+
}
299+
}
300+
301+
private void testPublisherSubscriberHelper(
302+
TopicName topicName, SubscriptionName subscriptionName) throws Exception {
303+
String messageToPublish = "my-message";
304+
305+
Publisher publisher = null;
306+
try {
307+
publisher = Publisher.newBuilder(topicName).build();
308+
PublisherSnippets snippets = new PublisherSnippets(publisher);
309+
final SettableRpcFuture<Void> done = new SettableRpcFuture<>();
310+
snippets
311+
.publish(messageToPublish)
312+
.addCallback(
313+
new RpcFutureCallback<String>() {
314+
public void onSuccess(String messageId) {
315+
done.set(null);
316+
}
317+
318+
public void onFailure(Throwable t) {
319+
done.setException(t);
320+
}
321+
});
322+
done.get();
323+
} finally {
324+
if (publisher != null) {
325+
publisher.shutdown();
326+
}
327+
}
328+
329+
final BlockingQueue<PubsubMessage> queue = new ArrayBlockingQueue<>(1);
330+
final SettableRpcFuture<Void> done = new SettableRpcFuture<>();
331+
final SettableRpcFuture<PubsubMessage> received = new SettableRpcFuture<>();
332+
SubscriberSnippets snippets =
333+
new SubscriberSnippets(
334+
subscriptionName,
335+
new MessageReceiverSnippets(queue).messageReceiver(),
336+
done,
337+
MoreExecutors.directExecutor());
338+
new Thread(new Runnable() {
339+
@Override
340+
public void run() {
341+
try {
342+
received.set(queue.poll(10, TimeUnit.MINUTES));
343+
} catch (InterruptedException e) {
344+
received.set(null);
345+
}
346+
done.set(null); // signal the subscriber to clean up
347+
}
348+
}).start();
349+
snippets.startAndWait(); // blocks until done is set
350+
351+
PubsubMessage message = received.get();
352+
assertNotNull(message);
353+
assertEquals(message.getData().toStringUtf8(), messageToPublish);
354+
}
267355
}

google-cloud-language/src/main/java/com/google/cloud/language/spi/v1/LanguageServiceClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-language/src/main/java/com/google/cloud/language/spi/v1/LanguageServiceSettings.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -83,6 +83,9 @@ public class LanguageServiceSettings extends ClientSettings {
8383
private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES =
8484
ImmutableList.<String>builder().add("https://www.googleapis.com/auth/cloud-platform").build();
8585

86+
private static final String DEFAULT_GENERATOR_NAME = "gapic";
87+
private static final String DEFAULT_GENERATOR_VERSION = "0.0.5";
88+
8689
private final SimpleCallSettings<AnalyzeSentimentRequest, AnalyzeSentimentResponse>
8790
analyzeSentimentSettings;
8891
private final SimpleCallSettings<AnalyzeEntitiesRequest, AnalyzeEntitiesResponse>
@@ -143,6 +146,7 @@ public static InstantiatingChannelProvider.Builder defaultChannelProviderBuilder
143146
return InstantiatingChannelProvider.newBuilder()
144147
.setServiceAddress(DEFAULT_SERVICE_ADDRESS)
145148
.setPort(DEFAULT_SERVICE_PORT)
149+
.setGeneratorHeader(DEFAULT_GENERATOR_NAME, DEFAULT_GENERATOR_VERSION)
146150
.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
147151
}
148152

google-cloud-language/src/main/java/com/google/cloud/language/spi/v1/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-language/src/test/java/com/google/cloud/language/spi/v1/LanguageServiceClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-language/src/test/java/com/google/cloud/language/spi/v1/MockLanguageService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-language/src/test/java/com/google/cloud/language/spi/v1/MockLanguageServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)