Skip to content

Commit c65004c

Browse files
committed
Addressing comemnts #1
1 parent f1f3542 commit c65004c

File tree

9 files changed

+69
-72
lines changed

9 files changed

+69
-72
lines changed

Firestore/Example/Tests/Integration/FSTDatastoreTests.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,27 +168,27 @@ void ExpectListenEvent(NSString *description) {
168168
[underlying_capture_ expectListenEventWithDescription:description];
169169
}
170170

171-
void ApplyRemoteEvent(const remote::RemoteEvent &remote_event) override {
171+
void ApplyRemoteEvent(const RemoteEvent &remote_event) override {
172172
[underlying_capture_ applyRemoteEvent:remote_event];
173173
}
174174

175-
void HandleRejectedListen(model::TargetId target_id, util::Status error) override {
175+
void HandleRejectedListen(TargetId target_id, Status error) override {
176176
[underlying_capture_ rejectListenWithTargetID:target_id error:error.ToNSError()];
177177
}
178178

179-
void HandleSuccessfulWrite(const model::MutationBatchResult &batch_result) override {
179+
void HandleSuccessfulWrite(const MutationBatchResult &batch_result) override {
180180
[underlying_capture_ applySuccessfulWriteWithResult:batch_result];
181181
}
182182

183-
void HandleRejectedWrite(model::BatchId batch_id, util::Status error) override {
183+
void HandleRejectedWrite(BatchId batch_id, Status error) override {
184184
[underlying_capture_ rejectFailedWriteWithBatchID:batch_id error:error.ToNSError()];
185185
}
186186

187-
void HandleOnlineStateChange(model::OnlineState online_state) override {
187+
void HandleOnlineStateChange(OnlineState online_state) override {
188188
HARD_FAIL("Not implemented");
189189
}
190190

191-
model::DocumentKeySet GetRemoteKeys(model::TargetId target_id) const override {
191+
model::DocumentKeySet GetRemoteKeys(TargetId target_id) const override {
192192
return [underlying_capture_ remoteKeysForTarget:target_id];
193193
}
194194

Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,8 @@ - (instancetype)initWithPersistence:(id<FSTPersistence>)persistence
200200
_datastore = std::make_shared<MockDatastore>(_databaseInfo, _workerQueue,
201201
std::make_shared<EmptyCredentialsProvider>());
202202
_remoteStore = absl::make_unique<RemoteStore>(
203-
_localStore, _datastore, _workerQueue, [self](OnlineState onlineState) {
204-
_syncEngine->HandleOnlineStateChange(onlineState);
205-
// _eventManager->HandleOnlineStateChange(onlineState);
206-
});
203+
_localStore, _datastore, _workerQueue,
204+
[self](OnlineState onlineState) { _syncEngine->HandleOnlineStateChange(onlineState); });
207205
;
208206

209207
_syncEngine = absl::make_unique<SyncEngine>(_localStore, _remoteStore.get(), initialUser);

Firestore/core/src/firebase/firestore/core/event_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class EventManager : public QueryEventCallback {
9797
absl::optional<ViewSnapshot> snapshot_;
9898
};
9999

100-
QueryEventSource* query_event_source_;
100+
QueryEventSource* query_event_source_ = nullptr;
101101
model::OnlineState online_state_ = model::OnlineState::Unknown;
102102
std::unordered_map<core::Query, QueryListenersInfo> queries_;
103103
};

Firestore/core/src/firebase/firestore/core/firestore_client.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_CORE_FIRESTORE_CLIENT_H_
1818
#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_CORE_FIRESTORE_CLIENT_H_
1919

20+
#if !defined(__OBJC__)
21+
#error "This header only supports Objective-C++"
22+
#endif // !defined(__OBJC__)
23+
2024
#import <Foundation/Foundation.h>
2125

2226
#include <memory>
@@ -48,15 +52,11 @@ namespace firebase {
4852
namespace firestore {
4953

5054
namespace remote {
51-
// Forward declaration to make CMAKE build pass as it does not support
52-
// Objective-C protos.
5355
class RemoteStore;
5456
} // namespace remote
5557

5658
namespace core {
5759

58-
// Forward declaration to make CMAKE build pass as it does not support
59-
// Objective-C protos.
6060
class EventManager;
6161
class SyncEngine;
6262

Firestore/core/src/firebase/firestore/core/firestore_client.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ QuerySnapshot result(query.firestore(), query.query(), std::move(snapshot),
429429
std::move(mutations), [callback, shared_this](Status error) {
430430
// Dispatch the result back onto the user dispatch queue.
431431
if (callback) {
432-
shared_this->user_executor()->Execute([=] { callback(error); });
432+
shared_this->user_executor()->Execute(
433+
[=] { callback(std::move(error)); });
433434
}
434435
});
435436
}

Firestore/core/src/firebase/firestore/core/sync_engine.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,28 @@ namespace core {
5252
*/
5353
class QueryEventCallback {
5454
public:
55+
virtual ~QueryEventCallback() = default;
56+
5557
/** Handles a change in online state. */
5658
virtual void HandleOnlineStateChange(model::OnlineState online_state) = 0;
5759
/** Handles new view snapshots. */
5860
virtual void OnViewSnapshots(std::vector<core::ViewSnapshot>&& snapshots) = 0;
5961
/** Handles the failure of a query. */
6062
virtual void OnError(const core::Query& query, util::Status error) = 0;
61-
62-
virtual ~QueryEventCallback() = default;
6363
};
6464

6565
/**
66-
* Interface implemented by `SyncEngine` receive requests from `EventManager`.
66+
* Interface implemented by `SyncEngine` to receive requests from
67+
* `EventManager`.
6768
*/
6869
class QueryEventSource {
6970
public:
71+
virtual ~QueryEventSource() = default;
72+
7073
virtual void SetCallback(QueryEventCallback* callback) = 0;
74+
7175
/**
72-
* Initiates a new listen. The FSTLocalStore will be queried for initial data
76+
* Initiates a new listen. The LocalStore will be queried for initial data
7377
* and the listen will be sent to the `RemoteStore` to get remote data. The
7478
* registered SyncEngineCallback will be notified of resulting view
7579
* snapshots and/or listen errors.
@@ -80,8 +84,6 @@ class QueryEventSource {
8084

8185
/** Stops listening to a query previously listened to via `Listen`. */
8286
virtual void StopListening(const Query& query) = 0;
83-
84-
virtual ~QueryEventSource() = default;
8587
};
8688

8789
/**

Firestore/core/src/firebase/firestore/remote/remote_store.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ class RemoteStoreCallback {
5656
* visible because of the snapshot version the remote event contains.
5757
*/
5858
virtual void ApplyRemoteEvent(const RemoteEvent& remote_event) = 0;
59+
5960
/**
6061
* Handles rejection of listen for the given targetId. This can be triggered
6162
* by the backend for any active target.
6263
*
63-
* @param target_id The targetId corresponding to a listen initiated via
64+
* @param target_id The target ID corresponding to a listen initiated via
6465
* RemoteStore::Listen()
6566
* @param error A description of the condition that has forced the rejection.
6667
* Nearly always this will be an indication that the user is no longer
@@ -85,8 +86,10 @@ class RemoteStoreCallback {
8586
virtual void HandleRejectedWrite(model::BatchId batch_id,
8687
util::Status error) = 0;
8788

88-
/** Applies an OnlineState change to the sync engine and notifies any views of
89-
* the change. */
89+
/**
90+
* Applies an OnlineState change to the sync engine and notifies any views of
91+
* the change.
92+
*/
9093
virtual void HandleOnlineStateChange(model::OnlineState online_state) = 0;
9194

9295
/**

Firestore/core/src/firebase/firestore/remote/remote_store.mm

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,7 @@ QueryData request_query_data(query_data.query(), target_id,
326326
}
327327

328328
// Finally handle remote event
329-
if (sync_engine_) {
330-
sync_engine_->ApplyRemoteEvent(remote_event);
331-
}
329+
sync_engine_->ApplyRemoteEvent(remote_event);
332330
}
333331

334332
void RemoteStore::ProcessTargetError(const WatchTargetChange& change) {
@@ -340,9 +338,7 @@ QueryData request_query_data(query_data.query(), target_id,
340338
if (found != listen_targets_.end()) {
341339
listen_targets_.erase(found);
342340
watch_change_aggregator_->RemoveTarget(target_id);
343-
if (sync_engine_) {
344-
sync_engine_->HandleRejectedListen(target_id, change.cause());
345-
}
341+
sync_engine_->HandleRejectedListen(target_id, change.cause());
346342
}
347343
}
348344
}
@@ -424,9 +420,7 @@ QueryData request_query_data(query_data.query(), target_id,
424420
MutationBatchResult batch_result(std::move(batch), commit_version,
425421
std::move(mutation_results),
426422
write_stream_->GetLastStreamToken());
427-
if (sync_engine_) {
428-
sync_engine_->HandleSuccessfulWrite(batch_result);
429-
}
423+
sync_engine_->HandleSuccessfulWrite(batch_result);
430424

431425
// It's possible that with the completion of this mutation another slot has
432426
// freed up.
@@ -502,9 +496,7 @@ MutationBatchResult batch_result(std::move(batch), commit_version,
502496
// down--this was just a bad request so inhibit backoff on the next restart.
503497
write_stream_->InhibitBackoff();
504498

505-
if (sync_engine_) {
506-
sync_engine_->HandleRejectedWrite(batch.batch_id(), status);
507-
}
499+
sync_engine_->HandleRejectedWrite(batch.batch_id(), status);
508500

509501
// It's possible that with the completion of this mutation another slot has
510502
// freed up.
@@ -522,10 +514,7 @@ MutationBatchResult batch_result(std::move(batch), commit_version,
522514
}
523515

524516
DocumentKeySet RemoteStore::GetRemoteKeysForTarget(TargetId target_id) const {
525-
if (sync_engine_) {
526-
return sync_engine_->GetRemoteKeys(target_id);
527-
}
528-
return DocumentKeySet{};
517+
return sync_engine_->GetRemoteKeys(target_id);
529518
}
530519

531520
absl::optional<QueryData> RemoteStore::GetQueryDataForTarget(

Firestore/core/test/firebase/firestore/core/event_manager_test.mm

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@
2929
#include "gmock/gmock.h"
3030
#include "gtest/gtest.h"
3131

32-
using firebase::firestore::core::EventListener;
33-
using firebase::firestore::core::EventManager;
34-
using firebase::firestore::core::ListenOptions;
35-
using firebase::firestore::core::QueryListener;
36-
using firebase::firestore::core::QueryEventCallback;
37-
using firebase::firestore::core::ViewSnapshot;
38-
using firebase::firestore::model::DocumentKeySet;
39-
using firebase::firestore::model::DocumentSet;
40-
using firebase::firestore::model::OnlineState;
41-
using firebase::firestore::util::StatusOr;
42-
using firebase::firestore::util::StatusOrCallback;
43-
using firebase::firestore::testutil::Query;
32+
namespace firebase {
33+
namespace firestore {
34+
namespace core {
35+
namespace {
36+
37+
using model::DocumentKeySet;
38+
using model::DocumentSet;
39+
using model::OnlineState;
40+
using util::StatusOr;
41+
using util::StatusOrCallback;
42+
using testutil::Query;
4443
using testing::_;
4544
using testing::ElementsAre;
45+
using testing::StrictMock;
4646

4747
ViewSnapshot::Listener NoopViewSnapshotHandler() {
4848
return EventListener<ViewSnapshot>::Create(
@@ -67,17 +67,15 @@
6767
auto listener1 = NoopQueryListener(query);
6868
auto listener2 = NoopQueryListener(query);
6969

70-
MockEventSource mock_event_source;
70+
StrictMock<MockEventSource> mock_event_source;
7171
EXPECT_CALL(mock_event_source, SetCallback(_));
7272
EventManager event_manager(&mock_event_source);
7373

7474
EXPECT_CALL(mock_event_source, Listen(query));
7575
event_manager.AddQueryListener(listener1);
7676

77-
EXPECT_CALL(mock_event_source, Listen(_)).Times(0);
77+
// Expecting no activity from mock_event_source.
7878
event_manager.AddQueryListener(listener2);
79-
80-
EXPECT_CALL(mock_event_source, StopListening(_)).Times(0);
8179
event_manager.RemoveQueryListener(listener2);
8280

8381
EXPECT_CALL(mock_event_source, StopListening(query));
@@ -112,33 +110,34 @@ ViewSnapshot make_empty_view_snapshot(const core::Query& query) {
112110
TEST(EventManagerTest, NotifiesListenersInTheRightOrder) {
113111
core::Query query1 = Query("foo/bar");
114112
core::Query query2 = Query("bar/baz");
115-
std::vector<std::string> eventOrder;
116-
117-
auto listener1 =
118-
QueryListener::Create(query1, [&eventOrder](StatusOr<ViewSnapshot>) {
119-
eventOrder.push_back("listener1");
120-
});
121-
auto listener2 =
122-
QueryListener::Create(query2, [&eventOrder](StatusOr<ViewSnapshot>) {
123-
eventOrder.push_back("listener2");
124-
});
125-
auto listener3 =
126-
QueryListener::Create(query1, [&eventOrder](StatusOr<ViewSnapshot>) {
127-
eventOrder.push_back("listener3");
128-
});
113+
std::vector<std::string> event_order;
114+
115+
auto listener1 = QueryListener::Create(query1, [&](StatusOr<ViewSnapshot>) {
116+
event_order.push_back("listener1");
117+
});
118+
auto listener2 = QueryListener::Create(query2, [&](StatusOr<ViewSnapshot>) {
119+
event_order.push_back("listener2");
120+
});
121+
auto listener3 = QueryListener::Create(query1, [&](StatusOr<ViewSnapshot>) {
122+
event_order.push_back("listener3");
123+
});
129124

130125
MockEventSource mock_event_source;
131126
EventManager event_manager(&mock_event_source);
132127

128+
EXPECT_CALL(mock_event_source, Listen(query1));
133129
event_manager.AddQueryListener(listener1);
130+
131+
EXPECT_CALL(mock_event_source, Listen(query2));
134132
event_manager.AddQueryListener(listener2);
133+
135134
event_manager.AddQueryListener(listener3);
136135

137136
ViewSnapshot snapshot1 = make_empty_view_snapshot(query1);
138137
ViewSnapshot snapshot2 = make_empty_view_snapshot(query2);
139138
event_manager.OnViewSnapshots({snapshot1, snapshot2});
140139

141-
ASSERT_THAT(eventOrder, ElementsAre("listener1", "listener3", "listener2"));
140+
ASSERT_THAT(event_order, ElementsAre("listener1", "listener3", "listener2"));
142141
}
143142

144143
TEST(EventManagerTest, WillForwardOnlineStateChanges) {
@@ -171,3 +170,8 @@ void OnOnlineStateChanged(OnlineState online_state) override {
171170
ASSERT_THAT(fake_listener->events,
172171
ElementsAre(OnlineState::Unknown, OnlineState::Online));
173172
}
173+
174+
} // namespace
175+
} // namespace core
176+
} // namespace firestore
177+
} // namespace firebase

0 commit comments

Comments
 (0)