Skip to content

Commit 59722fa

Browse files
author
Ajay Kannan
committed
Minor wording and link changes to testing readme.
1 parent 25bde60 commit 59722fa

File tree

4 files changed

+74
-29
lines changed

4 files changed

+74
-29
lines changed

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Java idiomatic client for [Google Cloud Platform][cloud-platform] services.
1414
This client supports the following Google Cloud Platform services:
1515

1616
- [Google Cloud Datastore] (#google-cloud-datastore)
17+
- [Google Cloud Storage] (#google-cloud-storage)
1718

1819
<!---
1920
- [Google Cloud Storage] (https://cloud.google.com/storage/)
@@ -44,7 +45,7 @@ Example Applications
4445
Google Cloud Datastore
4546
----------------------
4647

47-
Google [Cloud Datastore][cloud-datastore] is a fully managed, schemaless database for
48+
[Google Cloud Datastore][cloud-datastore] is a fully managed, schemaless database for
4849
storing non-relational data. Cloud Datastore automatically scales with
4950
your users and supports ACID transactions, high availability of reads and
5051
writes, strong consistency for reads and ancestor queries, and eventual
@@ -86,6 +87,53 @@ if (entity == null) {
8687
}
8788
```
8889

90+
Google Cloud Storage
91+
----------------------
92+
93+
[Google Cloud Storage][cloud-storage] is a durable and highly available
94+
object storage service. Google Cloud Storage is almost infinitely scalable
95+
and guarantees consistency: when a write succeeds, the latest copy of the
96+
object will be returned to any GET, globally.
97+
98+
See the [Google Cloud Storage docs][cloud-storage-activation] for more details on how to activate
99+
Cloud Storage for your project.
100+
101+
See the ``gcloud-java`` API [storage documentation][storage-api] to learn how to interact
102+
with the Cloud Storage using this Client Library.
103+
104+
```java
105+
import static java.nio.charset.StandardCharsets.UTF_8;
106+
107+
import com.google.gcloud.storage.Blob;
108+
import com.google.gcloud.storage.Storage;
109+
import com.google.gcloud.storage.StorageFactory;
110+
import com.google.gcloud.storage.StorageOptions;
111+
112+
import java.nio.ByteBuffer;
113+
import java.nio.channels.WritableByteChannel;
114+
115+
StorageOptions options = StorageOptions.builder().projectId(PROJECT_ID).build();
116+
Storage storage = StorageFactory.instance().get(options);
117+
Blob blob = new Blob(storage, "bucket", "blob_name");
118+
if (!blob.exists()) {
119+
storage2.create(blob.info(), "Hello, Cloud Storage!".getBytes(UTF_8));
120+
} else {
121+
System.out.println("Updating content for " + blob.info().name());
122+
byte[] prevContent = blob.content();
123+
System.out.println(new String(prevContent, UTF_8));
124+
WritableByteChannel channel = blob.writer();
125+
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
126+
channel.close();
127+
}
128+
```
129+
130+
Testing
131+
-------
132+
133+
This library provides tools to help write tests for code that use gcloud-java services.
134+
135+
See [TESTING] to read more about using our testing helpers.
136+
89137
Contributing
90138
------------
91139

@@ -118,6 +166,7 @@ Apache 2.0 - See [LICENSE] for more information.
118166
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
119167
[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md
120168
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
169+
[TESTING]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md
121170
[cloud-platform]: https://cloud.google.com/
122171
[cloud-datastore]: https://cloud.google.com/datastore/docs
123172
[cloud-datastore-docs]: https://cloud.google.com/datastore/docs
@@ -130,3 +179,5 @@ Apache 2.0 - See [LICENSE] for more information.
130179
[cloud-storage]: https://cloud.google.com/storage/
131180
[cloud-storage-docs]: https://cloud.google.com/storage/docs/overview
132181
[cloud-storage-create-bucket]: https://cloud.google.com/storage/docs/cloud-console#_creatingbuckets
182+
[cloud-storage-activation]: https://cloud.google.com/storage/docs/signup
183+
[storage-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/storage/package-summary.html

TESTING.md

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## gcloud-java tools for testing
22

3-
gcloud-java provides tools to make testing your application easier.
3+
This library provides tools to help write tests for code that uses gcloud-java services.
44

5-
### Testing interactions with Datastore
5+
### Testing code that uses Datastore
66

77
#### On your machine
88

@@ -16,7 +16,7 @@ You can test against a temporary local datastore by following these steps:
1616
```java
1717
DatastoreOptions options = DatastoreOptions.builder()
1818
.projectId(PROJECT_ID)
19-
.host("localhost:8080")
19+
.host("http://localhost:8080")
2020
.build();
2121
Datastore localDatastore = DatastoreFactory.instance().get(options);
2222
```
@@ -33,37 +33,31 @@ You can test against a remote datastore emulator as well. To do this, set the `
3333
```java
3434
DatastoreOptions options = DatastoreOptions.builder()
3535
.projectId(PROJECT_ID)
36-
.host("http://<hostname of machine>")
36+
.host("http://<hostname of machine>:<port>")
3737
.build();
3838
Datastore localDatastore = DatastoreFactory.instance().get(options);
3939
```
4040

41-
Note that the remote datastore must be running before your tests are run. Also note that the `host` argument must start with "http://" or "https://" if you are testing with a remote machine.
41+
Note that the remote datastore must be running before your tests are run.
4242

4343

44-
### Testing interactions with Storage
44+
### Testing code that uses Storage
4545

46-
There currently isn't an emulator for Google Cloud Storage, so an alternative is to create a test project. `RemoteGcsHelper` contains convenience methods to make setting up and cleaning up the test project easier. To use this class, follow the steps below:
46+
Currently, there isn't an emulator for Google Cloud Storage, so an alternative is to create a test project. `RemoteGcsHelper` contains convenience methods to make setting up and cleaning up the test project easier. To use this class, follow the steps below:
4747

4848
1. Create a test Google Cloud project.
4949

50-
2. Create and 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].
50+
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].
5151

52-
3. Set environment variables `GCLOUD_TESTS_PROJECT_ID` and `GCLOUD_TESTS_KEY` according to your test project's ID and the location of the newly-downloaded JSON key file. On linux and mac, for example,
53-
```
54-
export GCLOUD_TESTS_PROJECT_ID=<project id>
55-
export GCLOUD_TESTS_KEY=/path/to/JSON/key.json
56-
```
57-
58-
4. Create and and use a `RemoteGcsHelper` object.
52+
3. Create and use a `RemoteGcsHelper` object using your project ID and JSON key.
5953
Here is an example that uses the `RemoteGcsHelper` to create a bucket and clear the bucket at the end of the test.
60-
```java
61-
RemoteGcsHelper gcsHelper = RemoteGcsHelper.create();
62-
Storage storage = StorageFactory.instance().get(gcsHelper.options());
63-
String bucket = RemoteGcsHelper.generateBucketName();
64-
storage.create(BucketInfo.of(bucket));
65-
// Do tests using Storage
66-
RemoteGcsHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS);
67-
```
54+
```java
55+
RemoteGcsHelper gcsHelper = RemoteGcsHelper.create(PROJECT_ID, "/path/to/my/JSON/key.json");
56+
Storage storage = StorageFactory.instance().get(gcsHelper.options());
57+
String bucket = RemoteGcsHelper.generateBucketName();
58+
storage.create(BucketInfo.of(bucket));
59+
// Do tests using Storage
60+
RemoteGcsHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS);
61+
```
6862

6963
[cloud-platform-storage-authentication]:https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts

gcloud-java-datastore/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ if (entity == null) {
7272
Testing
7373
-------
7474

75-
This library makes testing interactions with Cloud Datastore easier by using a local datastore emulator.
75+
This library has tools to help write tests for code that uses the Datastore.
7676

77-
See [TESTING] to read more about testing locally.
77+
See [TESTING] to read more about testing.
7878

7979
Contributing
8080
------------
@@ -105,7 +105,7 @@ Apache 2.0 - See [LICENSE] for more information.
105105

106106
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
107107
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
108-
[TESTING]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md
108+
[TESTING]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md#testing-code-that-uses-datastore
109109
[cloud-platform]: https://cloud.google.com/
110110
[cloud-datastore]: https://cloud.google.com/datastore/docs
111111
[cloud-datastore-docs]: https://cloud.google.com/datastore/docs

gcloud-java-storage/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Add this to your pom.xml file
2929
Testing
3030
-------
3131

32-
This library makes testing interactions with Cloud Storage more convenient.
32+
This library has tools to help make tests for code using Cloud Storage.
3333

3434
See [TESTING] to read more about testing.
3535

@@ -62,7 +62,7 @@ Apache 2.0 - See [LICENSE] for more information.
6262

6363
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
6464
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
65-
[TESTING]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md
65+
[TESTING]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md#testing-code-that-uses-storage
6666
[cloud-platform]: https://cloud.google.com/
6767

6868
[cloud-storage]: https://cloud.google.com/storage/

0 commit comments

Comments
 (0)