25
25
26
26
#import " Firestore/Source/API/FIRFieldValue+Internal.h"
27
27
#import " Firestore/Source/Local/FSTPersistence.h"
28
- #import " Firestore/Source/Model/FSTMutationBatch.h"
29
28
#import " Firestore/Source/Util/FSTClasses.h"
30
29
31
30
#import " Firestore/Example/Tests/Local/FSTLocalStoreTests.h"
38
37
#include " Firestore/core/src/firebase/firestore/local/query_data.h"
39
38
#include " Firestore/core/src/firebase/firestore/model/document_map.h"
40
39
#include " Firestore/core/src/firebase/firestore/model/document_set.h"
40
+ #include " Firestore/core/src/firebase/firestore/model/mutation_batch_result.h"
41
41
#include " Firestore/core/src/firebase/firestore/remote/remote_event.h"
42
42
#include " Firestore/core/src/firebase/firestore/remote/watch_change.h"
43
43
#include " Firestore/core/src/firebase/firestore/util/status.h"
57
57
using firebase::firestore::model::ListenSequenceNumber;
58
58
using firebase::firestore::model::MaybeDocument;
59
59
using firebase::firestore::model::Mutation;
60
+ using firebase::firestore::model::MutationBatch;
61
+ using firebase::firestore::model::MutationBatchResult;
60
62
using firebase::firestore::model::MutationResult;
61
63
using firebase::firestore::model::DocumentMap;
62
64
using firebase::firestore::model::MaybeDocumentMap;
@@ -106,12 +108,12 @@ @interface FSTLocalStoreTests ()
106
108
@property (nonatomic , strong , readwrite ) id <FSTPersistence> localStorePersistence;
107
109
@property (nonatomic , strong , readwrite ) FSTLocalStore *localStore;
108
110
109
- @property (nonatomic , strong , readonly ) NSMutableArray <FSTMutationBatch *> *batches;
110
111
@property (nonatomic , assign , readwrite ) TargetId lastTargetID;
111
112
112
113
@end
113
114
114
115
@implementation FSTLocalStoreTests {
116
+ std::vector<MutationBatch> _batches;
115
117
MaybeDocumentMap _lastChanges;
116
118
}
117
119
@@ -128,7 +130,6 @@ - (void)setUp {
128
130
initialUser:User: :Unauthenticated ()];
129
131
[self .localStore start ];
130
132
131
- _batches = [NSMutableArray array ];
132
133
_lastTargetID = 0 ;
133
134
}
134
135
@@ -156,16 +157,14 @@ - (BOOL)isTestBaseClass {
156
157
}
157
158
158
159
- (void )writeMutation : (Mutation)mutation {
159
- [self writeMutations: {mutation}];
160
+ [self writeMutations: {std::move ( mutation) }];
160
161
}
161
162
162
163
- (void )writeMutations : (std::vector<Mutation> &&)mutations {
163
164
auto mutationsCopy = mutations;
164
165
LocalWriteResult result = [self .localStore locallyWriteMutations: std: :move (mutationsCopy)];
165
- [self .batches addObject: [[FSTMutationBatch alloc ] initWithBatchID: result.batch_id ()
166
- localWriteTime:Timestamp: :Now ()
167
- baseMutations: {}
168
- mutations:std: :move (mutations)]];
166
+ _batches.emplace_back (result.batch_id (), Timestamp::Now (), std::vector<Mutation>{},
167
+ std::move (mutations));
169
168
_lastChanges = result.changes ();
170
169
}
171
170
@@ -179,9 +178,12 @@ - (void)notifyLocalViewChanges:(LocalViewChanges)changes {
179
178
180
179
- (void )acknowledgeMutationWithVersion : (FSTTestSnapshotVersion)documentVersion
181
180
transformResult : (id _Nullable)transformResult {
182
- FSTMutationBatch *batch = [self .batches firstObject ];
183
- [self .batches removeObjectAtIndex: 0 ];
184
- XCTAssertEqual (batch.mutations .size (), 1 , @" Acknowledging more than one mutation not supported." );
181
+ XCTAssertGreaterThan (_batches.size (), 0 , @" Missing batch to acknowledge." );
182
+ MutationBatch batch = _batches.front ();
183
+ _batches.erase (_batches.begin ());
184
+
185
+ XCTAssertEqual (batch.mutations ().size (), 1 ,
186
+ @" Acknowledging more than one mutation not supported." );
185
187
SnapshotVersion version = testutil::Version (documentVersion);
186
188
187
189
absl::optional<std::vector<FieldValue>> mutationTransformResult;
@@ -190,10 +192,7 @@ - (void)acknowledgeMutationWithVersion:(FSTTestSnapshotVersion)documentVersion
190
192
}
191
193
192
194
MutationResult mutationResult (version, mutationTransformResult);
193
- FSTMutationBatchResult *result = [FSTMutationBatchResult resultWithBatch: batch
194
- commitVersion: version
195
- mutationResults: {mutationResult}
196
- streamToken: nil ];
195
+ MutationBatchResult result (batch, version, {mutationResult}, {});
197
196
_lastChanges = [self .localStore acknowledgeBatchWithResult: result];
198
197
}
199
198
@@ -202,9 +201,9 @@ - (void)acknowledgeMutationWithVersion:(FSTTestSnapshotVersion)documentVersion {
202
201
}
203
202
204
203
- (void )rejectMutation {
205
- FSTMutationBatch * batch = [ self .batches firstObject ] ;
206
- [ self .batches removeObjectAtIndex: 0 ] ;
207
- _lastChanges = [self .localStore rejectBatchID: batch.batchID ];
204
+ MutationBatch batch = _batches. front () ;
205
+ _batches. erase (_batches. begin ()) ;
206
+ _lastChanges = [self .localStore rejectBatchID: batch.batch_id () ];
208
207
}
209
208
210
209
- (TargetId)allocateQuery : (core::Query)query {
@@ -268,11 +267,8 @@ - (void)testMutationBatchKeys {
268
267
Mutation base = FSTTestSetMutation (@" foo/ignore" , @{@" foo" : @" bar" });
269
268
Mutation set1 = FSTTestSetMutation (@" foo/bar" , @{@" foo" : @" bar" });
270
269
Mutation set2 = FSTTestSetMutation (@" bar/baz" , @{@" bar" : @" baz" });
271
- FSTMutationBatch *batch = [[FSTMutationBatch alloc ] initWithBatchID: 1
272
- localWriteTime:Timestamp: :Now ()
273
- baseMutations: {base}
274
- mutations: {set1, set2}];
275
- DocumentKeySet keys = [batch keys ];
270
+ MutationBatch batch = MutationBatch (1 , Timestamp::Now (), {base}, {set1, set2});
271
+ DocumentKeySet keys = batch.keys ();
276
272
XCTAssertEqual (keys.size (), 2u );
277
273
}
278
274
0 commit comments