File tree 3 files changed +30
-6
lines changed
gcloud-java-datastore/src
main/java/com/google/cloud/datastore
test/java/com/google/cloud/datastore/testing
3 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,9 @@ public DatastoreOptions build() {
75
75
return new DatastoreOptions (this );
76
76
}
77
77
78
+ /**
79
+ * Sets the default namespace to be used by the datastore service.
80
+ */
78
81
public Builder namespace (String namespace ) {
79
82
this .namespace = validateNamespace (namespace );
80
83
return this ;
@@ -112,6 +115,9 @@ protected DatastoreRpcFactory defaultRpcFactory() {
112
115
return DefaultDatastoreRpcFactory .INSTANCE ;
113
116
}
114
117
118
+ /**
119
+ * Returns the default namespace to be used by the datastore service.
120
+ */
115
121
public String namespace () {
116
122
return namespace ;
117
123
}
Original file line number Diff line number Diff line change @@ -556,17 +556,28 @@ private static int findAvailablePort() {
556
556
}
557
557
}
558
558
559
+ private DatastoreOptions .Builder optionsBuilder () {
560
+ return DatastoreOptions .builder ()
561
+ .projectId (projectId )
562
+ .host ("localhost:" + Integer .toString (port ))
563
+ .authCredentials (AuthCredentials .noAuth ())
564
+ .retryParams (RetryParams .noRetries ());
565
+ }
566
+
559
567
/**
560
568
* Returns a {@link DatastoreOptions} instance that sets the host to use the Datastore emulator on
561
569
* localhost.
562
570
*/
563
571
public DatastoreOptions options () {
564
- return DatastoreOptions .builder ()
565
- .projectId (projectId )
566
- .host ("localhost:" + Integer .toString (port ))
567
- .authCredentials (AuthCredentials .noAuth ())
568
- .retryParams (RetryParams .noRetries ())
569
- .build ();
572
+ return optionsBuilder ().build ();
573
+ }
574
+
575
+ /**
576
+ * Returns a {@link DatastoreOptions} instance that sets the host to use the Datastore emulator on
577
+ * localhost. The default namespace is set to {@code namespace}.
578
+ */
579
+ public DatastoreOptions options (String namespace ) {
580
+ return optionsBuilder ().namespace (namespace ).build ();
570
581
}
571
582
572
583
/**
Original file line number Diff line number Diff line change 16
16
17
17
package com .google .cloud .datastore .testing ;
18
18
19
+ import static org .junit .Assert .assertEquals ;
19
20
import static org .junit .Assert .assertSame ;
20
21
import static org .junit .Assert .assertTrue ;
21
22
@@ -31,6 +32,7 @@ public class LocalDatastoreHelperTest {
31
32
32
33
private static final double TOLERANCE = 0.00001 ;
33
34
private static final String PROJECT_ID_PREFIX = "test-project-" ;
35
+ private static final String NAMESPACE = "namespace" ;
34
36
35
37
@ Test
36
38
public void testCreate () {
@@ -49,5 +51,10 @@ public void testOptions() {
49
51
assertTrue (options .projectId ().startsWith (PROJECT_ID_PREFIX ));
50
52
assertTrue (options .host ().startsWith ("localhost:" ));
51
53
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 ());
52
59
}
53
60
}
You can’t perform that action at this time.
0 commit comments