23
23
import static com .google .firebase .firestore .testutil .TestUtil .streamToken ;
24
24
import static java .util .Arrays .asList ;
25
25
import static java .util .Collections .emptyList ;
26
- import static org .hamcrest .Matchers .greaterThan ;
27
- import static org .hamcrest .Matchers .lessThan ;
28
26
import static org .junit .Assert .assertEquals ;
29
27
import static org .junit .Assert .assertFalse ;
30
28
import static org .junit .Assert .assertNotNull ;
@@ -103,38 +101,6 @@ public void testCountBatches() {
103
101
assertTrue (mutationQueue .isEmpty ());
104
102
}
105
103
106
- @ Test
107
- public void testAcknowledgeBatchId () {
108
- // Initial state of an empty queue
109
- assertEquals (MutationBatch .UNKNOWN , mutationQueue .getHighestAcknowledgedBatchId ());
110
-
111
- // Adding mutation batches should not change the highest acked batchId.
112
- MutationBatch batch1 = addMutationBatch ();
113
- MutationBatch batch2 = addMutationBatch ();
114
- MutationBatch batch3 = addMutationBatch ();
115
- assertThat (batch1 .getBatchId (), greaterThan (MutationBatch .UNKNOWN ));
116
- assertThat (batch2 .getBatchId (), greaterThan (batch1 .getBatchId ()));
117
- assertThat (batch3 .getBatchId (), greaterThan (batch2 .getBatchId ()));
118
-
119
- assertEquals (MutationBatch .UNKNOWN , mutationQueue .getHighestAcknowledgedBatchId ());
120
-
121
- acknowledgeBatch (batch1 );
122
- assertEquals (batch1 .getBatchId (), mutationQueue .getHighestAcknowledgedBatchId ());
123
-
124
- acknowledgeBatch (batch2 );
125
- assertEquals (batch2 .getBatchId (), mutationQueue .getHighestAcknowledgedBatchId ());
126
-
127
- removeMutationBatches (batch1 );
128
- assertEquals (batch2 .getBatchId (), mutationQueue .getHighestAcknowledgedBatchId ());
129
-
130
- removeMutationBatches (batch2 );
131
- assertEquals (batch2 .getBatchId (), mutationQueue .getHighestAcknowledgedBatchId ());
132
-
133
- // Batch 3 never acknowledged.
134
- removeMutationBatches (batch3 );
135
- assertEquals (batch2 .getBatchId (), mutationQueue .getHighestAcknowledgedBatchId ());
136
- }
137
-
138
104
@ Test
139
105
public void testAcknowledgeThenRemove () {
140
106
MutationBatch batch1 = addMutationBatch ();
@@ -147,44 +113,6 @@ public void testAcknowledgeThenRemove() {
147
113
});
148
114
149
115
assertEquals (0 , batchCount ());
150
- assertEquals (batch1 .getBatchId (), mutationQueue .getHighestAcknowledgedBatchId ());
151
- }
152
-
153
- @ Test
154
- public void testHighestAcknowledgedBatchIdNeverExceedsNextBatchId () {
155
- MutationBatch batch1 = addMutationBatch ();
156
- MutationBatch batch2 = addMutationBatch ();
157
- acknowledgeBatch (batch1 );
158
- acknowledgeBatch (batch2 );
159
- assertEquals (batch2 .getBatchId (), mutationQueue .getHighestAcknowledgedBatchId ());
160
-
161
- removeMutationBatches (batch1 , batch2 );
162
- assertEquals (batch2 .getBatchId (), mutationQueue .getHighestAcknowledgedBatchId ());
163
-
164
- // Restart the queue so that nextBatchId will be reset.
165
- mutationQueue = persistence .getMutationQueue (User .UNAUTHENTICATED );
166
- mutationQueue .start ();
167
-
168
- persistence .runTransaction ("Start mutationQueue" , () -> mutationQueue .start ());
169
-
170
- // Verify that on restart with an empty queue, nextBatchId falls to a lower value.
171
- assertThat (mutationQueue .getNextBatchId (), lessThan (batch2 .getBatchId ()));
172
-
173
- // As a result highestAcknowledgedBatchId must also reset lower.
174
- assertEquals (MutationBatch .UNKNOWN , mutationQueue .getHighestAcknowledgedBatchId ());
175
-
176
- // The mutation queue will reset the next batchId after all mutations are removed so adding
177
- // another mutation will cause a collision.
178
- MutationBatch newBatch = addMutationBatch ();
179
- assertEquals (batch1 .getBatchId (), newBatch .getBatchId ());
180
-
181
- // Restart the queue with one unacknowledged batch in it.
182
- persistence .runTransaction ("Start mutationQueue" , () -> mutationQueue .start ());
183
-
184
- assertEquals (newBatch .getBatchId () + 1 , mutationQueue .getNextBatchId ());
185
-
186
- // highestAcknowledgedBatchId must still be MutationBatch.UNKNOWN.
187
- assertEquals (MutationBatch .UNKNOWN , mutationQueue .getHighestAcknowledgedBatchId ());
188
116
}
189
117
190
118
@ Test
@@ -265,24 +193,6 @@ public void testNextMutationBatchAfterBatchIdSkipsAcknowledgedBatches() {
265
193
mutationQueue .getNextMutationBatchAfterBatchId (batches .get (1 ).getBatchId ()));
266
194
}
267
195
268
- @ Test
269
- public void testAllMutationBatchesThroughBatchID () {
270
- List <MutationBatch > batches = createBatches (10 );
271
- makeHoles (asList (2 , 6 , 7 ), batches );
272
-
273
- List <MutationBatch > found ;
274
- List <MutationBatch > expected ;
275
-
276
- found = mutationQueue .getAllMutationBatchesThroughBatchId (batches .get (0 ).getBatchId () - 1 );
277
- assertEquals (emptyList (), found );
278
-
279
- for (int i = 0 ; i < batches .size (); i ++) {
280
- found = mutationQueue .getAllMutationBatchesThroughBatchId (batches .get (i ).getBatchId ());
281
- expected = batches .subList (0 , i + 1 );
282
- assertEquals (expected , found );
283
- }
284
- }
285
-
286
196
@ Test
287
197
public void testAllMutationBatchesAffectingDocumentKey () {
288
198
List <Mutation > mutations =
@@ -442,7 +352,7 @@ public void testRemoveMutationBatches() {
442
352
443
353
List <MutationBatch > found ;
444
354
445
- found = mutationQueue .getAllMutationBatchesThroughBatchId ( last . getBatchId () );
355
+ found = mutationQueue .getAllMutationBatches ( );
446
356
assertEquals (batches , found );
447
357
assertEquals (9 , found .size ());
448
358
@@ -452,14 +362,14 @@ public void testRemoveMutationBatches() {
452
362
batches .remove (batches .get (0 ));
453
363
assertEquals (6 , batchCount ());
454
364
455
- found = mutationQueue .getAllMutationBatchesThroughBatchId ( last . getBatchId () );
365
+ found = mutationQueue .getAllMutationBatches ( );
456
366
assertEquals (batches , found );
457
367
assertEquals (6 , found .size ());
458
368
459
369
removeMutationBatches (batches .remove (batches .size () - 1 ));
460
370
assertEquals (5 , batchCount ());
461
371
462
- found = mutationQueue .getAllMutationBatchesThroughBatchId ( last . getBatchId () );
372
+ found = mutationQueue .getAllMutationBatches ( );
463
373
assertEquals (batches , found );
464
374
assertEquals (5 , found .size ());
465
375
@@ -469,12 +379,12 @@ public void testRemoveMutationBatches() {
469
379
removeMutationBatches (batches .remove (1 ));
470
380
assertEquals (3 , batchCount ());
471
381
472
- found = mutationQueue .getAllMutationBatchesThroughBatchId ( last . getBatchId () );
382
+ found = mutationQueue .getAllMutationBatches ( );
473
383
assertEquals (batches , found );
474
384
assertEquals (3 , found .size ());
475
385
476
386
removeMutationBatches (batches .toArray (new MutationBatch [0 ]));
477
- found = mutationQueue .getAllMutationBatchesThroughBatchId ( last . getBatchId () );
387
+ found = mutationQueue .getAllMutationBatches ( );
478
388
assertEquals (emptyList (), found );
479
389
assertEquals (0 , found .size ());
480
390
assertTrue (mutationQueue .isEmpty ());
@@ -496,7 +406,6 @@ public void testStreamToken() {
496
406
persistence .runTransaction (
497
407
"acknowledgeBatchId" , () -> mutationQueue .acknowledgeBatch (batch1 , streamToken2 ));
498
408
499
- assertEquals (batch1 .getBatchId (), mutationQueue .getHighestAcknowledgedBatchId ());
500
409
assertEquals (streamToken2 , mutationQueue .getLastStreamToken ());
501
410
}
502
411
0 commit comments