@@ -71,10 +71,10 @@ - (void)testCountBatches {
71
71
FSTMutationBatch *batch2 = [self addMutationBatch ];
72
72
XCTAssertEqual (2 , [self batchCount ]);
73
73
74
- [self .mutationQueue removeMutationBatch: batch2 ];
74
+ [self .mutationQueue removeMutationBatch: batch1 ];
75
75
XCTAssertEqual (1 , [self batchCount ]);
76
76
77
- [self .mutationQueue removeMutationBatch: batch1 ];
77
+ [self .mutationQueue removeMutationBatch: batch2 ];
78
78
XCTAssertEqual (0 , [self batchCount ]);
79
79
XCTAssertTrue ([self .mutationQueue isEmpty ]);
80
80
});
@@ -98,10 +98,9 @@ - (void)testAcknowledgeBatchID {
98
98
XCTAssertEqual ([self .mutationQueue highestAcknowledgedBatchID ], kFSTBatchIDUnknown );
99
99
100
100
[self .mutationQueue acknowledgeBatch: batch1 streamToken: nil ];
101
- [self .mutationQueue acknowledgeBatch: batch2 streamToken: nil ];
102
- XCTAssertEqual ([self .mutationQueue highestAcknowledgedBatchID ], batch2.batchID );
103
-
104
101
[self .mutationQueue removeMutationBatch: batch1];
102
+
103
+ [self .mutationQueue acknowledgeBatch: batch2 streamToken: nil ];
105
104
XCTAssertEqual ([self .mutationQueue highestAcknowledgedBatchID ], batch2.batchID );
106
105
107
106
[self .mutationQueue removeMutationBatch: batch2];
@@ -139,10 +138,10 @@ - (void)testHighestAcknowledgedBatchIDNeverExceedsNextBatchID {
139
138
140
139
self.persistence .run (" testHighestAcknowledgedBatchIDNeverExceedsNextBatchID" , [&]() {
141
140
[self .mutationQueue acknowledgeBatch: batch1 streamToken: nil ];
141
+ [self .mutationQueue removeMutationBatch: batch1];
142
142
[self .mutationQueue acknowledgeBatch: batch2 streamToken: nil ];
143
143
XCTAssertEqual ([self .mutationQueue highestAcknowledgedBatchID ], batch2.batchID );
144
144
145
- [self .mutationQueue removeMutationBatch: batch1];
146
145
[self .mutationQueue removeMutationBatch: batch2];
147
146
XCTAssertEqual ([self .mutationQueue highestAcknowledgedBatchID ], batch2.batchID );
148
147
});
@@ -186,7 +185,7 @@ - (void)testLookupMutationBatch {
186
185
XCTAssertNil (notFound);
187
186
188
187
NSMutableArray <FSTMutationBatch *> *batches = [self createBatches: 10 ];
189
- NSArray <FSTMutationBatch *> *removed = [self makeHoles: @[ @ 2 , @ 6 , @ 7 ] inBatches: batches];
188
+ NSArray <FSTMutationBatch *> *removed = [self removeFirstBatches: 3 inBatches: batches];
190
189
191
190
// After removing, a batch should not be found
192
191
for (NSUInteger i = 0 ; i < removed.count ; i++) {
@@ -211,10 +210,7 @@ - (void)testNextMutationBatchAfterBatchID {
211
210
212
211
self.persistence .run (" testNextMutationBatchAfterBatchID" , [&]() {
213
212
NSMutableArray <FSTMutationBatch *> *batches = [self createBatches: 10 ];
214
-
215
- // This is an array of successors assuming the removals below will happen:
216
- NSArray <FSTMutationBatch *> *afters = @[ batches[3 ], batches[8 ], batches[8 ] ];
217
- NSArray <FSTMutationBatch *> *removed = [self makeHoles: @[ @2 , @6 , @7 ] inBatches: batches];
213
+ NSArray <FSTMutationBatch *> *removed = [self removeFirstBatches: 3 inBatches: batches];
218
214
219
215
for (NSUInteger i = 0 ; i < batches.count - 1 ; i++) {
220
216
FSTMutationBatch *current = batches[i];
@@ -225,7 +221,7 @@ - (void)testNextMutationBatchAfterBatchID {
225
221
226
222
for (NSUInteger i = 0 ; i < removed.count ; i++) {
227
223
FSTMutationBatch *current = removed[i];
228
- FSTMutationBatch *next = afters[i ];
224
+ FSTMutationBatch *next = batches[ 0 ];
229
225
FSTMutationBatch *found = [self .mutationQueue nextMutationBatchAfterBatchID: current.batchID];
230
226
XCTAssertEqual (found.batchID , next.batchID );
231
227
}
@@ -262,26 +258,6 @@ - (void)testNextMutationBatchAfterBatchIDSkipsAcknowledgedBatches {
262
258
});
263
259
}
264
260
265
- - (void )testAllMutationBatchesThroughBatchID {
266
- if ([self isTestBaseClass ]) return ;
267
-
268
- self.persistence .run (" testAllMutationBatchesThroughBatchID" , [&]() {
269
- NSMutableArray <FSTMutationBatch *> *batches = [self createBatches: 10 ];
270
- [self makeHoles: @[ @2 , @6 , @7 ] inBatches: batches];
271
-
272
- NSArray <FSTMutationBatch *> *found, *expected;
273
-
274
- found = [self .mutationQueue allMutationBatchesThroughBatchID: batches[0 ].batchID - 1 ];
275
- XCTAssertEqualObjects (found, (@[]));
276
-
277
- for (NSUInteger i = 0 ; i < batches.count ; i++) {
278
- found = [self .mutationQueue allMutationBatchesThroughBatchID: batches[i].batchID];
279
- expected = [batches subarrayWithRange: NSMakeRange (0 , i + 1 )];
280
- XCTAssertEqualObjects (found, expected, @" for index %lu " , (unsigned long )i);
281
- }
282
- });
283
- }
284
-
285
261
- (void )testAllMutationBatchesAffectingDocumentKey {
286
262
if ([self isTestBaseClass ]) return ;
287
263
@@ -443,12 +419,11 @@ - (void)testRemoveMutationBatches {
443
419
[self .mutationQueue removeMutationBatch: batches[0 ]];
444
420
[batches removeObjectAtIndex: 0 ];
445
421
446
- FSTMutationBatch *last = batches[batches.count - 1 ];
447
422
XCTAssertEqual ([self batchCount ], 9 );
448
423
449
424
NSArray <FSTMutationBatch *> *found;
450
425
451
- found = [self .mutationQueue allMutationBatchesThroughBatchID: last.batchID ];
426
+ found = [self .mutationQueue allMutationBatches ];
452
427
XCTAssertEqualObjects (found, batches);
453
428
XCTAssertEqual (found.count , 9 );
454
429
@@ -458,35 +433,35 @@ - (void)testRemoveMutationBatches {
458
433
[batches removeObjectsInRange: NSMakeRange (0 , 3 )];
459
434
XCTAssertEqual ([self batchCount ], 6 );
460
435
461
- found = [self .mutationQueue allMutationBatchesThroughBatchID: last.batchID ];
436
+ found = [self .mutationQueue allMutationBatches ];
462
437
XCTAssertEqualObjects (found, batches);
463
438
XCTAssertEqual (found.count , 6 );
464
439
465
- [self .mutationQueue removeMutationBatch: batches[batches.count - 1 ]];
466
- [batches removeObjectAtIndex: batches.count - 1 ];
440
+ [self .mutationQueue removeMutationBatch: batches[0 ]];
441
+ [batches removeObjectAtIndex: 0 ];
467
442
XCTAssertEqual ([self batchCount ], 5 );
468
443
469
- found = [self .mutationQueue allMutationBatchesThroughBatchID: last.batchID ];
444
+ found = [self .mutationQueue allMutationBatches ];
470
445
XCTAssertEqualObjects (found, batches);
471
446
XCTAssertEqual (found.count , 5 );
472
447
473
- [self .mutationQueue removeMutationBatch: batches[3 ]];
474
- [batches removeObjectAtIndex: 3 ];
448
+ [self .mutationQueue removeMutationBatch: batches[0 ]];
449
+ [batches removeObjectAtIndex: 0 ];
475
450
XCTAssertEqual ([self batchCount ], 4 );
476
451
477
- [self .mutationQueue removeMutationBatch: batches[1 ]];
478
- [batches removeObjectAtIndex: 1 ];
452
+ [self .mutationQueue removeMutationBatch: batches[0 ]];
453
+ [batches removeObjectAtIndex: 0 ];
479
454
XCTAssertEqual ([self batchCount ], 3 );
480
455
481
- found = [self .mutationQueue allMutationBatchesThroughBatchID: last.batchID ];
456
+ found = [self .mutationQueue allMutationBatches ];
482
457
XCTAssertEqualObjects (found, batches);
483
458
XCTAssertEqual (found.count , 3 );
484
459
XCTAssertFalse ([self .mutationQueue isEmpty ]);
485
460
486
461
for (FSTMutationBatch *batch in batches) {
487
462
[self .mutationQueue removeMutationBatch: batch];
488
463
}
489
- found = [self .mutationQueue allMutationBatchesThroughBatchID: last.batchID ];
464
+ found = [self .mutationQueue allMutationBatches ];
490
465
XCTAssertEqualObjects (found, @[]);
491
466
XCTAssertEqual (found.count , 0 );
492
467
XCTAssertTrue ([self .mutationQueue isEmpty ]);
@@ -554,24 +529,21 @@ - (NSUInteger)batchCount {
554
529
}
555
530
556
531
/* *
557
- * Removes entries from from the given @a batches and returns them.
532
+ * Removes the first n entries from the the given batches and returns them.
558
533
*
559
- * @param holes An array of indexes in the batches array; in increasing order. Indexes are relative
560
- * to the original state of the batches array, not any intermediate state that might occur.
534
+ * @param n The number of batches to remove.
561
535
* @param batches The array to mutate, removing entries from it.
562
536
* @return A new array containing all the entries that were removed from @a batches.
563
537
*/
564
- - (NSArray <FSTMutationBatch *> *)makeHoles : ( NSArray <NSNumber *> *) holes
565
- inBatches : (NSMutableArray <FSTMutationBatch *> *)batches {
566
- NSMutableArray <FSTMutationBatch *> *removed = [NSMutableArray array ];
567
- for ( NSUInteger i = 0 ; i < holes. count ; i++) {
568
- NSUInteger index = holes[i]. unsignedIntegerValue - i;
569
- FSTMutationBatch *batch = batches[ index ];
538
+ - (NSArray <FSTMutationBatch *> *)removeFirstBatches : ( NSUInteger ) n
539
+ inBatches : (NSMutableArray <FSTMutationBatch *> *)batches {
540
+ NSArray <FSTMutationBatch *> *removed = [batches subarrayWithRange: NSMakeRange ( 0 , n) ];
541
+ [batches removeObjectsInRange: NSMakeRange ( 0 , n)];
542
+
543
+ [removed enumerateObjectsUsingBlock: ^( FSTMutationBatch *batch, NSUInteger idx, BOOL *stop) {
570
544
[self .mutationQueue removeMutationBatch: batch];
545
+ }];
571
546
572
- [batches removeObjectAtIndex: index ];
573
- [removed addObject: batch];
574
- }
575
547
return removed;
576
548
}
577
549
0 commit comments