use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class SQLiteTargetCache method saveTargetData.
private void saveTargetData(TargetData targetData) {
int targetId = targetData.getTargetId();
String canonicalId = targetData.getTarget().getCanonicalId();
Timestamp version = targetData.getSnapshotVersion().getTimestamp();
com.google.firebase.firestore.proto.Target targetProto = localSerializer.encodeTargetData(targetData);
db.execute("INSERT OR REPLACE INTO targets (" + "target_id, " + "canonical_id, " + "snapshot_version_seconds, " + "snapshot_version_nanos, " + "resume_token, " + "last_listen_sequence_number, " + "target_proto) " + "VALUES (?, ?, ?, ?, ?, ?, ?)", targetId, canonicalId, version.getSeconds(), version.getNanoseconds(), targetData.getResumeToken().toByteArray(), targetData.getSequenceNumber(), targetProto.toByteArray());
}
use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class UserDataWriterTest method testConvertsTimestampValue.
@Test
public void testConvertsTimestampValue() {
List<Timestamp> testCases = asList(new Timestamp(0, 0), new Timestamp(1356048000L, 0));
for (Timestamp t : testCases) {
Value value = wrap(t);
assertValueType(Value.ValueTypeCase.TIMESTAMP_VALUE, value);
Object convertedValue = convertValue(value);
assertEquals(t, convertedValue);
}
}
use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class UserDataWriterTest method testConvertsDateValue.
@Test
public void testConvertsDateValue() {
UserDataWriter dateWriter = new UserDataWriter(TestUtil.firestore(), DocumentSnapshot.ServerTimestampBehavior.DEFAULT);
List<Date> testCases = asList(new Date(0), new Date(1356048000000L));
for (Date d : testCases) {
Value value = wrap(d);
assertValueType(Value.ValueTypeCase.TIMESTAMP_VALUE, value);
Object convertedValue = dateWriter.convertValue(value);
assertTrue(convertedValue instanceof Timestamp);
assertEquals(d, ((Timestamp) convertedValue).toDate());
}
}
use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class QueryTest method testCanonicalIdsAreStable.
@Test
public void testCanonicalIdsAreStable() {
// This test aims to ensure that we do not break canonical IDs, as they are used as keys in
// the TargetCache.
Query baseQuery = Query.atPath(ResourcePath.fromString("collection"));
assertCanonicalId(baseQuery, "collection|f:|ob:__name__asc");
assertCanonicalId(baseQuery.filter(filter("a", ">", "a")), "collection|f:a>a|ob:aasc__name__asc");
assertCanonicalId(baseQuery.filter(filter("a", "<=", new GeoPoint(90.0, -90.0))), "collection|f:a<=geo(90.0,-90.0)|ob:aasc__name__asc");
assertCanonicalId(baseQuery.filter(filter("a", "<=", new Timestamp(60, 3000))), "collection|f:a<=time(60,3000)|ob:aasc__name__asc");
assertCanonicalId(baseQuery.filter(filter("a", ">=", Blob.fromBytes(new byte[] { 1, 2, 3 }))), "collection|f:a>=010203|ob:aasc__name__asc");
assertCanonicalId(baseQuery.filter(filter("a", "==", Arrays.asList(1, 2, 3))), "collection|f:a==[1,2,3]|ob:__name__asc");
assertCanonicalId(baseQuery.filter(filter("a", "!=", Arrays.asList(1, 2, 3))), "collection|f:a!=[1,2,3]|ob:aasc__name__asc");
assertCanonicalId(baseQuery.filter(filter("a", "==", Double.NaN)), "collection|f:a==NaN|ob:__name__asc");
assertCanonicalId(baseQuery.filter(filter("__name__", "==", ref("collection/id"))), "collection|f:__name__==collection/id|ob:__name__asc");
assertCanonicalId(baseQuery.filter(filter("a", "==", map("a", "b", "inner", map("d", "c")))), "collection|f:a=={a:b,inner:{d:c}}|ob:__name__asc");
assertCanonicalId(baseQuery.filter(filter("a", "in", Arrays.asList(1, 2, 3))), "collection|f:ain[1,2,3]|ob:__name__asc");
assertCanonicalId(baseQuery.filter(filter("a", "not-in", Arrays.asList(1, 2, 3))), "collection|f:anot_in[1,2,3]|ob:aasc__name__asc");
assertCanonicalId(baseQuery.filter(filter("a", "array-contains-any", Arrays.asList(1, 2, 3))), "collection|f:aarray_contains_any[1,2,3]|ob:__name__asc");
assertCanonicalId(baseQuery.filter(filter("a", "array-contains", "a")), "collection|f:aarray_containsa|ob:__name__asc");
assertCanonicalId(baseQuery.orderBy(orderBy("a")), "collection|f:|ob:aasc__name__asc");
assertCanonicalId(baseQuery.orderBy(orderBy("a")).startAt(bound(/* inclusive= */
true, "foo", Arrays.asList(1, 2, 3))), "collection|f:|ob:aasc__name__asc|lb:b:foo,[1,2,3]");
assertCanonicalId(baseQuery.orderBy(orderBy("a")).endAt(bound(/* inclusive= */
true, "foo", Arrays.asList(1, 2, 3))), "collection|f:|ob:aasc__name__asc|ub:a:foo,[1,2,3]");
assertCanonicalId(baseQuery.limitToFirst(5), "collection|f:|ob:__name__asc|l:5");
assertCanonicalId(baseQuery.limitToLast(5), "collection|f:|ob:__name__desc|l:5");
}
use of com.google.firebase.Timestamp in project firebase-android-sdk by firebase.
the class MutationTest method testAppliesServerAckedServerTimestampTransformsToDocuments.
@Test
public void testAppliesServerAckedServerTimestampTransformsToDocuments() {
Map<String, Object> data = map("foo", map("bar", "bar-value"), "baz", "baz-value");
MutableDocument transformedDoc = doc("collection/key", 1, data);
Mutation transform = patchMutation("collection/key", map("foo.bar", FieldValue.serverTimestamp()));
Timestamp serverTimestamp = new Timestamp(2, 0);
MutationResult mutationResult = new MutationResult(version(1), Collections.singletonList(wrap(serverTimestamp)));
transform.applyToRemoteDocument(transformedDoc, mutationResult);
Map<String, Object> expectedData = map("foo", map("bar", serverTimestamp.toDate()), "baz", "baz-value");
assertEquals(doc("collection/key", 1, expectedData).setHasCommittedMutations(), transformedDoc);
}
Aggregations