Skip to content

Commit f0fad1e

Browse files
committed
---
yaml --- r: 4811 b: refs/heads/logging-alpha c: 215a5df h: refs/heads/master i: 4809: 97178da 4807: b6bc04e
1 parent 82bb5c5 commit f0fad1e

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
@@ -12,7 +12,7 @@ refs/heads/compute-alpha: 969cba2627f1d53d352cc4a5ffe0879dacf65e6c
1212
refs/heads/dns-alpha: 2f90e7e338349287ace33375896907af0f032ca1
1313
refs/heads/dns-alpha-batch: 17442b07867021b85d0452f5f3eda29a3413288f
1414
refs/heads/gcs-nio: 283aeaf15efdcf3621eb6859f05e55ad7764375d
15-
refs/heads/logging-alpha: cd848c0ff6edc1da9965e853219bfb72837fd37e
15+
refs/heads/logging-alpha: 215a5dfd611a58a2a2114fae84c69515597d002e
1616
refs/tags/v0.1.0: a615317f7424ed58621b1f65d5c4d8cbbe8a6ed8
1717
refs/tags/v0.1.1: 7a7f6985fe465e9dd6a075af55493f42b4933be0
1818
refs/tags/v0.1.2: 3eb3fe866ba22487686048f45d927b8c8638ea3f

branches/logging-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)