|
25 | 25 | import static java.util.Arrays.asList;
|
26 | 26 | import static org.junit.Assert.assertEquals;
|
27 | 27 | import static org.junit.Assert.assertFalse;
|
| 28 | +import static org.junit.Assert.assertNull; |
28 | 29 |
|
29 | 30 | import com.google.firebase.firestore.FieldValue;
|
30 | 31 | import com.google.firebase.firestore.auth.User;
|
@@ -110,6 +111,46 @@ public void testCreateOverlayFromSet() {
|
110 | 111 | assertFalse(migrationManager.hasPendingOverlayMigration());
|
111 | 112 | }
|
112 | 113 |
|
| 114 | + @Test |
| 115 | + public void testSkipsIfAlreadyMigrated() { |
| 116 | + writeRemoteDocument(doc("foo/bar", 2, map("it", "original"))); |
| 117 | + writeMutation(setMutation("foo/bar", map("foo", "bar"))); |
| 118 | + |
| 119 | + // Switch to new persistence and run migrations |
| 120 | + this.persistence.shutdown(); |
| 121 | + persistence = PersistenceTestHelpers.createSQLitePersistence("test-data-migration"); |
| 122 | + IndexBackfiller indexBackfiller = new IndexBackfiller(persistence, new AsyncQueue()); |
| 123 | + localStore = |
| 124 | + new LocalStore(persistence, indexBackfiller, new QueryEngine(), User.UNAUTHENTICATED); |
| 125 | + localStore.start(); |
| 126 | + |
| 127 | + assertEquals( |
| 128 | + setMutation("foo/bar", map("foo", "bar")), |
| 129 | + persistence |
| 130 | + .getDocumentOverlayCache(User.UNAUTHENTICATED) |
| 131 | + .getOverlay(key("foo/bar")) |
| 132 | + .getMutation()); |
| 133 | + |
| 134 | + // Delete the overlay to verify migration is skipped the second time. |
| 135 | + persistence.getDocumentOverlayCache(User.UNAUTHENTICATED).removeOverlaysForBatchId(1); |
| 136 | + |
| 137 | + // Switch to new persistence and run migrations which should be a no-op. |
| 138 | + this.persistence.shutdown(); |
| 139 | + persistence = PersistenceTestHelpers.createSQLitePersistence("test-data-migration"); |
| 140 | + indexBackfiller = new IndexBackfiller(persistence, new AsyncQueue()); |
| 141 | + localStore = |
| 142 | + new LocalStore(persistence, indexBackfiller, new QueryEngine(), User.UNAUTHENTICATED); |
| 143 | + localStore.start(); |
| 144 | + |
| 145 | + SQLiteOverlayMigrationManager migrationManager = |
| 146 | + (SQLiteOverlayMigrationManager) persistence.getOverlayMigrationManager(); |
| 147 | + assertFalse(migrationManager.hasPendingOverlayMigration()); |
| 148 | + |
| 149 | + // We deleted the overlay earlier and the migration is not run again, so we get a null. |
| 150 | + assertNull( |
| 151 | + persistence.getDocumentOverlayCache(User.UNAUTHENTICATED).getOverlay(key("foo/bar"))); |
| 152 | + } |
| 153 | + |
113 | 154 | @Test
|
114 | 155 | public void testCreateOverlayFromDelete() {
|
115 | 156 | writeRemoteDocument(doc("foo/bar", 2, map("it", "original")));
|
|
0 commit comments