Skip to content

Commit 58ca576

Browse files
garrettjonesgooglemziccard
authored andcommitted
---
yaml --- r: 7317 b: refs/heads/tswast-patch-1 c: c291344 h: refs/heads/master i: 7315: 00cfc21
1 parent caa13a8 commit 58ca576

6 files changed

Lines changed: 61 additions & 26 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: e26198e899eb26a1c283046fc35b08fb63a76d6d
60+
refs/heads/tswast-patch-1: c2913449758390054576d34dab4081716ece4a17
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/PublisherApi.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import io.gapi.gax.grpc.ServiceApiSettings;
5050
import io.gapi.gax.internal.ApiUtils;
5151
import io.gapi.gax.protobuf.PathTemplate;
52-
import io.grpc.Channel;
5352
import io.grpc.ManagedChannel;
5453

5554
import java.io.IOException;
@@ -151,14 +150,14 @@ public Iterable<String> extractResources(ListTopicSubscriptionsResponse payload)
151150
* A PathTemplate representing the fully-qualified path to represent
152151
* a project resource.
153152
*/
154-
public static final PathTemplate PROJECT_PATH_TEMPLATE =
153+
private static final PathTemplate PROJECT_PATH_TEMPLATE =
155154
PathTemplate.create("/projects/{project}");
156155

157156
/**
158157
* A PathTemplate representing the fully-qualified path to represent
159158
* a topic resource.
160159
*/
161-
public static final PathTemplate TOPIC_PATH_TEMPLATE =
160+
private static final PathTemplate TOPIC_PATH_TEMPLATE =
162161
PathTemplate.create("/projects/{project}/topics/{topic}");
163162

164163
// ========
@@ -220,13 +219,28 @@ public static final String createTopicPath(String project, String topic) {
220219
"project", project,"topic", topic);
221220
}
222221

222+
/**
223+
* Extracts the project from the given fully-qualified path which
224+
* represents a project resource.
225+
*/
226+
public static final String extractProjectFromProjectPath(String projectPath) {
227+
return PROJECT_PATH_TEMPLATE.parse(projectPath).get("project");
228+
}
223229

224-
// ========
225-
// Getters
226-
// ========
230+
/**
231+
* Extracts the project from the given fully-qualified path which
232+
* represents a topic resource.
233+
*/
234+
public static final String extractProjectFromTopicPath(String topicPath) {
235+
return TOPIC_PATH_TEMPLATE.parse(topicPath).get("project");
236+
}
227237

