Skip to content

Commit 738a280

Browse files
jartmziccard
authored andcommitted
---
yaml --- r: 7385 b: refs/heads/tswast-patch-1 c: affed4d h: refs/heads/master i: 7383: 4a58aa3
1 parent a2fe062 commit 738a280

40 files changed

Lines changed: 5127 additions & 107 deletions

[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: a09e00c5dcc38359f6622c31cae861e1c8d792dd
60+
refs/heads/tswast-patch-1: affed4d676fc8b42a35ec4007aea87e336a6c999
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/TESTING.md

Lines changed: 74 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,10 @@
22

33
This library provides tools to help write tests for code that uses the following gcloud-java services:
44

5-
- [BigQuery] (#testing-code-that-uses-bigquery)
6-
- [Compute] (#testing-code-that-uses-compute)
75
- [Datastore] (#testing-code-that-uses-datastore)
8-
- [DNS] (#testing-code-that-uses-dns)
9-
- [PubSub] (#testing-code-that-uses-pubsub)
10-
- [Resource Manager] (#testing-code-that-uses-resource-manager)
116
- [Storage] (#testing-code-that-uses-storage)
12-
13-
### Testing code that uses BigQuery
14-
15-
Currently, there isn't an emulator for Google BigQuery, so an alternative is to create a test
16-
project. `RemoteBigQueryHelper` contains convenience methods to make setting up and cleaning up the
17-
test project easier. To use this class, follow the steps below:
18-
19-
1. Create a test Google Cloud project.
20-
21-
2. Download a [JSON service account credentials file][create-service-account] from the Google
22-
Developer's Console.
23-
24-
3. Create a `RemoteBigQueryHelper` object using your project ID and JSON key.
25-
Here is an example that uses the `RemoteBigQueryHelper` to create a dataset.
26-
```java
27-
RemoteBigQueryHelper bigqueryHelper =
28-
RemoteBigQueryHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
29-
BigQuery bigquery = bigqueryHelper.options().service();
30-
String dataset = RemoteBigQueryHelper.generateDatasetName();
31-
bigquery.create(DatasetInfo.builder(dataset).build());
32-
```
33-
34-
4. Run your tests.
35-
36-
5. Clean up the test project by using `forceDelete` to clear any datasets used.
37-
Here is an example that clears the dataset created in Step 3.
38-
```java
39-
RemoteBigQueryHelper.forceDelete(bigquery, dataset);
40-
```
41-
42-
### Testing code that uses Compute
43-
44-
Currently, there isn't an emulator for Google Compute, so an alternative is to create a test
45-
project. `RemoteComputeHelper` contains convenience methods to make setting up the test project
46-
easier. To use this class, follow the steps below:
47-
48-
1. Create a test Google Cloud project.
49-
50-
2. Download a [JSON service account credentials file][create-service-account] from the Google
51-
Developer's Console.
52-
53-
3. Create a `RemoteComputeHelper` object using your project ID and JSON key. Here is an example that
54-
uses the `RemoteComputeHelper` to create an address.
55-
```java
56-
RemoteComputeHelper computeHelper =
57-
RemoteBigQueryHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
58-
Compute compute = computeHelper.options().service();
59-
// Pick a name for the resource with low probability of clashing
60-
String addressName = RemoteComputeHelper.baseResourceName() + "address";
61-
AddressId addressId = RegionAddressId.of(REGION, addressName);
62-
AddressInfo addressInfo = AddressInfo.of(addressId);
63-
Operation operation = compute.create(addressInfo);
64-
```
65-
66-
4. Run your tests.
7+
- [Resource Manager] (#testing-code-that-uses-resource-manager)
8+
- [BigQuery] (#testing-code-that-uses-bigquery)
679

6810
### Testing code that uses Datastore
6911

@@ -146,45 +88,30 @@ You can test against an in-memory local DNS by following these steps:
14688

14789
This method will block until the server thread has been terminated.
14890

149-
### Testing code that uses Pub/Sub
150-
151-
#### On your machine
152-
153-
You can test against a temporary local Pub/Sub by following these steps:
154-
155-
1. Start the local Pub/Sub emulator before running your tests using `LocalPubSubHelper`'s `create`
156-
and `start` methods. This will bind a port for communication with the local Pub/Sub emulator.
157-
```java
158-
LocalPubSubHelper helper = LocalPubSubHelper.create();
91+
### Testing code that uses Storage
15992

160-
helper.start(); // Starts the local Pub/Sub emulator in a separate process
161-
```
93+
Currently, there isn't an emulator for Google Cloud Storage, so an alternative is to create a test project. `RemoteStorageHelper` contains convenience methods to make setting up and cleaning up the test project easier. To use this class, follow the steps below:
16294

163-
2. Create and use a `PubSub` object with the options given by the `LocalPubSubHelper` instance. For
164-
example:
165-
```java
166-
PubSub localPubsub = helper.options().service();
167-
```
95+
1. Create a test Google Cloud project.
16896

169-
3. Run your tests.
97+
2. Download a JSON service account credentials file from the Google Developer's Console. See more about this on the [Google Cloud Platform Storage Authentication page][cloud-platform-storage-authentication].
17098

171-
4. Stop the local Pub/Sub emulator by calling the `stop()` method, like so:
99+
3. Create a `RemoteStorageHelper` object using your project ID and JSON key.
100+
Here is an example that uses the `RemoteStorageHelper` to create a bucket.
172101
```java
173-
helper.stop();
102+
RemoteStorageHelper helper =
103+
RemoteStorageHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
104+
Storage storage = helper.options().service();
105+
String bucket = RemoteStorageHelper.generateBucketName();
106+
storage.create(BucketInfo.of(bucket));
174107
```
175108

176-
#### On a remote machine
177-
178-
You can test against a remote Pub/Sub emulator as well. To do this, set the `PubSubOptions` project
179-
endpoint to the hostname of the remote machine, like the example below.
109+
4. Run your tests.
180110

111+
5. Clean up the test project by using `forceDelete` to clear any buckets used.
112+
Here is an example that clears the bucket created in Step 3 with a timeout of 5 seconds.
181113
```java
182-
PubSubOptions options = PubSubOptions.builder()
183-
.projectId("my-project-id") // must match project ID specified on remote machine
184-
.host("<hostname of machine>:<port>")
185-
.authCredentials(AuthCredentials.noAuth())
186-
.build();
187-
PubSub localPubsub= options.service();
114+
RemoteStorageHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS);
188115
```
189116

190117
### Testing code that uses Resource Manager
@@ -218,30 +145,74 @@ You can test against an in-memory local Resource Manager by following these step
218145

219146
This method will block until the server thread has been terminated.
220147

221-
### Testing code that uses Storage
148+
### Testing code that uses BigQuery
222149

223-
Currently, there isn't an emulator for Google Cloud Storage, so an alternative is to create a test project. `RemoteStorageHelper` contains convenience methods to make setting up and cleaning up the test project easier. To use this class, follow the steps below:
150+
Currently, there isn't an emulator for Google BigQuery, so an alternative is to create a test
151+
project. `RemoteBigQueryHelper` contains convenience methods to make setting up and cleaning up the
152+
test project easier. To use this class, follow the steps below:
224153

225154
1. Create a test Google Cloud project.
226155

227-
2. Download a JSON service account credentials file from the Google Developer's Console. See more about this on the [Google Cloud Platform Storage Authentication page][cloud-platform-storage-authentication].
156+
2. Download a [JSON service account credentials file][create-service-account] from the Google
157+
Developer's Console.
228158

229-
3. Create a `RemoteStorageHelper` object using your project ID and JSON key.
230-
Here is an example that uses the `RemoteStorageHelper` to create a bucket.
159+
3. Create a `RemoteBigQueryHelper` object using your project ID and JSON key.
160+
Here is an example that uses the `RemoteBigQueryHelper` to create a dataset.
231161
```java
232-
RemoteStorageHelper helper =
233-
RemoteStorageHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
234-
Storage storage = helper.options().service();
235-
String bucket = RemoteStorageHelper.generateBucketName();
236-
storage.create(BucketInfo.of(bucket));
162+
RemoteBigQueryHelper bigqueryHelper =
163+
RemoteBigQueryHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
164+
BigQuery bigquery = bigqueryHelper.options().service();
165+
String dataset = RemoteBigQueryHelper.generateDatasetName();
166+
bigquery.create(DatasetInfo.builder(dataset).build());
237167
```
238168

239169
4. Run your tests.
240170

241-
5. Clean up the test project by using `forceDelete` to clear any buckets used.
242-
Here is an example that clears the bucket created in Step 3 with a timeout of 5 seconds.
171+
5. Clean up the test project by using `forceDelete` to clear any datasets used.
172+
Here is an example that clears the dataset created in Step 3.
243173
```java
244-
RemoteStorageHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS);
174+
RemoteBigQueryHelper.forceDelete(bigquery, dataset);
175+
```
176+
177+
### Testing code that uses Pub/Sub
178+
179+
#### On your machine
180+
181+
You can test against a temporary local Pub/Sub by following these steps:
182+
183+
1. Start the local Pub/Sub emulator before running your tests using `LocalPubSubHelper`'s `create`
184+
and `start` methods. This will bind a port for communication with the local Pub/Sub emulator.
185+
```java
186+
LocalPubSubHelper helper = LocalPubSubHelper.create();
187+
188+
helper.start(); // Starts the local Pub/Sub emulator in a separate process
189+
```
190+
191+
2. Create and use a `PubSub` object with the options given by the `LocalPubSubHelper` instance. For
192+
example:
193+
```java
194+
PubSub localPubsub = helper.options().service();
195+
```
196+
197+
3. Run your tests.
198+
199+
4. Stop the local Pub/Sub emulator by calling the `stop()` method, like so:
200+
```java
201+
helper.stop();
202+
```
203+
204+
#### On a remote machine
205+
206+
You can test against a remote Pub/Sub emulator as well. To do this, set the `PubSubOptions` project
207+
endpoint to the hostname of the remote machine, like the example below.
208+
209+
```java
210+
PubSubOptions options = PubSubOptions.builder()
211+
.projectId("my-project-id") // must match project ID specified on remote machine
212+
.host("<hostname of machine>:<port>")
213+
.authCredentials(AuthCredentials.noAuth())
214+
.build();
215+
PubSub localPubsub= options.service();
245216
```
246217

247218
[cloud-platform-storage-authentication]:https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?xml version="1.0"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.google.gcloud</groupId>
5+
<artifactId>gcloud-java-nio</artifactId>
6+
<packaging>jar</packaging>
7+
<name>GCloud Java NIO</name>
8+
<description>
9+
FileSystemProvider for Java NIO to access GCS transparently.
10+
</description>
11+
<parent>
12+
<groupId>com.google.gcloud</groupId>
13+
<artifactId>gcloud-java-contrib</artifactId>
14+
<version>0.1.4-SNAPSHOT</version>
15+
</parent>
16+
<properties>
17+
<site.installationModule>nio</site.installationModule>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>${project.groupId}</groupId>
22+
<artifactId>gcloud-java</artifactId>
23+
<version>${project.version}</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.google.guava</groupId>
27+
<artifactId>guava</artifactId>
28+
<version>19.0</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>com.google.code.findbugs</groupId>
32+
<artifactId>jsr305</artifactId>
33+
<version>2.0.1</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>javax.inject</groupId>
37+
<artifactId>javax.inject</artifactId>
38+
<version>1</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>com.google.auto.service</groupId>
42+
<artifactId>auto-service</artifactId>
43+
<version>1.0-rc2</version>
44+
<scope>provided</scope> <!-- to leave out of the all-deps jar -->
45+
</dependency>
46+
<dependency>
47+
<groupId>com.google.auto.value</groupId>
48+
<artifactId>auto-value</artifactId>
49+
<version>1.1</version>
50+
<scope>provided</scope> <!-- to leave out of the all-deps jar -->
51+
</dependency>
52+
<dependency>
53+
<groupId>com.google.appengine.tools</groupId>
54+
<artifactId>appengine-gcs-client</artifactId>
55+
<version>0.5</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>junit</groupId>
59+
<artifactId>junit</artifactId>
60+
<version>4.12</version>
61+
<scope>test</scope>
62+
</dependency>
63+
<dependency>
64+
<groupId>com.google.guava</groupId>
65+
<artifactId>guava-testlib</artifactId>
66+
<version>19.0</version>
67+
<scope>test</scope>
68+
</dependency>
69+
<dependency>
70+
<groupId>com.google.truth</groupId>
71+
<artifactId>truth</artifactId>
72+
<version>0.27</version>
73+
<scope>test</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.mockito</groupId>
77+
<artifactId>mockito-core</artifactId>
78+
<version>1.9.5</version>
79+
</dependency>
80+
<dependency>
81+
<groupId>com.google.appengine</groupId>
82+
<artifactId>appengine-testing</artifactId>
83+
<version>1.9.30</version>
84+
<scope>test</scope>
85+
</dependency>
86+
<dependency>
87+
<groupId>com.google.appengine</groupId>
88+
<artifactId>appengine-api-stubs</artifactId>
89+
<version>1.9.30</version>
90+
<scope>test</scope>
91+
</dependency>
92+
<dependency>
93+
<groupId>com.google.appengine</groupId>
94+
<artifactId>appengine-local-endpoints</artifactId>
95+
<version>1.9.30</version>
96+
<scope>test</scope>
97+
</dependency>
98+
</dependencies>
99+
<build>
100+
<plugins>
101+
<plugin>
102+
<groupId>org.codehaus.mojo</groupId>
103+
<artifactId>exec-maven-plugin</artifactId>
104+
<configuration>
105+
<skip>false</skip>
106+
</configuration>
107+
</plugin>
108+
<plugin>
109+
<artifactId>maven-compiler-plugin</artifactId>
110+
<version>3.1</version>
111+
<configuration>
112+
<source>1.7</source>
113+
<target>1.7</target>
114+
<encoding>UTF-8</encoding>
115+
<compilerArgument>-Xlint:unchecked</compilerArgument>
116+
</configuration>
117+
</plugin>
118+
<plugin>
119+
<artifactId>maven-jar-plugin</artifactId>
120+
<version>2.6</version>
121+
<configuration>
122+
<archive>
123+
<addMavenDescriptor>true</addMavenDescriptor>
124+
<index>true</index>
125+
<manifest>
126+
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
127+
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
128+
</manifest>
129+
<manifestEntries>
130+
<artifactId>${project.artifactId}</artifactId>
131+
<groupId>${project.groupId}</groupId>
132+
<version>${project.version}</version>
133+
<buildNumber>${buildNumber}</buildNumber>
134+
</manifestEntries>
135+
</archive>
136+
</configuration>
137+
</plugin>
138+
</plugins>
139+
</build>
140+
</project>

0 commit comments

Comments
 (0)