Skip to content

Commit 06ca7a7

Browse files
feat(datastore): support --use-firestore-in-datastore-mode in the datastore emulator (#3633)
Fixes #1406 This followed the changes in the java-datastore library. See https://togithub.com/googleapis/java-datastore/pull/1698
1 parent 925c0e1 commit 06ca7a7

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

docs/src/main/asciidoc/datastore.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ The following configuration options are available:
7979
| `spring.cloud.gcp.datastore.emulator.consistency` | The https://cloud.google.com/sdk/gcloud/reference/beta/emulators/datastore/start?#--consistency[consistency] to use for the Datastore Emulator instance | No | `0.9`
8080
| `spring.cloud.gcp.datastore.emulator.store-on-disk` | Configures whether or not the emulator should persist any data to disk. | No | `true`
8181
| `spring.cloud.gcp.datastore.emulator.data-dir` | The directory to be used to store/retrieve data/config for an emulator run. | No | The default value is `<USER_CONFIG_DIR>/emulators/datastore`. See the https://cloud.google.com/sdk/gcloud/reference/beta/emulators/datastore/start[gcloud documentation] for finding your `USER_CONFIG_DIR`.
82+
| `spring.cloud.gcp.datastore.emulator.firestore-in-datastore-mode` | Configures whether the emulator runs in "Cloud Firestore in Datastore Mode" | No | `false`
8283
| `spring.cloud.gcp.datastore.skip-null-value` | Whether skip inserting `null` values. | No | The default value is `false`.
8384
If configured to `true`, `null` value will not be inserted into the datastore.
8485

spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/datastore/EmulatorSettings.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ public class EmulatorSettings {
5454
*/
5555
private Path dataDir;
5656

57+
/**
58+
* Configures whether the emulator runs in "Cloud Firestore in Datastore Mode". Correspondent CLI
59+
* property: --use-firestore-in-datastore-mode.
60+
*/
61+
private boolean firestoreInDatastoreMode = false;
62+
63+
public boolean getFirestoreInDatastoreMode() {
64+
return firestoreInDatastoreMode;
65+
}
66+
67+
public void setFirestoreInDatastoreMode(boolean useFirestoreInDatastoreMode) {
68+
this.firestoreInDatastoreMode = useFirestoreInDatastoreMode;
69+
}
70+
5771
public Path getDataDir() {
5872
return dataDir;
5973
}

spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/datastore/GcpDatastoreEmulatorAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public LocalDatastoreHelper createDatastoreHelper(GcpDatastoreProperties datasto
5858
.setPort(settings.getPort())
5959
.setStoreOnDisk(settings.isStoreOnDisk())
6060
.setDataDir(settings.getDataDir())
61+
.setFirestoreInDatastoreMode(settings.getFirestoreInDatastoreMode())
6162
.build();
6263

6364
return this.helper;

spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/datastore/GcpDatastoreEmulatorAutoConfigurationTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ void testDatastoreOptionsCorrectlySet() {
4242
"spring.cloud.gcp.datastore.emulator.enabled=true",
4343
"spring.cloud.gcp.datastore.emulator.consistency=0.8",
4444
"spring.cloud.gcp.datastore.emulator.dataDir=/usr/local/datastore",
45-
"spring.cloud.gcp.datastore.emulator.storeOnDisk=false")
45+
"spring.cloud.gcp.datastore.emulator.storeOnDisk=false",
46+
"spring.cloud.gcp.datastore.emulator.firestoreInDatastoreMode=true")
4647
.run(
4748
context -> {
4849
LocalDatastoreHelper helper = context.getBean(LocalDatastoreHelper.class);
@@ -51,6 +52,7 @@ void testDatastoreOptionsCorrectlySet() {
5152
assertThat(helper.getConsistency()).isEqualTo(0.8D);
5253
assertThat(helper.getGcdPath()).isEqualTo(Paths.get("/usr/local/datastore"));
5354
assertThat(helper.isStoreOnDisk()).isFalse();
55+
assertThat(helper.isFirestoreInDatastoreMode()).isTrue();
5456
});
5557
}
5658

0 commit comments

Comments
 (0)