Skip to content

Commit 5b4d511

Browse files
committed
---
yaml --- r: 3879 b: refs/heads/pubsub-alpha c: 215a5df h: refs/heads/master i: 3877: dc5a4d1 3875: a862147 3871: a42883d
1 parent 6209238 commit 5b4d511

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 36a62ef856d199f8efd09501b5ba65c422c01f23
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 7406918e071dd2c5677a638ae2a06e7592b6542c
5-
refs/heads/pubsub-alpha: cd848c0ff6edc1da9965e853219bfb72837fd37e
5+
refs/heads/pubsub-alpha: 215a5dfd611a58a2a2114fae84c69515597d002e
66
refs/heads/update-datastore: 47aae517c2cb33f1dccd909adaced73ec9d0f4df
77
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444
88
refs/tags/v0.0.10: 207ebd2a3472fddee69fe1298eb90429e3306efd

branches/pubsub-alpha/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/testing/LocalPubsubHelper.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,21 @@
1919
import com.google.api.gax.testing.DownloadableEmulatorRunner;
2020
import com.google.api.gax.testing.GCloudEmulatorRunner;
2121
import com.google.api.gax.testing.LocalServiceHelper;
22-
23-
import io.grpc.ManagedChannel;
24-
import io.grpc.netty.NegotiationType;
25-
import io.grpc.netty.NettyChannelBuilder;
22+
import com.google.cloud.AuthCredentials;
23+
import com.google.cloud.RetryParams;
24+
import com.google.cloud.pubsub.PubSubOptions;
2625

2726
import java.io.IOException;
2827
import java.net.MalformedURLException;
2928
import java.net.URL;
3029
import java.util.ArrayList;
3130
import java.util.Arrays;
3231
import java.util.List;
32+
import java.util.UUID;
33+
34+
import io.grpc.ManagedChannel;
35+
import io.grpc.netty.NegotiationType;
36+
import io.grpc.netty.NettyChannelBuilder;
3337

3438
/**
3539
* A class that runs a Pubsub emulator instance for use in tests.
@@ -38,11 +42,13 @@ public class LocalPubsubHelper {
3842

3943
private final int port;
4044
private final LocalServiceHelper serviceHelper;
45+
private final String projectId;
4146

4247
// Local server settings
4348
private static final int DEFAULT_PORT = 8080;
4449
private static final String DEFAULT_HOST = "localhost";
4550
private static final URL EMULATOR_URL;
51+
private static final String PROJECT_ID_PREFIX = "test-project-";
4652

4753
// GCloud emulator settings
4854
private static final String GCLOUD_CMD_TEXT = "gcloud beta emulators pubsub start";
@@ -77,8 +83,8 @@ public LocalPubsubHelper() {
7783
DownloadableEmulatorRunner downloadRunner =
7884
new DownloadableEmulatorRunner(Arrays.asList(BIN_NAME, BIN_CMD_PORT_FLAG + port),
7985
EMULATOR_URL, MD5_CHECKSUM);
80-
serviceHelper =
81-
new LocalServiceHelper(Arrays.asList(gcloudRunner, downloadRunner), port);
86+
serviceHelper = new LocalServiceHelper(Arrays.asList(gcloudRunner, downloadRunner), port);
87+
projectId = PROJECT_ID_PREFIX + UUID.randomUUID().toString();
8288
}
8389

8490
/**
@@ -121,4 +127,17 @@ public ManagedChannel createChannel() {
121127
.negotiationType(NegotiationType.PLAINTEXT)
122128
.build();
123129
}
130+
131+
/**
132+
* Returns a {@link PubSubOptions} instance that sets the host to use the PubSub emulator on
133+
* localhost.
134+
*/
135+
public PubSubOptions options() {
136+
return PubSubOptions.builder()
137+
.projectId(projectId)
138+
.host("localhost:" + port)
139+
.authCredentials(AuthCredentials.noAuth())
140+
.retryParams(RetryParams.noRetries())
141+
.build();
142+
}
124143
}

0 commit comments

Comments
 (0)