@@ -53,6 +53,7 @@ public class LocalDatastoreHelper extends BaseEmulatorHelper<DatastoreOptions> {
5353 private final double consistency ;
5454 private final Path gcdPath ;
5555 private boolean storeOnDisk ;
56+ private boolean firestoreInDatastoreMode ;
5657
5758 // Gcloud emulator settings
5859 private static final String GCLOUD_CMD_TEXT = "gcloud beta emulators datastore start" ;
@@ -74,6 +75,8 @@ public class LocalDatastoreHelper extends BaseEmulatorHelper<DatastoreOptions> {
7475 private static final String PROJECT_FLAG = "--project=" ;
7576 private static final double DEFAULT_CONSISTENCY = 0.9 ;
7677 private static final String DEFAULT_PROJECT_ID = PROJECT_ID_PREFIX + UUID .randomUUID ();
78+ private static final String FIRESTORE_IN_DATASTORE_MODE_FLAG =
79+ "--use-firestore-in-datastore-mode" ;
7780
7881 private static final Logger LOGGER = Logger .getLogger (LocalDatastoreHelper .class .getName ());
7982
@@ -102,6 +105,7 @@ public static class Builder {
102105 private int port ;
103106 private Path dataDir ;
104107 private boolean storeOnDisk = true ;
108+ private boolean firestoreInDatastoreMode = false ;
105109 private String projectId ;
106110
107111 private Builder () {}
@@ -110,6 +114,7 @@ private Builder(LocalDatastoreHelper helper) {
110114 this .consistency = helper .consistency ;
111115 this .dataDir = helper .gcdPath ;
112116 this .storeOnDisk = helper .storeOnDisk ;
117+ this .firestoreInDatastoreMode = helper .firestoreInDatastoreMode ;
113118 }
114119
115120 public Builder setConsistency (double consistency ) {
@@ -136,6 +141,10 @@ public Builder setStoreOnDisk(boolean storeOnDisk) {
136141 this .storeOnDisk = storeOnDisk ;
137142 return this ;
138143 }
144+ public Builder setFirestoreInDatastoreMode (boolean firestoreInDatastoreMode ) {
145+ this .firestoreInDatastoreMode = firestoreInDatastoreMode ;
146+ return this ;
147+ }
139148
140149 /** Creates a {@code LocalDatastoreHelper} object. */
141150 public LocalDatastoreHelper build () {
@@ -152,14 +161,21 @@ private LocalDatastoreHelper(Builder builder) {
152161 this .consistency = builder .consistency > 0 ? builder .consistency : DEFAULT_CONSISTENCY ;
153162 this .gcdPath = builder .dataDir ;
154163 this .storeOnDisk = builder .storeOnDisk ;
164+ this .firestoreInDatastoreMode = builder .firestoreInDatastoreMode ;
155165 String binName = BIN_NAME ;
156166 if (isWindows ()) {
157167 binName = BIN_NAME .replace ("/" , "\\ " );
158168 }
159169 List <String > gcloudCommand = new ArrayList <>(Arrays .asList (GCLOUD_CMD_TEXT .split (" " )));
160170 gcloudCommand .add (GCLOUD_CMD_PORT_FLAG + "localhost:" + getPort ());
161- gcloudCommand .add (CONSISTENCY_FLAG + builder .consistency );
162171 gcloudCommand .add (PROJECT_FLAG + projectId );
172+ if (builder .firestoreInDatastoreMode ) {
173+ gcloudCommand .add (FIRESTORE_IN_DATASTORE_MODE_FLAG );
174+ } else {
175+ // At most one of --consistency | --use-firestore-in-datastore-mode can be specified.
176+ // --consistency will be ignored with --use-firestore-in-datastore-mode.
177+ gcloudCommand .add (CONSISTENCY_FLAG + builder .consistency );
178+ }
163179 if (!builder .storeOnDisk ) {
164180 gcloudCommand .add ("--no-store-on-disk" );
165181 }
@@ -170,8 +186,14 @@ private LocalDatastoreHelper(Builder builder) {
170186 new GcloudEmulatorRunner (gcloudCommand , VERSION_PREFIX , MIN_VERSION );
171187 List <String > binCommand = new ArrayList <>(Arrays .asList (binName , "start" ));
172188 binCommand .add ("--testing" );
189+ if (builder .firestoreInDatastoreMode ) {
190+ binCommand .add (FIRESTORE_IN_DATASTORE_MODE_FLAG );
191+ } else {
192+ // At most one of --consistency | --use-firestore-in-datastore-mode can be specified.
193+ // --consistency will be ignored with --use-firestore-in-datastore-mode.
194+ binCommand .add (CONSISTENCY_FLAG + getConsistency ());
195+ }
173196 binCommand .add (BIN_CMD_PORT_FLAG + getPort ());
174- binCommand .add (CONSISTENCY_FLAG + getConsistency ());
175197 DownloadableEmulatorRunner downloadRunner =
176198 new DownloadableEmulatorRunner (binCommand , EMULATOR_URL , MD5_CHECKSUM , ACCESS_TOKEN );
177199 this .emulatorRunners = ImmutableList .of (gcloudRunner , downloadRunner );
@@ -235,6 +257,11 @@ public boolean isStoreOnDisk() {
235257 return storeOnDisk ;
236258 }
237259
260+ /** Returns {@code true} use firestore-in-datastore-mode, otherwise {@code false} use native mode. */
261+ public boolean isFirestoreInDatastoreMode () {
262+ return firestoreInDatastoreMode ;
263+ }
264+
238265 /**
239266 * Creates a local Datastore helper with the specified settings for project ID and consistency.
240267 *
0 commit comments