use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class ServerTimestampTest method verifyTimestampsAreResolved.
/**
* Verifies a snapshot containing setData but with resolved server timestamps.
*/
private void verifyTimestampsAreResolved(DocumentSnapshot snapshot) {
assertTrue(snapshot.exists());
Timestamp when = snapshot.getTimestamp("when");
assertNotNull(when);
// Tolerate up to 48*60*60 seconds of clock skew between client and server. This should be more
// than enough to compensate for timezone issues (even after taking daylight saving into
// account) and should allow local clocks to deviate from true time slightly and still pass the
// test.
int deltaSec = 48 * 60 * 60;
Timestamp now = Timestamp.now();
assertTrue("resolved timestamp (" + when + ") should be within " + deltaSec + "s of now (" + now + ")", Math.abs(when.getSeconds() - now.getSeconds()) < deltaSec);
// Validate the rest of the document.
assertEquals(expectedDataWithTimestamp(when), snapshot.getData());
}
use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class ServerTimestampTest method verifyTimestampsAreEstimates.
/**
* Verifies a snapshot containing setData but with local estimates for server timestamps.
*/
private void verifyTimestampsAreEstimates(DocumentSnapshot snapshot) {
assertTrue(snapshot.exists());
Timestamp when = snapshot.getTimestamp("when", ServerTimestampBehavior.ESTIMATE);
assertNotNull(when);
assertEquals(expectedDataWithTimestamp(when), snapshot.getData(ServerTimestampBehavior.ESTIMATE));
}
use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class TypeTest method testCanReadAndWriteTimestamps.
@Test
public void testCanReadAndWriteTimestamps() {
Timestamp timestamp = new Timestamp(100, 123000000);
verifySuccessfulWriteReadCycle(map("timestamp", timestamp), testDoc());
}
use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class WriteBatchTest method testWriteTheSameServerTimestampAcrossWrites.
@Test
public void testWriteTheSameServerTimestampAcrossWrites() {
CollectionReference collection = testCollection();
DocumentReference docA = collection.document("a");
DocumentReference docB = collection.document("b");
EventAccumulator<QuerySnapshot> accumulator = new EventAccumulator<>();
collection.addSnapshotListener(MetadataChanges.INCLUDE, accumulator.listener());
QuerySnapshot initialSnap = accumulator.await();
assertEquals(0, initialSnap.size());
// Atomically write two documents with server timestamps.
waitFor(collection.getFirestore().batch().set(docA, map("when", FieldValue.serverTimestamp())).set(docB, map("when", FieldValue.serverTimestamp())).commit());
QuerySnapshot localSnap = accumulator.await();
assertTrue(localSnap.getMetadata().hasPendingWrites());
assertEquals(asList(map("when", null), map("when", null)), querySnapshotToValues(localSnap));
QuerySnapshot serverSnap = accumulator.awaitRemoteEvent();
assertFalse(serverSnap.getMetadata().hasPendingWrites());
assertEquals(2, serverSnap.size());
Timestamp when = serverSnap.getDocuments().get(0).getTimestamp("when");
assertNotNull(when);
assertEquals(asList(map("when", when), map("when", when)), querySnapshotToValues(serverSnap));
}
use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class SQLiteTargetCache method start.
void start() {
// Store exactly one row in the table. If the row exists at all, it's the global metadata.
int found = db.query("SELECT highest_target_id, highest_listen_sequence_number, " + "last_remote_snapshot_version_seconds, last_remote_snapshot_version_nanos, " + "target_count FROM target_globals LIMIT 1").first(row -> {
highestTargetId = row.getInt(0);
lastListenSequenceNumber = row.getInt(1);
lastRemoteSnapshotVersion = new SnapshotVersion(new Timestamp(row.getLong(2), row.getInt(3)));
targetCount = row.getLong(4);
});
hardAssert(found == 1, "Missing target_globals entry");
}
Aggregations