use of com.google.firebase.firestore.proto.Target in project firebase-android-sdk by firebase.
the class SQLiteSchemaTest method dropsLastLimboFreeSnapshotIfValuesCannotBeReliedUpon.
@Test
public void dropsLastLimboFreeSnapshotIfValuesCannotBeReliedUpon() {
schema.runSchemaUpgrades(0, 9);
db.execSQL("INSERT INTO targets (target_id, canonical_id, target_proto) VALUES (?,?, ?)", new Object[] { 1, "foo", createDummyQueryTargetWithLimboFreeVersion(1).toByteArray() });
schema.runSchemaUpgrades(9, 10);
new SQLitePersistence.Query(db, "SELECT target_proto FROM targets WHERE target_id = 1").first(cursor -> {
byte[] targetProtoBytes = cursor.getBlob(0);
try {
Target targetProto = Target.parseFrom(targetProtoBytes);
assertFalse(targetProto.hasLastLimboFreeSnapshotVersion());
} catch (InvalidProtocolBufferException e) {
fail("Failed to decode Query data");
}
});
}
use of com.google.firebase.firestore.proto.Target in project firebase-android-sdk by firebase.
the class SQLiteSchemaTest method rewritesCanonicalIds.
@Test
public void rewritesCanonicalIds() {
schema.runSchemaUpgrades(0, 10);
Query filteredQuery = query("colletion").filter(filter("foo", "==", "bar"));
TargetData initialTargetData = new TargetData(filteredQuery.toTarget(), /* targetId= */
2, /* sequenceNumber= */
1, QueryPurpose.LISTEN);
db.execSQL("INSERT INTO targets (target_id, canonical_id, target_proto) VALUES (? ,?, ?)", new Object[] { 2, "invalid_canonical_id", serializer.encodeTargetData(initialTargetData).toByteArray() });
schema.runSchemaUpgrades(10, 11);
new SQLitePersistence.Query(db, "SELECT canonical_id, target_proto, canonical_id FROM targets").forEach(cursor -> {
String actualCanonicalId = cursor.getString(0);
byte[] targetProtoBytes = cursor.getBlob(1);
try {
Target targetProto = Target.parseFrom(targetProtoBytes);
TargetData targetData = serializer.decodeTargetData(targetProto);
String expectedCanonicalId = targetData.getTarget().getCanonicalId();
assertEquals(expectedCanonicalId, actualCanonicalId);
} catch (InvalidProtocolBufferException e) {
fail("Failed to decode Target data");
}
});
}
use of com.google.firebase.firestore.proto.Target in project firebase-android-sdk by firebase.
the class SQLiteSchemaTest method dropsLastLimboFreeSnapshotIfPreviouslyDowngraded.
@Test
public void dropsLastLimboFreeSnapshotIfPreviouslyDowngraded() {
schema.runSchemaUpgrades(0, 9);
db.execSQL("INSERT INTO targets (target_id, canonical_id, target_proto) VALUES (?,?, ?)", new Object[] { 1, "foo", createDummyQueryTargetWithLimboFreeVersion(1).toByteArray() });
db.execSQL("INSERT INTO targets (target_id, canonical_id, target_proto) VALUES (?, ?, ?)", new Object[] { 2, "bar", createDummyQueryTargetWithLimboFreeVersion(2).toByteArray() });
db.execSQL("INSERT INTO targets (target_id, canonical_id, target_proto) VALUES (?,?, ?)", new Object[] { 3, "baz", createDummyQueryTargetWithLimboFreeVersion(3).toByteArray() });
schema.runSchemaUpgrades(0, 8);
schema.runSchemaUpgrades(8, 10);
int rowCount = new SQLitePersistence.Query(db, "SELECT target_id, target_proto FROM targets").forEach(cursor -> {
int targetId = cursor.getInt(0);
byte[] targetProtoBytes = cursor.getBlob(1);
try {
Target targetProto = Target.parseFrom(targetProtoBytes);
assertEquals(targetId, targetProto.getTargetId());
assertFalse(targetProto.hasLastLimboFreeSnapshotVersion());
} catch (InvalidProtocolBufferException e) {
fail("Failed to decode Query data");
}
});
assertEquals(3, rowCount);
}
use of com.google.firebase.firestore.proto.Target in project firebase-android-sdk by firebase.
the class SQLiteSchema method dropLastLimboFreeSnapshotVersion.
private void dropLastLimboFreeSnapshotVersion() {
new SQLitePersistence.Query(db, "SELECT target_id, target_proto FROM targets").forEach(cursor -> {
int targetId = cursor.getInt(0);
byte[] targetProtoBytes = cursor.getBlob(1);
try {
Target targetProto = Target.parseFrom(targetProtoBytes);
targetProto = targetProto.toBuilder().clearLastLimboFreeSnapshotVersion().build();
db.execSQL("UPDATE targets SET target_proto = ? WHERE target_id = ?", new Object[] { targetProto.toByteArray(), targetId });
} catch (InvalidProtocolBufferException e) {
throw fail("Failed to decode Query data for target %s", targetId);
}
});
}
use of com.google.firebase.firestore.proto.Target in project firebase-android-sdk by firebase.
the class SQLiteSchema method rewriteCanonicalIds.
private void rewriteCanonicalIds() {
new SQLitePersistence.Query(db, "SELECT target_id, target_proto FROM targets").forEach(cursor -> {
int targetId = cursor.getInt(0);
byte[] targetProtoBytes = cursor.getBlob(1);
try {
Target targetProto = Target.parseFrom(targetProtoBytes);
TargetData targetData = serializer.decodeTargetData(targetProto);
String updatedCanonicalId = targetData.getTarget().getCanonicalId();
db.execSQL("UPDATE targets SET canonical_id = ? WHERE target_id = ?", new Object[] { updatedCanonicalId, targetId });
} catch (InvalidProtocolBufferException e) {
throw fail("Failed to decode Query data for target %s", targetId);
}
});
}
Aggregations