File tree Expand file tree Collapse file tree
gcloud-java-datastore/src
main/java/com/google/cloud/datastore
test/java/com/google/cloud/datastore/testing Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -75,6 +75,9 @@ public DatastoreOptions build() {
7575 return new DatastoreOptions (this );
7676 }
7777
78+ /**
79+ * Sets the default namespace to be used by the datastore service.
80+ */
7881 public Builder namespace (String namespace ) {
7982 this .namespace = validateNamespace (namespace );
8083 return this ;
@@ -112,6 +115,9 @@ protected DatastoreRpcFactory defaultRpcFactory() {
112115 return DefaultDatastoreRpcFactory .INSTANCE ;
113116 }
114117
118+ /**
119+ * Returns the default namespace to be used by the datastore service.
120+ */
115121 public String namespace () {
116122 return namespace ;
117123 }
Original file line number Diff line number Diff line change @@ -569,6 +569,20 @@ public DatastoreOptions options() {
569569 .build ();
570570 }
571571
572+ /**
573+ * Returns a {@link DatastoreOptions} instance that sets the host to use the Datastore emulator on
574+ * localhost. The default namespace is set to {@code namespace}.
575+ */
576+ public DatastoreOptions options (String namespace ) {
577+ return DatastoreOptions .builder ()
578+ .projectId (projectId )
579+ .host ("localhost:" + Integer .toString (port ))
580+ .authCredentials (AuthCredentials .noAuth ())
581+ .retryParams (RetryParams .noRetries ())
582+ .namespace (namespace )
583+ .build ();
584+ }
585+
572586 /**
573587 * Returns the project ID associated with this local Datastore emulator.
574588 */
Original file line number Diff line number Diff line change 1616
1717package com .google .cloud .datastore .testing ;
1818
19+ import static org .junit .Assert .assertEquals ;
1920import static org .junit .Assert .assertSame ;
2021import static org .junit .Assert .assertTrue ;
2122
@@ -31,6 +32,7 @@ public class LocalDatastoreHelperTest {
3132
3233 private static final double TOLERANCE = 0.00001 ;
3334 private static final String PROJECT_ID_PREFIX = "test-project-" ;
35+ private static final String NAMESPACE = "namespace" ;
3436
3537 @ Test
3638 public void testCreate () {
@@ -49,5 +51,10 @@ public void testOptions() {
4951 assertTrue (options .projectId ().startsWith (PROJECT_ID_PREFIX ));
5052 assertTrue (options .host ().startsWith ("localhost:" ));
5153 assertSame (AuthCredentials .noAuth (), options .authCredentials ());
54+ options = helper .options (NAMESPACE );
55+ assertTrue (options .projectId ().startsWith (PROJECT_ID_PREFIX ));
56+ assertTrue (options .host ().startsWith ("localhost:" ));
57+ assertSame (AuthCredentials .noAuth (), options .authCredentials ());
58+ assertEquals (NAMESPACE , options .namespace ());
5259 }
5360}
You can’t perform that action at this time.
0 commit comments