@@ -183,7 +183,7 @@ Cloud Datastore relies on indexing to run queries. Indexing is turned on by defa
183183#### Updating data
184184Another thing you'll probably want to do is update your data. The following snippet shows how to update a Datastore entity if it exists.
185185
186- ``` java
186+ ``` java
187187KeyFactory keyFactory = datastore. newKeyFactory(). setKind(" keyKind" );
188188Key key = keyFactory. newKey(" keyName" );
189189Entity entity = datastore. get(key);
@@ -197,12 +197,12 @@ if (entity != null) {
197197```
198198
199199The complete source code can be found at
200- [ UpdateEntity.java] ( ../.. /google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/UpdateEntity.java) .
200+ [ UpdateEntity.java] ( https://github.com/googleapis/google-cloud-java/blob/2c1850d4f82f3fbd7b4a50582384c008085aa1a8 /google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/UpdateEntity.java) .
201201
202202#### Complete source code
203203
204204In
205- [ AddEntitiesAndRunQuery.java] ( ../.. /google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/AddEntitiesAndRunQuery.java)
205+ [ AddEntitiesAndRunQuery.java] ( https://github.com/googleapis/google-cloud-java/blob/2c1850d4f82f3fbd7b4a50582384c008085aa1a8 /google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/AddEntitiesAndRunQuery.java)
206206we put together all the code to store data and run queries into one program. The program assumes that you are
207207running on Compute Engine or from your own desktop. To run the example on App Engine, simply move
208208the code from the main method to your application's servlet class and change the print statements to
@@ -213,7 +213,33 @@ Testing
213213
214214This library has tools to help write tests for code that uses the Datastore.
215215
216- See [ TESTING.md] ( https://github.com/googleapis/google-cloud-java/blob/main/TESTING.md#testing-code-that-uses-datastore ) to read more about testing.
216+ #### On your machine
217+
218+ You can test against a temporary local Datastore by following these steps:
219+
220+ 1 . [ Install Cloud SDK and start the emulator] ( https://cloud.google.com/datastore/docs/tools/datastore-emulator )
221+
222+ To determine which host/port the emulator is running on:
223+
224+ ```
225+ $ gcloud beta emulators datastore env-init
226+
227+ # Sample output:
228+ # export DATASTORE_EMULATOR_HOST=localhost:8759
229+ ```
230+
231+ 3 . Point your client to the emulator
232+
233+ ``` java
234+ DatastoreOptions options = DatastoreOptions . newBuilder()
235+ .setProjectId(DatastoreOptions . getDefaultProjectId())
236+ .setHost(System . getenv(" DATASTORE_EMULATOR_HOST" ))
237+ .setCredentials(NoCredentials . getInstance())
238+ .setRetrySettings(ServiceOptions . getNoRetrySettings())
239+ .build();
240+ Datastore datastore = options. getService();
241+ ```
242+ 4 . Run your tests
217243
218244Example Applications
219245--------------------
0 commit comments