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 tests for PushConfig (#1004)
  • Loading branch information
mziccard committed Jun 27, 2016
commit cb92ee4c402f8d735b2fb792ff431b221c39a416
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public abstract static class Builder {
abstract Builder publishTime(long publishTime);

/**
* Creates a topic object.
* Creates a message object.
*/
public abstract Message build();
}
Expand Down
156 changes: 141 additions & 15 deletions gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/PushConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@
import java.util.Objects;

/**
* PubSub subscription push configuration.
* Google Cloud Pub/Sub configuration for a push subscription.
*
* <p>In a push subscription, the Pub/Sub server sends a request to the subscriber application. A
* {@code PushConfig} object can be used to configure the application endpoint. 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").
*
* @see <a href="https://cloud.google.com/pubsub/subscriber">Subscriber Guide</a>
*/
public final class PushConfig implements Serializable {

Expand All @@ -36,34 +45,97 @@ public final class PushConfig implements Serializable {
private final String endpoint;
private final ImmutableMap<String, String> attributes;

/**
* Builder for {@code PushConfig} objects.
*/
public static final class Builder {

private String endpoint;
private final Map<String, String> attributes = new HashMap<>();
private Map<String, String> attributes = new HashMap<>();

private Builder() {
}

public Builder endPoint(String endpoint) {
/**
* Sets the URL locating the endpoint to which messages should be pushed. For example, an
* endpoint might use {@code https://example.com/push}.
*/
public Builder endpoint(String endpoint) {
this.endpoint = checkNotNull(endpoint);
return this;
}

/**
* Adds an API-supported attribute that can be used to control different aspects of the message
* delivery.
*
* <p>The currently supported attribute is {@code x-goog-version}, which can be used to change
* the format of the push message. This attribute indicates the version of the data expected by
* the endpoint. The endpoint version is based on the version of the Pub/Sub API. Possible
* values for this attribute are:
* <ul>
* <li>{@code v1beta1}: uses the push format defined in the v1beta1 Pub/Sub API
* <li>{@code v1} or {@code v1beta2}: uses the push format defined in the v1 Pub/Sub API
* </ul>
*
* <p>If the {@code x-goog-version} attribute is not present when a subscription is created (see
* {@link PubSub#create(SubscriptionInfo)} and {@link PubSub#createAsync(SubscriptionInfo)}), it
* will default to {@code v1}. If it is not present when modifying the push config (see
* {@link PubSub#replacePushConfig(String, PushConfig)} and
* {@link PubSub#replacePushConfigAsync(String, PushConfig)}), its value will not be changed.
*
* @see <a href="https://cloud.google.com/pubsub/subscriber#msg-format">Message Format</a>
*/
public Builder addAttribute(String name, String value) {
attributes.put(name, value);
return this;
}

/**
* Sets the API-supported attributes that can be used to control different aspects of the
* message delivery.
*
* <p>The currently supported attribute is {@code x-goog-version}, which can be used to change
* the format of the push message. This attribute indicates the version of the data expected by
* the endpoint. The endpoint version is based on the version of the Pub/Sub API. Possible
* values for this attribute are:
* <ul>
* <li>{@code v1beta1}: uses the push format defined in the v1beta1 Pub/Sub API
* <li>{@code v1} or {@code v1beta2}: uses the push format defined in the v1 Pub/Sub API
* </ul>
*
* <p>If the {@code x-goog-version} attribute is not present when a subscription is created (see
* {@link PubSub#create(SubscriptionInfo)} and {@link PubSub#createAsync(SubscriptionInfo)}), it
* will default to {@code v1}. If it is not present when modifying the push config (see
* {@link PubSub#replacePushConfig(String, PushConfig)} and
* {@link PubSub#replacePushConfigAsync(String, PushConfig)}), its value will not be changed.
*
* @see <a href="https://cloud.google.com/pubsub/subscriber#msg-format">Message Format</a>
*/
public Builder attributes(Map<String, String> attributes) {
this.attributes = new HashMap<>(attributes);
return this;
}

/**
* Removes an API-supported attribute.
*/
public Builder removeAttribute(String name) {
attributes.remove(name);
return this;
}

/**
* Clears all API-supported attributes.
*/
public Builder clearAttributes() {
attributes.clear();
return this;
}

/**
* Creates a {@code PushConfig} object.
*/
public PushConfig build() {
return new PushConfig(this);
}
Expand All @@ -74,24 +146,49 @@ private PushConfig(Builder builder) {
attributes = ImmutableMap.copyOf(builder.attributes);
}

/**
* Returns the URL locating the endpoint to which messages should be pushed. For example, an
* endpoint might use {@code https://example.com/push}.
*/
public String endpoint() {
return endpoint;
}

/**
* Returns the API-supported attributes that can be used to control different aspects of the
* message delivery.
*
* <p>The currently supported attribute is {@code x-goog-version}, which can be used to change
* the format of the push message. This attribute indicates the version of the data expected by
* the endpoint. The endpoint version is based on the version of the Pub/Sub API. Possible
* values for this attribute are:
* <ul>
* <li>{@code v1beta1}: uses the push format defined in the v1beta1 Pub/Sub API
* <li>{@code v1} or {@code v1beta2}: uses the push format defined in the v1 Pub/Sub API
* </ul>
*
* <p>If the {@code x-goog-version} attribute is not present when a subscription is created (see
* {@link PubSub#create(SubscriptionInfo)} and {@link PubSub#createAsync(SubscriptionInfo)}), it
* will default to {@code v1}. If it is not present when modifying the push config (see
* {@link PubSub#replacePushConfig(String, PushConfig)} and
* {@link PubSub#replacePushConfigAsync(String, PushConfig)}), its value will not be changed.
*
* @see <a href="https://cloud.google.com/pubsub/subscriber#msg-format">Message Format</a>
*/
public Map<String, String> attributes() {
return attributes;
}

@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 instanceof PushConfig)) {
return false;
}
PushConfig that = (PushConfig) o;
return Objects.equals(endpoint, that.endpoint) && Objects.equals(attributes, that.attributes);
PushConfig other = (PushConfig) obj;
return Objects.equals(endpoint, other.endpoint) && Objects.equals(attributes, other.attributes);
}

@Override
Expand All @@ -107,28 +204,57 @@ public String toString() {
.toString();
}

/**
* Returns a builder for the {@code PushConfig} object.
*/
public Builder toBuilder() {
return builder(endpoint, attributes);
}

/**
* Creates a {@code PushConfig} object given the push endpoint.
*
* @param endpoint the URL locating the endpoint to which messages should be pushed. For example,
* an endpoint might use {@code https://example.com/push}.
*/
public static PushConfig of(String endpoint) {
return builder(endpoint).build();
}

/**
* Creates a {@code PushConfig} object given the push endpoint and the API-supported attributes
* that can be used to control different aspects of the message delivery.
*
* @param endpoint the URL locating the endpoint to which messages should be pushed. For example,
* an endpoint might use {@code https://example.com/push}.
* @param attributes API supported attributes used to control message delivery. See
* {@link Builder#attributes(Map)} for more details.
*/
public static PushConfig of(String endpoint, Map<String, String> attributes) {
return builder(endpoint, attributes).build();
}

public static Builder builder(String endPoint) {
return new Builder().endPoint(endPoint);
/**
* Creates a builder for {@code PushConfig} objects given the push endpoint.
*
* @param endpoint the URL locating the endpoint to which messages should be pushed. For example,
* an endpoint might use {@code https://example.com/push}.
*/
public static Builder builder(String endpoint) {
return new Builder().endpoint(endpoint);
}

/**
* Creates a builder for {@code PushConfig} objects given the push endpoint and the API-supported
* attributes that can be used to control different aspects of the message delivery.
*
* @param endpoint the URL locating the endpoint to which messages should be pushed. For example,
* an endpoint might use {@code https://example.com/push}.
* @param attributes API supported attributes used to control message delivery. See
* {@link Builder#attributes(Map)} for more details.
*/
public static Builder builder(String endpoint, Map<String, String> attributes) {
Builder builder = builder(endpoint);
for (Map.Entry<String, String> entry : attributes.entrySet()) {
builder.addAttribute(entry.getKey(), entry.getValue());
}
return builder;
return builder(endpoint).attributes(attributes);
}

com.google.pubsub.v1.PushConfig toPb() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public void testToBuilder() {
.build();
assertEquals("newPayload", message.payloadAsString());
assertEquals(ImmutableMap.of("key1", "value1"), message.attributes());
message = MESSAGE.toBuilder().payload(PAYLOAD_STRING).attributes(ATTRIBUTES).build();
message = message.toBuilder()
.payload(PAYLOAD_STRING)
.removeAttribute("key1")
.attributes(ATTRIBUTES)
.build();
compareMessage(MESSAGE, message);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* 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 com.google.common.collect.ImmutableMap;

import org.junit.Test;

import java.util.Map;

public class PushConfigTest {

private static final String ENDPOINT = "https://example.com/push";
private static final Map<String, String> ATTRIBUTES =
ImmutableMap.of("key1", "value1", "key2", "value2");
private static final PushConfig PUSH_CONFIG = PushConfig.builder(ENDPOINT, ATTRIBUTES).build();

@Test
public void testToBuilder() {
comparePushConfig(PUSH_CONFIG, PUSH_CONFIG.toBuilder().build());
PushConfig pushConfig = PUSH_CONFIG.toBuilder()
.endpoint("https://example2.com/push")
.clearAttributes()
.addAttribute("key1", "value1")
.build();
assertEquals("https://example2.com/push", pushConfig.endpoint());
assertEquals(ImmutableMap.of("key1", "value1"), pushConfig.attributes());
pushConfig = pushConfig.toBuilder()
.endpoint(ENDPOINT)
.removeAttribute("key1")
.attributes(ATTRIBUTES)
.build();
comparePushConfig(PUSH_CONFIG, pushConfig);
}

@Test
public void testBuilder() {
assertEquals(ENDPOINT, PUSH_CONFIG.endpoint());
assertEquals(ATTRIBUTES, PUSH_CONFIG.attributes());
PushConfig pushConfig = PushConfig.builder("https://example2.com/push")
.endpoint(ENDPOINT)
.attributes(ATTRIBUTES)
.clearAttributes()
.addAttribute("key1", "value1")
.addAttribute("key2", "value2")
.build();
assertEquals(ENDPOINT, pushConfig.endpoint());
assertEquals(ATTRIBUTES, pushConfig.attributes());
comparePushConfig(PUSH_CONFIG, pushConfig);
}

@Test
public void testOf() {
PushConfig pushConfig = PushConfig.of(ENDPOINT);
assertEquals(ENDPOINT, pushConfig.endpoint());
assertEquals(ImmutableMap.of(), pushConfig.attributes());
pushConfig = PushConfig.of(ENDPOINT, ATTRIBUTES);
assertEquals(ENDPOINT, pushConfig.endpoint());
assertEquals(ATTRIBUTES, pushConfig.attributes());
comparePushConfig(PUSH_CONFIG, pushConfig);
}

@Test
public void testToAndFromPb() {
comparePushConfig(PUSH_CONFIG, PushConfig.fromPb(PUSH_CONFIG.toPb()));
}

@Test
public void testToAndFromPbIncomplete() {
PushConfig pushConfig = PushConfig.of(ENDPOINT);
comparePushConfig(pushConfig, PushConfig.fromPb(pushConfig.toPb()));
}

private void comparePushConfig(PushConfig expected, PushConfig value) {
assertEquals(expected, value);
assertEquals(expected.endpoint(), value.endpoint());
assertEquals(expected.attributes(), value.attributes());
assertEquals(expected.hashCode(), value.hashCode());
}
}