Skip to content

Commit 13a7066

Browse files
authored
C++ migration: eliminate FSTRemoteStore (#2338)
1 parent a22b4cd commit 13a7066

File tree

12 files changed

+62
-322
lines changed

12 files changed

+62
-322
lines changed

Firestore/Example/Tests/Integration/FSTDatastoreTests.mm

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#import "Firestore/Source/Model/FSTFieldValue.h"
3131
#import "Firestore/Source/Model/FSTMutation.h"
3232
#import "Firestore/Source/Model/FSTMutationBatch.h"
33-
#import "Firestore/Source/Remote/FSTRemoteStore.h"
3433

3534
#import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
3635

@@ -41,6 +40,7 @@
4140
#include "Firestore/core/src/firebase/firestore/model/precondition.h"
4241
#include "Firestore/core/src/firebase/firestore/remote/datastore.h"
4342
#include "Firestore/core/src/firebase/firestore/remote/remote_event.h"
43+
#include "Firestore/core/src/firebase/firestore/remote/remote_store.h"
4444
#include "Firestore/core/src/firebase/firestore/util/async_queue.h"
4545
#include "Firestore/core/src/firebase/firestore/util/executor_libdispatch.h"
4646
#include "Firestore/core/src/firebase/firestore/util/hard_assert.h"
@@ -60,15 +60,12 @@
6060
using firebase::firestore::remote::Datastore;
6161
using firebase::firestore::remote::GrpcConnection;
6262
using firebase::firestore::remote::RemoteEvent;
63+
using firebase::firestore::remote::RemoteStore;
6364
using firebase::firestore::util::AsyncQueue;
6465
using firebase::firestore::util::ExecutorLibdispatch;
6566

6667
NS_ASSUME_NONNULL_BEGIN
6768

68-
@interface FSTRemoteStore (Tests)
69-
- (void)addBatchToWritePipeline:(FSTMutationBatch *)batch;
70-
@end
71-
7269
#pragma mark - FSTRemoteStoreEventCapture
7370

7471
@interface FSTRemoteStoreEventCapture : NSObject <FSTRemoteSyncer>
@@ -163,7 +160,7 @@ @implementation FSTDatastoreTests {
163160

164161
DatabaseInfo _databaseInfo;
165162
std::shared_ptr<Datastore> _datastore;
166-
FSTRemoteStore *_remoteStore;
163+
std::unique_ptr<RemoteStore> _remoteStore;
167164
}
168165

169166
- (void)setUp {
@@ -185,18 +182,16 @@ - (void)setUp {
185182
_testWorkerQueue = absl::make_unique<AsyncQueue>(absl::make_unique<ExecutorLibdispatch>(queue));
186183
_datastore = std::make_shared<Datastore>(_databaseInfo, _testWorkerQueue.get(), &_credentials);
187184

188-
_remoteStore = [[FSTRemoteStore alloc] initWithLocalStore:_localStore
189-
datastore:_datastore
190-
workerQueue:_testWorkerQueue.get()
191-
onlineStateHandler:[](OnlineState) {}];
185+
_remoteStore = absl::make_unique<RemoteStore>(_localStore, _datastore, _testWorkerQueue.get(),
186+
[](OnlineState) {});
192187

193-
_testWorkerQueue->Enqueue([=] { [_remoteStore start]; });
188+
_testWorkerQueue->Enqueue([=] { _remoteStore->Start(); });
194189
}
195190

196191
- (void)tearDown {
197192
XCTestExpectation *completion = [self expectationWithDescription:@"shutdown"];
198193
_testWorkerQueue->Enqueue([=] {
199-
[_remoteStore shutdown];
194+
_remoteStore->Shutdown();
200195
[completion fulfill];
201196
});
202197
[self awaitExpectations];
@@ -219,17 +214,17 @@ - (void)testStreamingWrite {
219214
FSTRemoteStoreEventCapture *capture = [[FSTRemoteStoreEventCapture alloc] initWithTestCase:self];
220215
[capture expectWriteEventWithDescription:@"write mutations"];
221216

222-
[_remoteStore setSyncEngine:capture];
217+
_remoteStore->set_sync_engine(capture);
223218

224219
FSTSetMutation *mutation = [self setMutation];
225220
FSTMutationBatch *batch = [[FSTMutationBatch alloc] initWithBatchID:23
226221
localWriteTime:[FIRTimestamp timestamp]
227222
mutations:{mutation}];
228223
_testWorkerQueue->Enqueue([=] {
229-
[_remoteStore addBatchToWritePipeline:batch];
224+
_remoteStore->AddToWritePipeline(batch);
230225
// The added batch won't be written immediately because write stream wasn't yet open --
231226
// trigger its opening.
232-
[_remoteStore fillWritePipeline];
227+
_remoteStore->FillWritePipeline();
233228
});
234229

235230
[self awaitExpectations];

Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include <unordered_map>
2121
#include <vector>
2222

23-
#import "Firestore/Source/Remote/FSTRemoteStore.h"
24-
2523
#include "Firestore/core/src/firebase/firestore/auth/user.h"
2624
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
2725
#include "Firestore/core/src/firebase/firestore/model/document_key_set.h"
@@ -286,7 +284,7 @@ typedef std::unordered_map<firebase::firestore::auth::User,
286284
* outstanding persisted mutations.
287285
*
288286
* Note: The size of the list for the current user will generally be the same as
289-
* sentWritesCount, but not necessarily, since the FSTRemoteStore limits the number of
287+
* sentWritesCount, but not necessarily, since the `RemoteStore` limits the number of
290288
* outstanding writes to the backend at a given time.
291289
*/
292290
@property(nonatomic, assign, readonly) const FSTOutstandingWriteQueues &outstandingWrites;

Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "Firestore/core/src/firebase/firestore/core/database_info.h"
4141
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
4242
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
43+
#include "Firestore/core/src/firebase/firestore/remote/remote_store.h"
4344
#include "Firestore/core/src/firebase/firestore/util/async_queue.h"
4445
#include "Firestore/core/src/firebase/firestore/util/executor_libdispatch.h"
4546
#include "Firestore/core/src/firebase/firestore/util/hard_assert.h"
@@ -59,6 +60,7 @@
5960
using firebase::firestore::model::SnapshotVersion;
6061
using firebase::firestore::model::TargetId;
6162
using firebase::firestore::remote::MockDatastore;
63+
using firebase::firestore::remote::RemoteStore;
6264
using firebase::firestore::remote::WatchChange;
6365
using firebase::firestore::util::AsyncQueue;
6466
using firebase::firestore::util::TimerId;
@@ -86,7 +88,6 @@ @interface FSTSyncEngineTestDriver ()
8688
#pragma mark - Parts of the Firestore system that the spec tests need to control.
8789

8890
@property(nonatomic, strong, readonly) FSTEventManager *eventManager;
89-
@property(nonatomic, strong, readonly) FSTRemoteStore *remoteStore;
9091
@property(nonatomic, strong, readonly) FSTLocalStore *localStore;
9192
@property(nonatomic, strong, readonly) FSTSyncEngine *syncEngine;
9293
@property(nonatomic, strong, readonly) id<FSTPersistence> persistence;
@@ -113,6 +114,8 @@ @interface FSTSyncEngineTestDriver ()
113114
@implementation FSTSyncEngineTestDriver {
114115
std::unique_ptr<AsyncQueue> _workerQueue;
115116

117+
std::unique_ptr<RemoteStore> _remoteStore;
118+
116119
std::unordered_map<TargetId, FSTQueryData *> _expectedActiveTargets;
117120

118121
// ivar is declared as mutable.
@@ -154,19 +157,17 @@ - (instancetype)initWithPersistence:(id<FSTPersistence>)persistence
154157

155158
_datastore =
156159
std::make_shared<MockDatastore>(_databaseInfo, _workerQueue.get(), &_credentialProvider);
157-
_remoteStore =
158-
[[FSTRemoteStore alloc] initWithLocalStore:_localStore
159-
datastore:_datastore
160-
workerQueue:_workerQueue.get()
161-
onlineStateHandler:[self](OnlineState onlineState) {
162-
[self.syncEngine applyChangedOnlineState:onlineState];
163-
[self.eventManager applyChangedOnlineState:onlineState];
164-
}];
160+
_remoteStore = absl::make_unique<RemoteStore>(
161+
_localStore, _datastore, _workerQueue.get(), [self](OnlineState onlineState) {
162+
[self.syncEngine applyChangedOnlineState:onlineState];
163+
[self.eventManager applyChangedOnlineState:onlineState];
164+
});
165+
;
165166

166167
_syncEngine = [[FSTSyncEngine alloc] initWithLocalStore:_localStore
167-
remoteStore:_remoteStore
168+
remoteStore:_remoteStore.get()
168169
initialUser:initialUser];
169-
[_remoteStore setSyncEngine:_syncEngine];
170+
_remoteStore->set_sync_engine(_syncEngine);
170171
_eventManager = [FSTEventManager eventManagerWithSyncEngine:_syncEngine];
171172

172173
// Set up internal event tracking for the spec tests.
@@ -210,7 +211,7 @@ - (void)drainQueue {
210211
- (void)start {
211212
_workerQueue->EnqueueBlocking([&] {
212213
[self.localStore start];
213-
[self.remoteStore start];
214+
_remoteStore->Start();
214215
});
215216
}
216217

@@ -222,7 +223,7 @@ - (void)validateUsage {
222223

223224
- (void)shutdown {
224225
_workerQueue->EnqueueBlocking([&] {
225-
[self.remoteStore shutdown];
226+
_remoteStore->Shutdown();
226227
[self.persistence shutdown];
227228
});
228229
}
@@ -254,13 +255,13 @@ - (void)disableNetwork {
254255
_workerQueue->EnqueueBlocking([&] {
255256
// Make sure to execute all writes that are currently queued. This allows us
256257
// to assert on the total number of requests sent before shutdown.
257-
[self.remoteStore fillWritePipeline];
258-
[self.remoteStore disableNetwork];
258+
_remoteStore->FillWritePipeline();
259+
_remoteStore->DisableNetwork();
259260
});
260261
}
261262

262263
- (void)enableNetwork {
263-
_workerQueue->EnqueueBlocking([&] { [self.remoteStore enableNetwork]; });
264+
_workerQueue->EnqueueBlocking([&] { _remoteStore->EnableNetwork(); });
264265
}
265266

266267
- (void)runTimer:(TimerId)timerID {

Firestore/Source/Core/FSTEventManager.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#import <Foundation/Foundation.h>
1818

1919
#import "Firestore/Source/Core/FSTViewSnapshot.h"
20-
#import "Firestore/Source/Remote/FSTRemoteStore.h"
2120

2221
#include "Firestore/core/src/firebase/firestore/model/types.h"
2322

Firestore/Source/Core/FSTFirestoreClient.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#import "Firestore/Source/Core/FSTTypes.h"
2323
#import "Firestore/Source/Core/FSTViewSnapshot.h"
24-
#import "Firestore/Source/Remote/FSTRemoteStore.h"
2524

2625
#include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
2726
#include "Firestore/core/src/firebase/firestore/core/database_info.h"

Firestore/Source/Core/FSTFirestoreClient.mm

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,19 @@
4040
#import "Firestore/Source/Local/FSTMemoryPersistence.h"
4141
#import "Firestore/Source/Model/FSTDocument.h"
4242
#import "Firestore/Source/Model/FSTDocumentSet.h"
43-
#import "Firestore/Source/Remote/FSTRemoteStore.h"
4443
#import "Firestore/Source/Remote/FSTSerializerBeta.h"
4544
#import "Firestore/Source/Util/FSTClasses.h"
4645

4746
#include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
4847
#include "Firestore/core/src/firebase/firestore/core/database_info.h"
4948
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
5049
#include "Firestore/core/src/firebase/firestore/remote/datastore.h"
50+
#include "Firestore/core/src/firebase/firestore/remote/remote_store.h"
5151
#include "Firestore/core/src/firebase/firestore/util/async_queue.h"
5252
#include "Firestore/core/src/firebase/firestore/util/hard_assert.h"
5353
#include "Firestore/core/src/firebase/firestore/util/log.h"
5454
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
55+
#include "absl/memory/memory.h"
5556

5657
namespace util = firebase::firestore::util;
5758
using firebase::firestore::auth::CredentialsProvider;
@@ -64,6 +65,7 @@
6465
using firebase::firestore::model::MaybeDocumentMap;
6566
using firebase::firestore::model::OnlineState;
6667
using firebase::firestore::remote::Datastore;
68+
using firebase::firestore::remote::RemoteStore;
6769
using firebase::firestore::util::Path;
6870
using firebase::firestore::util::Status;
6971
using firebase::firestore::util::AsyncQueue;
@@ -93,7 +95,6 @@ - (instancetype)initWithDatabaseInfo:(const DatabaseInfo &)databaseInfo
9395
@property(nonatomic, strong, readonly) FSTEventManager *eventManager;
9496
@property(nonatomic, strong, readonly) id<FSTPersistence> persistence;
9597
@property(nonatomic, strong, readonly) FSTSyncEngine *syncEngine;
96-
@property(nonatomic, strong, readonly) FSTRemoteStore *remoteStore;
9798
@property(nonatomic, strong, readonly) FSTLocalStore *localStore;
9899

99100
// Does not own the CredentialsProvider instance.
@@ -110,6 +111,8 @@ @implementation FSTFirestoreClient {
110111
*/
111112
std::unique_ptr<AsyncQueue> _workerQueue;
112113

114+
std::unique_ptr<RemoteStore> _remoteStore;
115+
113116
std::unique_ptr<Executor> _userExecutor;
114117
std::chrono::milliseconds _initialGcDelay;
115118
std::chrono::milliseconds _regularGcDelay;
@@ -226,26 +229,23 @@ - (void)initializeWithUser:(const User &)user settings:(FIRFirestoreSettings *)s
226229
auto datastore =
227230
std::make_shared<Datastore>(*self.databaseInfo, _workerQueue.get(), _credentialsProvider);
228231

229-
_remoteStore = [[FSTRemoteStore alloc] initWithLocalStore:_localStore
230-
datastore:std::move(datastore)
231-
workerQueue:_workerQueue.get()
232-
onlineStateHandler:[self](OnlineState onlineState) {
233-
[self.syncEngine applyChangedOnlineState:onlineState];
234-
}];
232+
_remoteStore = absl::make_unique<RemoteStore>(
233+
_localStore, std::move(datastore), _workerQueue.get(),
234+
[self](OnlineState onlineState) { [self.syncEngine applyChangedOnlineState:onlineState]; });
235235

236236
_syncEngine = [[FSTSyncEngine alloc] initWithLocalStore:_localStore
237-
remoteStore:_remoteStore
237+
remoteStore:_remoteStore.get()
238238
initialUser:user];
239239

240240
_eventManager = [FSTEventManager eventManagerWithSyncEngine:_syncEngine];
241241

242242
// Setup wiring for remote store.
243-
[_remoteStore setSyncEngine:_syncEngine];
243+
_remoteStore->set_sync_engine(_syncEngine);
244244

245245
// NOTE: RemoteStore depends on LocalStore (for persisting stream tokens, refilling mutation
246246
// queue, etc.) so must be started after LocalStore.
247247
[_localStore start];
248-
[_remoteStore start];
248+
_remoteStore->Start();
249249
}
250250

251251
/**
@@ -270,7 +270,7 @@ - (void)credentialDidChangeWithUser:(const User &)user {
270270

271271
- (void)disableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion {
272272
_workerQueue->Enqueue([self, completion] {
273-
[self.remoteStore disableNetwork];
273+
_remoteStore->DisableNetwork();
274274
if (completion) {
275275
self->_userExecutor->Execute([=] { completion(nil); });
276276
}
@@ -279,7 +279,7 @@ - (void)disableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion {
279279

280280
- (void)enableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion {
281281
_workerQueue->Enqueue([self, completion] {
282-
[self.remoteStore enableNetwork];
282+
_remoteStore->EnableNetwork();
283283
if (completion) {
284284
self->_userExecutor->Execute([=] { completion(nil); });
285285
}
@@ -294,7 +294,7 @@ - (void)shutdownWithCompletion:(nullable FSTVoidErrorBlock)completion {
294294
if (self->_lruCallback) {
295295
self->_lruCallback.Cancel();
296296
}
297-
[self.remoteStore shutdown];
297+
_remoteStore->Shutdown();
298298
[self.persistence shutdown];
299299
if (completion) {
300300
self->_userExecutor->Execute([=] { completion(nil); });

Firestore/Source/Core/FSTSyncEngine.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@
1919
#include <vector>
2020

2121
#import "Firestore/Source/Core/FSTTypes.h"
22-
#import "Firestore/Source/Remote/FSTRemoteStore.h"
2322

2423
#include "Firestore/core/src/firebase/firestore/auth/user.h"
2524
#include "Firestore/core/src/firebase/firestore/model/types.h"
25+
#include "Firestore/core/src/firebase/firestore/remote/remote_store.h"
2626
#include "Firestore/core/src/firebase/firestore/util/async_queue.h"
2727

2828
@class FSTLocalStore;
2929
@class FSTMutation;
3030
@class FSTQuery;
31-
@class FSTRemoteStore;
3231
@class FSTViewSnapshot;
3332

3433
using firebase::firestore::model::OnlineState;
@@ -65,7 +64,7 @@ NS_ASSUME_NONNULL_BEGIN
6564

6665
- (instancetype)init NS_UNAVAILABLE;
6766
- (instancetype)initWithLocalStore:(FSTLocalStore *)localStore
68-
remoteStore:(FSTRemoteStore *)remoteStore
67+
remoteStore:(firebase::firestore::remote::RemoteStore *)remoteStore
6968
initialUser:(const firebase::firestore::auth::User &)user
7069
NS_DESIGNATED_INITIALIZER;
7170

@@ -76,7 +75,7 @@ NS_ASSUME_NONNULL_BEGIN
7675

7776
/**
7877
* Initiates a new listen. The FSTLocalStore will be queried for initial data and the listen will
79-
* be sent to the FSTRemoteStore to get remote data. The registered FSTSyncEngineDelegate will be
78+
* be sent to the `RemoteStore` to get remote data. The registered FSTSyncEngineDelegate will be
8079
* notified of resulting view snapshots and/or listen errors.
8180
*
8281
* @return the target ID assigned to the query.

0 commit comments

Comments
 (0)