228-
public Channel getChannel() {
229-
return channel;
238+
/**
239+
* Extracts the topic from the given fully-qualified path which
240+
* represents a topic resource.
241+
*/
242+
public static final String extractTopicFromTopicPath(String topicPath) {
243+
return TOPIC_PATH_TEMPLATE.parse(topicPath).get("topic");
230244
}
231245

232246

branches/tswast-patch-1/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/SubscriberApi.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import io.gapi.gax.grpc.ServiceApiSettings;
5151
import io.gapi.gax.internal.ApiUtils;
5252
import io.gapi.gax.protobuf.PathTemplate;
53-
import io.grpc.Channel;
5453
import io.grpc.ManagedChannel;
5554

5655
import java.io.IOException;
@@ -132,14 +131,14 @@ public Iterable<Subscription> extractResources(ListSubscriptionsResponse payload
132131
* A PathTemplate representing the fully-qualified path to represent
133132
* a project resource.
134133
*/
135-
public static final PathTemplate PROJECT_PATH_TEMPLATE =
134+
private static final PathTemplate PROJECT_PATH_TEMPLATE =
136135
PathTemplate.create("/projects/{project}");
137136

138137
/**
139138
* A PathTemplate representing the fully-qualified path to represent
140139
* a subscription resource.
141140
*/
142-
public static final PathTemplate SUBSCRIPTION_PATH_TEMPLATE =
141+
private static final PathTemplate SUBSCRIPTION_PATH_TEMPLATE =
143142
PathTemplate.create("/projects/{project}/subscriptions/{subscription}");
144143

145144
// ========
@@ -168,7 +167,11 @@ public static SubscriberApi create(ServiceApiSettings settings) throws IOExcepti
168167
return new SubscriberApi(settings);
169168
}
170169

171-
private SubscriberApi(ServiceApiSettings settings) throws IOException {
170+
/**
171+
* Constructs an instance of SubscriberApi, using the given settings. This is protected so that it
172+
* easy to make a subclass, but otherwise, the static factory methods should be preferred.
173+
*/
174+
protected SubscriberApi(ServiceApiSettings settings) throws IOException {
172175
ServiceApiSettings internalSettings = ApiUtils.settingsWithChannels(settings,
173176
SERVICE_ADDRESS, DEFAULT_SERVICE_PORT, ALL_SCOPES);
174177
this.settings = internalSettings;
@@ -197,13 +200,28 @@ public static final String createSubscriptionPath(String project, String subscri
197200
"project", project,"subscription", subscription);
198201
}
199202

203+
/**
204+
* Extracts the project from the given fully-qualified path which
205+
* represents a project resource.
206+
*/
207+
public static final String extractProjectFromProjectPath(String projectPath) {
208+
return PROJECT_PATH_TEMPLATE.parse(projectPath).get("project");
209+
}
200210

201-
// ========
202-
// Getters
203-
// ========
211+
/**
212+
* Extracts the project from the given fully-qualified path which
213+
* represents a subscription resource.
214+
*/
215+
public static final String extractProjectFromSubscriptionPath(String subscriptionPath) {
216+
return SUBSCRIPTION_PATH_TEMPLATE.parse(subscriptionPath).get("project");
217+
}
204218

205-
public Channel getChannel() {
206-
return channel;
219+
/**
220+
* Extracts the subscription from the given fully-qualified path which
221+
* represents a subscription resource.
222+
*/
223+
public static final String extractSubscriptionFromSubscriptionPath(String subscriptionPath) {
224+
return SUBSCRIPTION_PATH_TEMPLATE.parse(subscriptionPath).get("subscription");
207225
}
208226

209227

branches/tswast-patch-1/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/testing/LocalPublisherImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public void getTopic(GetTopicRequest request, StreamObserver<Topic> responseObse
7777
public void listTopics(ListTopicsRequest request, StreamObserver<ListTopicsResponse> responseObserver) {
7878
List<Topic> responseTopics = new ArrayList<>();
7979
for (String topicName : topics.keySet()) {
80-
String projectOfTopic = PublisherApi.TOPIC_PATH_TEMPLATE.parse(topicName).get("project");
81-
String projectOfRequest = PublisherApi.PROJECT_PATH_TEMPLATE.parse(request.getProject()).get("project");
80+
String projectOfTopic = PublisherApi.extractProjectFromTopicPath(topicName);
81+
String projectOfRequest = PublisherApi.extractProjectFromProjectPath(request.getProject());
8282
if (projectOfTopic.equals(projectOfRequest)) {
8383
Topic topicObj = Topic.newBuilder().setName(topicName).build();
8484
responseTopics.add(topicObj);

branches/tswast-patch-1/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/testing/LocalPubsubHelper.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,22 @@
1919
* A class that runs an in-memory Publisher instance for use in tests.
2020
*/
2121
public class LocalPubsubHelper {
22-
private static final SocketAddress address = new LocalAddress("in-process-1");
23-
private static Server server;
24-
private static LocalPublisherImpl publisherImpl;
22+
private static int FLOW_CONTROL_WINDOW = 65 * 1024;
23+
24+
private final SocketAddress address;
25+
private final Server server;
26+
private final LocalPublisherImpl publisherImpl;
2527

2628
/**
2729
* Constructs a new LocalPubsubHelper. The method start() must
2830
* be called before it is used.
2931
*/
30-
public LocalPubsubHelper() {
32+
public LocalPubsubHelper(String addressString) {
33+
address = new LocalAddress(addressString);
3134
publisherImpl = new LocalPublisherImpl();
3235
NettyServerBuilder builder = NettyServerBuilder
3336
.forAddress(address)
34-
.flowControlWindow(65 * 1024)
37+
.flowControlWindow(FLOW_CONTROL_WINDOW)
3538
.channelType(LocalServerChannel.class);
3639
builder.addService(PublisherGrpc.bindService(publisherImpl));
3740
server = builder.build();

branches/tswast-patch-1/gcloud-java-pubsub/src/test/java/com/google/gcloud/pubsub/spi/PublisherApiTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class PublisherApiTest {
3838

3939
@BeforeClass
4040
public static void startStaticServer() {
41-
pubsubHelper = new LocalPubsubHelper().start();
41+
pubsubHelper = new LocalPubsubHelper("in-process-1").start();
4242
}
4343

4444
@AfterClass

0 commit comments

Comments
 (0)