Skip to content

Commit 7e79572

Browse files
committed
more get tests
1 parent 0d52495 commit 7e79572

File tree

1 file changed

+71
-1
lines changed
  • firebase-database/src/androidTest/java/com/google/firebase/database

1 file changed

+71
-1
lines changed

firebase-database/src/androidTest/java/com/google/firebase/database/QueryTest.java

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import androidx.annotation.NonNull;
2525
import androidx.test.ext.junit.runners.AndroidJUnit4;
26+
27+
import com.google.android.gms.tasks.Continuation;
2628
import com.google.android.gms.tasks.OnCompleteListener;
2729
import com.google.android.gms.tasks.Task;
2830
import com.google.firebase.database.core.DatabaseConfig;
@@ -3406,7 +3408,6 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
34063408

34073409
@Test
34083410
public void emptyQueryGet() throws DatabaseException, InterruptedException {
3409-
assertTrue(false);
34103411
DatabaseReference node = IntegrationTestHelpers.getRandomNode();
34113412
final Semaphore semaphore = new Semaphore(0);
34123413
node.get()
@@ -3423,6 +3424,75 @@ public void onComplete(@NonNull Task<DataSnapshot> task) {
34233424
IntegrationTestHelpers.waitFor(semaphore);
34243425
}
34253426

3427+
@Test
3428+
public void offlineQueryGet() throws DatabaseException {
3429+
DatabaseConfig cfg = IntegrationTestHelpers.newTestConfig();
3430+
IntegrationTestHelpers.goOffline(cfg);
3431+
DatabaseReference node = IntegrationTestHelpers.getRandomNode();
3432+
node.get()
3433+
.addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
3434+
@Override
3435+
public void onComplete(@NonNull Task<DataSnapshot> task) {
3436+
assertFalse(task.isSuccessful());
3437+
assertTrue(task.isCanceled());
3438+
assertNotNull(task.getException());
3439+
assertEquals(task.getException().getMessage(), "Client offline with empty cache!");
3440+
}
3441+
});
3442+
}
3443+
3444+
@Test
3445+
public void getQueryBasic() throws DatabaseException, InterruptedException {
3446+
DatabaseReference ref = IntegrationTestHelpers.getRandomNode();
3447+
final Semaphore semaphore = new Semaphore(0);
3448+
ref.setValue(42).continueWithTask(new Continuation<Void, Task<DataSnapshot>>() {
3449+
@Override
3450+
public Task<DataSnapshot> then(@NonNull Task<Void> task) throws Exception {
3451+
assertTrue(task.isSuccessful());
3452+
return ref.get()
3453+
.addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
3454+
@Override
3455+
public void onComplete(@NonNull Task<DataSnapshot> task) {
3456+
assertTrue(task.isSuccessful());
3457+
DataSnapshot snap = task.getResult();
3458+
assertNotNull(snap);
3459+
assertEquals(42, snap.getValue());
3460+
semaphore.release();
3461+
}
3462+
});
3463+
}
3464+
});
3465+
IntegrationTestHelpers.waitFor(semaphore);
3466+
}
3467+
3468+
@Test
3469+
public void getQueryCached() throws DatabaseException, InterruptedException, TimeoutException, TestFailure {
3470+
DatabaseReference ref = IntegrationTestHelpers.getRandomNode();
3471+
DatabaseConfig cfg = IntegrationTestHelpers.newTestConfig();
3472+
ReadFuture future = ReadFuture.untilNonNull(ref);
3473+
ref.setValue(42);
3474+
assertEquals(42, future.waitForLastValue());
3475+
IntegrationTestHelpers.goOffline(cfg);
3476+
final Semaphore semaphore = new Semaphore(0);
3477+
ref.get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
3478+
@Override
3479+
public void onComplete(@NonNull Task<DataSnapshot> task) {
3480+
assertTrue(task.isSuccessful());
3481+
DataSnapshot snapshot = task.getResult();
3482+
assertNotNull(snapshot);
3483+
assertEquals(42, snapshot.getValue());
3484+
semaphore.release();
3485+
}
3486+
});
3487+
IntegrationTestHelpers.waitFor(semaphore);
3488+
}
3489+
3490+
@Test
3491+
public void getQuerySkipsCache() throws DatabaseException {
3492+
DatabaseReference ref = IntegrationTestHelpers.getRandomNode();
3493+
DatabaseConfig cfg = IntegrationTestHelpers.newTestConfig();
3494+
}
3495+
34263496
@Test
34273497
public void querySnapshotChildrenRespectDefaultOrdering()
34283498
throws DatabaseException, ExecutionException, TimeoutException, TestFailure,

0 commit comments

Comments
 (0)