Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
a0fd43a
Initial GAX submission - generated classes only
garrettjonesgoogle Oct 30, 2015
66e176c
Updating README.md to latest form
garrettjonesgoogle Nov 2, 2015
23294dc
Updating version and installation module
garrettjonesgoogle Nov 2, 2015
19da84d
Adding GAX classes
garrettjonesgoogle Nov 3, 2015
a884d58
Adding implicit dependency, using constant instead of hardcoded string
garrettjonesgoogle Nov 4, 2015
e184b32
Initial submission of generated pubsub protobuf classes
garrettjonesgoogle Nov 4, 2015
980ba88
Adding all sections to readme, with TODOs for missing content
garrettjonesgoogle Nov 5, 2015
fce95f9
Generated Pub/Sub client classes and unit tests
garrettjonesgoogle Nov 10, 2015
edd73cc
Fixing source paths and module configuration
garrettjonesgoogle Nov 11, 2015
e26198e
Updates to address PR comments.
garrettjonesgoogle Nov 17, 2015
c291344
More updates to address PR comments
garrettjonesgoogle Nov 19, 2015
6cc6456
Third round of updates to address PR comments
garrettjonesgoogle Nov 20, 2015
48b49b7
Delete duplicate LocalPublisherImpl.java
pongad Nov 30, 2015
34f170c
merge from master
aozarov Feb 5, 2016
1671c0e
disable javadoc generation for java 8 on gcloud-java-pubsub
aozarov Feb 6, 2016
a6be66f
Removing GAX from gcloud-java
garrettjonesgoogle Feb 18, 2016
78179b4
Removing generated files from gcloud-java-pubsub
garrettjonesgoogle Feb 18, 2016
44dd3d2
Switching dependencies, regenerating code
garrettjonesgoogle Feb 18, 2016
c160a25
Using version of GAX compatible with Java 1.7
garrettjonesgoogle Feb 24, 2016
c286b88
Fixing doc problems, improving formatting
garrettjonesgoogle Feb 25, 2016
39b713a
Fixing javadoc error
garrettjonesgoogle Feb 25, 2016
4ab3977
Regenerating code, new settings classes
garrettjonesgoogle Mar 4, 2016
20c9bd3
Updating to GAX 0.0.3
garrettjonesgoogle Mar 8, 2016
f253c54
Surface updates from internal review
garrettjonesgoogle Mar 10, 2016
0b7b39a
Using resurrected ServiceApiSettings in Settings classes
garrettjonesgoogle Mar 11, 2016
7282c7a
Updates due to code gen
garrettjonesgoogle Mar 11, 2016
e2b1969
Removing newSettings() method from XApi classes
garrettjonesgoogle Mar 16, 2016
878ae88
Fixing build from last change
garrettjonesgoogle Mar 16, 2016
7252fca
Putting spi files under spi.v1
garrettjonesgoogle Mar 16, 2016
bece1d4
Bundling descriptor for Publish
garrettjonesgoogle Mar 18, 2016
3c2b7f5
Regenerating (fixing style issues)
garrettjonesgoogle Mar 22, 2016
980d39e
Update with latest surface fixes based Java export review.
shinfan Mar 29, 2016
72b1442
Update pom to fix the dependency issues.
shinfan Mar 29, 2016
ababe05
Update the grpc dependency of pubsub java.
shinfan Mar 29, 2016
7c68c8e
Update pubsub client with latest surface changes. (#885)
shinfan Apr 11, 2016
613a5cc
Rename com.google.gcloud to com.google.cloud (#907)
garrettjonesgoogle Apr 12, 2016
87ff28e
update pubsub pom
aozarov Apr 13, 2016
9b2f341
Update gcloud pubsub. (#951)
shinfan Apr 22, 2016
7c56fc2
Add custom port support to LocalPubsubHelper (#956)
shinfan Apr 25, 2016
2cd4b0c
Add PubSub API prototype and related classes (#962)
mziccard Apr 28, 2016
9ec67ad
Add javadoc and unit tests for TopicInfo (#976)
mziccard May 3, 2016
8586506
Add AsyncPage implementation and docs. Add related tests (#974)
mziccard May 4, 2016
f9a9ed0
Updating pubsub to match gax-java 0.0.12 (#981)
michaelbausor May 5, 2016
05d39cc
Add javadoc and unit tests for SubscriptionInfo (#977)
mziccard May 5, 2016
e9f247b
Update LocalPubsubHelper to be compatible with beta emulators. (#992)
shinfan May 6, 2016
697803f
Add TopicId and SubscriptionId classes (#984)
mziccard May 10, 2016
a427d89
Add base class for operation options, javadoc and tests (#996)
mziccard May 11, 2016
9ae7fda
Add options() method and project name to LocalPubsubHelper (#999)
mziccard May 11, 2016
238c7d1
Add tests and javadoc for Message and ByteArray (#1000)
mziccard May 12, 2016
cb92ee4
Add javadoc and tests for PushConfig (#1004)
mziccard May 12, 2016
916dbb2
Add base service option classes for gRPC and HTTP services (#1011)
mziccard May 16, 2016
4053013
Regenerated pubsub surface (#1009)
michaelbausor May 17, 2016
a9e3873
Implement Pub/Sub management methods, add javadoc and tests (#1015)
mziccard May 22, 2016
47c4c1c
Implement modifyAckDeadline methods, add javadoc and tests (#1022)
mziccard May 25, 2016
ce2ace0
Fix deleted topic name: _deleted_topic_ -> _deleted-topic_ (#1023)
mziccard May 26, 2016
07a45e4
Add javadoc and tests for functional Topic class (#1021)
mziccard May 28, 2016
47046e6
Implement ack and nack methods, add javadoc and tests (#1027)
mziccard Jun 1, 2016
174849f
Add javadoc and tests for functional ReceivedMessage class (#1038)
mziccard Jun 1, 2016
f4e4e26
Add AckDeadlineRenewer class for automatic ack deadline renewal (#1031)
mziccard Jun 3, 2016
54e179c
Implement Iterator pull methods, add javadoc and tests (#1041)
mziccard Jun 6, 2016
337a8ef
Fix PubSub Iterator pullAsync: add callback to PubSubRpc.pull (#1048)
mziccard Jun 14, 2016
f6f552e
Add MessageConsumerImpl class, implement pullAsync, add tests (#1043)
mziccard Jun 22, 2016
d7ac46d
Add serialization test for PubSub classes (#1072)
mziccard Jun 23, 2016
933c985
Add javadoc and tests for Subscription (#1074)
mziccard Jun 24, 2016
fec0e12
Add docs to PubSub spi layer (#1066)
mziccard Jun 24, 2016
57883ae
Add PubSub examples, update READMEs and package-info javadoc (#1075)
mziccard Jun 24, 2016
2553b89
Support setting library header in grpc services (#1078)
mziccard Jun 24, 2016
098ab65
Add integration tests to pubsub (#1080)
mziccard Jun 26, 2016
fb3e663
Update grpc-related dependencies, remove gax dependency from pubsub
mziccard Jun 27, 2016
aefce68
Fix broken link in main README
mziccard Jun 28, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add javadoc and unit tests for SubscriptionInfo (#977)
  • Loading branch information
mziccard committed Jun 27, 2016
commit 05d39cca2fe49f4af203dbadf4741e448cbbd2a4
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.cloud.pubsub.PubSub.MessageConsumer;
import com.google.cloud.pubsub.PubSub.MessageProcessor;
import com.google.cloud.pubsub.PubSub.PullOption;
import com.google.common.base.Function;

import java.io.IOException;
import java.io.ObjectInputStream;
Expand Down Expand Up @@ -103,7 +104,11 @@ public boolean equals(Object obj) {
return false;
}
Subscription other = (Subscription) obj;
return Objects.equals(toPb(), other.toPb()) && Objects.equals(options, other.options);
return Objects.equals(topic(), other.topic())
&& Objects.equals(name(), other.name())
&& Objects.equals(pushConfig(), other.pushConfig())
&& ackDeadlineSeconds() == other.ackDeadlineSeconds()
&& Objects.equals(options, other.options);
}

public PubSub pubSub() {
Expand Down Expand Up @@ -155,4 +160,14 @@ static Subscription fromPb(PubSub storage, com.google.pubsub.v1.Subscription sub
SubscriptionInfo subscriptionInfo = SubscriptionInfo.fromPb(subscriptionPb);
return new Subscription(storage, new BuilderImpl(subscriptionInfo));
}

static Function<com.google.pubsub.v1.Subscription, Subscription> fromPbFunction(
final PubSub pubsub) {
return new Function<com.google.pubsub.v1.Subscription, Subscription>() {
@Override
public Subscription apply(com.google.pubsub.v1.Subscription subscriptionPb) {
return fromPb(pubsub, subscriptionPb);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,35 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.cloud.pubsub.spi.v1.PublisherApi;
import com.google.cloud.pubsub.spi.v1.SubscriberApi;
import com.google.common.base.MoreObjects;

import java.io.Serializable;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
* Pub/Sub subscription information.
* A Google Cloud Pub/Sub subscription. A subscription represents the stream of messages from a
* single, specific topic, to be delivered to the subscribing application. Pub/Sub subscriptions
* support both push and pull message delivery.
*
* <p>In a push subscription, the Pub/Sub server sends a request to the subscriber application, at a
* preconfigured endpoint (see {@link PushConfig}). The subscriber's HTTP response serves as an
* implicit acknowledgement: a success response indicates that the message has been succesfully
* processed and the Pub/Sub system can delete it from the subscription; a non-success response
* indicates that the Pub/Sub server should resend it (implicit "nack").
*
* <p>In a pull subscription, the subscribing application must explicitly pull messages using one of
* {@link PubSub#pull(String, PubSub.PullOption...)},
* {@link PubSub#pullAsync(String, PubSub.MessageProcessor)} or
* {@link PubSub#pullAsync(String, PubSub.PullOption...)}. The subscribing application must then
* explicitly acknowledge the messages using one of {@link PubSub#ack(String, Iterable)},
* {@link PubSub#ack(String, String, String...)}, {@link PubSub#ackAsync(String, Iterable)} or
* {@link PubSub#ackAsync(String, String, String...)}.
*
* @see <a href="https://cloud.google.com/pubsub/overview#data_model">Pub/Sub Data Model</a>
* @see <a href="https://cloud.google.com/pubsub/subscriber">Subscriber Guide</a>
*/
public class SubscriptionInfo implements Serializable {

Expand All @@ -35,20 +57,47 @@ public class SubscriptionInfo implements Serializable {
private final PushConfig pushConfig;
private final int ackDeadlineSeconds;


/**
* Builder for Subscription.
* Builder for {@code SubscriptionInfo} objects.
*/
public abstract static class Builder {

/**
* Sets the name of the subscription. The name must start with a letter, and contain only
* letters ({@code [A-Za-z]}), numbers ({@code [0-9]}), dashes ({@code -}), underscores
* ({@code _}), periods ({@code .}), tildes ({@code ~}), plus ({@code +}) or percent signs
* ({@code %}). It must be between 3 and 255 characters in length and cannot begin with the
* string {@code goog}.
*/
public abstract Builder name(String name);

/**
* Sets the name of the topic the subscription refers to.
*/
public abstract Builder topic(String name);

/**
* Sets the push configuration for the subscription. If set, the subscription will be in
* push mode and the {@code pushConfig} parameter provides the push endpoint. If not set, the
* subscription will be in pull mode.
*/
public abstract Builder pushConfig(PushConfig pushConfig);

/**
* Sets the maximum time after a subscriber receives a message before the subscriber should
* acknowledge the message. After message delivery but before the ack deadline expires and
* before the message is acknowledged, it is an outstanding message and will not be delivered
* again during that time (on a best-effort basis). For pull subscriptions, this value is used
* as the initial value for the ack deadline. To override the ack deadline value for a given
* message, use {@link PubSub#modifyAckDeadline(String, int, TimeUnit, Iterable)}. For push
* delivery, this value is used to set the request timeout for the call to the push endpoint. If
* not specified, the default value of 10 seconds is used.
*/
public abstract Builder ackDeadLineSeconds(int ackDeadLineSeconds);

/**
* Creates a subscription object.
*/
public abstract SubscriptionInfo build();
}

Expand Down Expand Up @@ -108,31 +157,60 @@ public SubscriptionInfo build() {
ackDeadlineSeconds = builder.ackDeadlineSeconds;
}

/**
* Returns the name of the topic this subscription refers to.
*/
public String topic() {
return topic;
}

/**
* Sets the name of the subscription. The name must start with a letter, and contain only
* letters ({@code [A-Za-z]}), numbers ({@code [0-9]}), dashes ({@code -}), underscores
* ({@code _}), periods ({@code .}), tildes ({@code ~}), plus ({@code +}) or percent signs
* ({@code %}). It must be between 3 and 255 characters in length and cannot begin with the
* string {@code goog}.
*/
public String name() {
return name;
}

/**
* Returns the push configuration for the subscription. If set, the subscription is in push mode
* and the returned value defines the push endpoint. If {@code null}, the subscription is in pull
* mode.
*/
public PushConfig pushConfig() {
return pushConfig;
}

/**
* Returns the maximum time after a subscriber receives a message before the subscriber should
* acknowledge the message. After message delivery but before the ack deadline expires and
* before the message is acknowledged, it is an outstanding message and will not be delivered
* again during that time (on a best-effort basis). For pull subscriptions, this value is used
* as the initial value for the ack deadline. To override the ack deadline value for a given
* message, use {@link PubSub#modifyAckDeadline(String, int, TimeUnit, Iterable)}. For push
* delivery, this value is used to set the request timeout for the call to the push endpoint. If
* not specified, the default value of 10 seconds is used.
*/
public long ackDeadlineSeconds() {
return ackDeadlineSeconds;
}

@Override
public boolean equals(Object o) {
if (this == o) {
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (obj == null || !obj.getClass().equals(this.getClass())) {
return false;
}
return Objects.equals(toPb(), ((SubscriptionInfo) o).toPb());
SubscriptionInfo other = (SubscriptionInfo) obj;
return Objects.equals(topic, other.topic)
&& Objects.equals(name, other.name)
&& Objects.equals(pushConfig, other.pushConfig)
&& ackDeadlineSeconds == other.ackDeadlineSeconds;
}

@Override
Expand All @@ -150,11 +228,11 @@ public String toString() {
.toString();
}

com.google.pubsub.v1.Subscription toPb() {
com.google.pubsub.v1.Subscription toPb(String projectId) {
com.google.pubsub.v1.Subscription.Builder builder =
com.google.pubsub.v1.Subscription.newBuilder();
builder.setTopic(topic);
builder.setName(name);
builder.setTopic(PublisherApi.formatTopicName(projectId, topic));
builder.setName(SubscriberApi.formatSubscriptionName(projectId, name));
builder.setAckDeadlineSeconds(ackDeadlineSeconds);
if (pushConfig != null) {
builder.setPushConfig(pushConfig.toPb());
Expand All @@ -163,26 +241,67 @@ com.google.pubsub.v1.Subscription toPb() {
}

static SubscriptionInfo fromPb(com.google.pubsub.v1.Subscription subscription) {
Builder builder = builder(subscription.getTopic(), subscription.getName());
Builder builder = builder(PublisherApi.parseTopicFromTopicName(subscription.getTopic()),
SubscriberApi.parseSubscriptionFromSubscriptionName(subscription.getName()));
builder.ackDeadLineSeconds(subscription.getAckDeadlineSeconds());
if (subscription.hasPushConfig()) {
// A subscription with an "empty" push config is a pull subscription
if (subscription.hasPushConfig()
&& !subscription.getPushConfig().getPushEndpoint().equals("")) {
builder.pushConfig(PushConfig.fromPb(subscription.getPushConfig()));
}
return builder.build();
}

/**
* Returns a builder for the subscription object.
*/
public Builder toBuilder() {
return new BuilderImpl(this);
}

/**
* Creates a pull {@code SubscriptionInfo} object given the name of the topic and the name of the
* subscription.
*
* @param topic the name of the topic the subscription refers to
* @param name the name of the subscription. The name must start with a letter, and contain only
* letters ({@code [A-Za-z]}), numbers ({@code [0-9]}), dashes ({@code -}), underscores
* ({@code _}), periods ({@code .}), tildes ({@code ~}), plus ({@code +}) or percent signs
* ({@code %}). It must be between 3 and 255 characters in length and cannot begin with the
* string {@code goog}
*/
public static SubscriptionInfo of(String topic, String name) {
return builder(topic, name).build();
}

/**
* Creates a push {@code SubscriptionInfo} object given the name of the topic, the name of the
* subscription and the push endpoint.
*
* @param topic the name of the topic the subscription refers to
* @param name the name of the subscription. The name must start with a letter, and contain only
* letters ({@code [A-Za-z]}), numbers ({@code [0-9]}), dashes ({@code -}), underscores
* ({@code _}), periods ({@code .}), tildes ({@code ~}), plus ({@code +}) or percent signs
* ({@code %}). It must be between 3 and 255 characters in length and cannot begin with the
* string {@code goog}
* @param endpoint a URL locating the endpoint to which messages should be pushed. For example,
* an endpoint might use {@code https://example.com/push}.
*/
public static SubscriptionInfo of(String topic, String name, String endpoint) {
return builder(topic, name).pushConfig(PushConfig.of(endpoint)).build();
}

/**
* Creates a builder for {@code SubscriptionInfo} objects given the name of the topic and the name
* of the subscription.
*
* @param topic the name of the topic the subscription refers to
* @param name the name of the subscription. The name must start with a letter, and contain only
* letters ({@code [A-Za-z]}), numbers ({@code [0-9]}), dashes ({@code -}), underscores
* ({@code _}), periods ({@code .}), tildes ({@code ~}), plus ({@code +}) or percent signs
* ({@code %}). It must be between 3 and 255 characters in length and cannot begin with the
* string {@code goog}
*/
public static Builder builder(String topic, String name) {
return new BuilderImpl(topic, name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ static TopicInfo fromPb(com.google.pubsub.v1.Topic topicPb) {
return builder(PublisherApi.parseTopicFromTopicName(topicPb.getName())).build();
}

/**
* Returns a builder for the topic object.
*/
public Builder toBuilder() {
return new BuilderImpl(this);
}
Expand All @@ -137,7 +140,7 @@ public Builder toBuilder() {
* ({@code [A-Za-z]}), numbers ({@code [0-9]}), dashes ({@code -}), underscores ({@code _}),
* periods ({@code .}), tildes ({@code ~}), plus ({@code +}) or percent signs ({@code %}).
* It must be between 3 and 255 characters in length and cannot begin with the string
* {@code goog}.
* {@code goog}
*/
public static TopicInfo of(String name) {
return builder(name).build();
Expand All @@ -150,7 +153,7 @@ public static TopicInfo of(String name) {
* ({@code [A-Za-z]}), numbers ({@code [0-9]}), dashes ({@code -}), underscores ({@code _}),
* periods ({@code .}), tildes ({@code ~}), plus ({@code +}) or percent signs ({@code %}).
* It must be between 3 and 255 characters in length and cannot begin with the string
* {@code goog}.
* {@code goog}
*/
public static Builder builder(String name) {
return new BuilderImpl(name);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.pubsub;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import org.junit.Test;

public class SubscriptionInfoTest {

private static final String TOPIC = "topic";
private static final String NAME = "subscription";
private static final String ENDPOINT = "https://example.com/push";
private static final PushConfig PUSH_CONFIG = PushConfig.of(ENDPOINT);
private static final int ACK_DEADLINE = 42;
private static final SubscriptionInfo SUBSCRIPTION_INFO = SubscriptionInfo.builder(TOPIC, NAME)
.pushConfig(PUSH_CONFIG)
.ackDeadLineSeconds(ACK_DEADLINE)
.build();

@Test
public void testToBuilder() {
compareSubscriptionInfo(SUBSCRIPTION_INFO, SUBSCRIPTION_INFO.toBuilder().build());
SubscriptionInfo subscriptionInfo = SUBSCRIPTION_INFO.toBuilder()
.topic("newTopic")
.name("newSubscription")
.build();
assertEquals("newTopic", subscriptionInfo.topic());
assertEquals("newSubscription", subscriptionInfo.name());
subscriptionInfo = subscriptionInfo.toBuilder().name(NAME).topic(TOPIC).build();
compareSubscriptionInfo(SUBSCRIPTION_INFO, subscriptionInfo);
}

@Test
public void testBuilder() {
assertEquals(TOPIC, SUBSCRIPTION_INFO.topic());
assertEquals(NAME, SUBSCRIPTION_INFO.name());
assertEquals(PUSH_CONFIG, SUBSCRIPTION_INFO.pushConfig());
assertEquals(ACK_DEADLINE, SUBSCRIPTION_INFO.ackDeadlineSeconds());
}

@Test
public void testOf() {
SubscriptionInfo subscriptionInfo = SubscriptionInfo.of(TOPIC, NAME);
assertEquals(TOPIC, subscriptionInfo.topic());
assertEquals(NAME, subscriptionInfo.name());
assertNull(subscriptionInfo.pushConfig());
assertEquals(0, subscriptionInfo.ackDeadlineSeconds());
subscriptionInfo = SubscriptionInfo.of(TOPIC, NAME, ENDPOINT);
assertEquals(TOPIC, subscriptionInfo.topic());
assertEquals(NAME, subscriptionInfo.name());
assertEquals(PushConfig.of(ENDPOINT), subscriptionInfo.pushConfig());
assertEquals(0, subscriptionInfo.ackDeadlineSeconds());
}

@Test
public void testToAndFromPb() {
compareSubscriptionInfo(SUBSCRIPTION_INFO,
SubscriptionInfo.fromPb(SUBSCRIPTION_INFO.toPb("project")));
SubscriptionInfo subscriptionInfo = SubscriptionInfo.of(TOPIC, NAME);
compareSubscriptionInfo(subscriptionInfo,
SubscriptionInfo.fromPb(subscriptionInfo.toPb("project")));
subscriptionInfo = SubscriptionInfo.of(TOPIC, NAME, ENDPOINT);
compareSubscriptionInfo(subscriptionInfo,
SubscriptionInfo.fromPb(subscriptionInfo.toPb("project")));
}

private void compareSubscriptionInfo(SubscriptionInfo expected, SubscriptionInfo value) {
assertEquals(expected, value);
assertEquals(expected.topic(), value.topic());
assertEquals(expected.name(), value.name());
assertEquals(expected.pushConfig(), value.pushConfig());
assertEquals(expected.ackDeadlineSeconds(), value.ackDeadlineSeconds());
assertEquals(expected.hashCode(), value.hashCode());
}
}