use of com.google.firebase.firestore.bundle.BundleMetadata in project firebase-android-sdk by firebase.
the class LocalStoreTestCase method assertHasNewerBundle.
private void assertHasNewerBundle(String bundleId, int createTime) {
boolean hasNewerBundle = localStore.hasNewerBundle(new BundleMetadata(bundleId, /* version= */
1, version(createTime), /* totalDocuments= */
1, /* totalBytes= */
10));
assertTrue(hasNewerBundle);
}
use of com.google.firebase.firestore.bundle.BundleMetadata in project firebase-android-sdk by firebase.
the class SyncEngine method loadBundle.
public void loadBundle(BundleReader bundleReader, LoadBundleTask resultTask) {
try {
BundleMetadata bundleMetadata = bundleReader.getBundleMetadata();
boolean hasNewerBundle = localStore.hasNewerBundle(bundleMetadata);
if (hasNewerBundle) {
resultTask.setResult(LoadBundleTaskProgress.forSuccess(bundleMetadata));
return;
}
@Nullable LoadBundleTaskProgress progress = LoadBundleTaskProgress.forInitial(bundleMetadata);
resultTask.updateProgress(progress);
BundleLoader bundleLoader = new BundleLoader(localStore, bundleMetadata);
long currentBytesRead = 0;
BundleElement bundleElement;
while ((bundleElement = bundleReader.getNextElement()) != null) {
long oldBytesRead = currentBytesRead;
currentBytesRead = bundleReader.getBytesRead();
progress = bundleLoader.addElement(bundleElement, currentBytesRead - oldBytesRead);
if (progress != null) {
resultTask.updateProgress(progress);
}
}
ImmutableSortedMap<DocumentKey, Document> changes = bundleLoader.applyChanges();
// TODO(b/160876443): This currently raises snapshots with `fromCache=false` if users already
// listen to some queries and bundles has newer version.
emitNewSnapsAndNotifyLocalStore(changes, /* remoteEvent= */
null);
// Save metadata, so loading the same bundle will skip.
localStore.saveBundle(bundleMetadata);
resultTask.setResult(LoadBundleTaskProgress.forSuccess(bundleMetadata));
} catch (Exception e) {
Logger.warn("Firestore", "Loading bundle failed : %s", e);
resultTask.setException(new FirebaseFirestoreException("Bundle failed to load", FirebaseFirestoreException.Code.INVALID_ARGUMENT, e));
} finally {
try {
bundleReader.close();
} catch (IOException e) {
Logger.warn("SyncEngine", "Exception while closing bundle", e);
}
}
}
use of com.google.firebase.firestore.bundle.BundleMetadata in project firebase-android-sdk by firebase.
the class BundleCacheTestCase method testReturnsSavedBundle.
@Test
public void testReturnsSavedBundle() {
BundleMetadata expectedBundleMetadata = new BundleMetadata("bundle-1", 1, new SnapshotVersion(Timestamp.now()), /* totalDocuments= */
1, /* totalBytes= */
10);
bundleCache.saveBundleMetadata(expectedBundleMetadata);
BundleMetadata actualBundleMetadata = bundleCache.getBundleMetadata("bundle-1");
assertEquals(expectedBundleMetadata, actualBundleMetadata);
// Overwrite
expectedBundleMetadata = new BundleMetadata("bundle-1", 2, new SnapshotVersion(Timestamp.now()), /* totalDocuments= */
1, /* totalBytes= */
10);
bundleCache.saveBundleMetadata(expectedBundleMetadata);
actualBundleMetadata = bundleCache.getBundleMetadata("bundle-1");
assertEquals(expectedBundleMetadata, actualBundleMetadata);
}
use of com.google.firebase.firestore.bundle.BundleMetadata in project firebase-android-sdk by firebase.
the class LocalStoreTestCase method assertNoNewerBundle.
private void assertNoNewerBundle(String bundleId, int createTime) {
boolean hasNewerBundle = localStore.hasNewerBundle(new BundleMetadata(bundleId, /* version= */
1, version(createTime), /* totalDocuments= */
1, /* totalBytes= */
10));
assertFalse(hasNewerBundle);
}
Aggregations