23
23
24
24
import androidx .annotation .NonNull ;
25
25
import androidx .test .ext .junit .runners .AndroidJUnit4 ;
26
+
27
+ import com .google .android .gms .tasks .Continuation ;
26
28
import com .google .android .gms .tasks .OnCompleteListener ;
27
29
import com .google .android .gms .tasks .Task ;
28
30
import com .google .firebase .database .core .DatabaseConfig ;
@@ -3406,7 +3408,6 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
3406
3408
3407
3409
@ Test
3408
3410
public void emptyQueryGet () throws DatabaseException , InterruptedException {
3409
- assertTrue (false );
3410
3411
DatabaseReference node = IntegrationTestHelpers .getRandomNode ();
3411
3412
final Semaphore semaphore = new Semaphore (0 );
3412
3413
node .get ()
@@ -3423,6 +3424,75 @@ public void onComplete(@NonNull Task<DataSnapshot> task) {
3423
3424
IntegrationTestHelpers .waitFor (semaphore );
3424
3425
}
3425
3426
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
+
3426
3496
@ Test
3427
3497
public void querySnapshotChildrenRespectDefaultOrdering ()
3428
3498
throws DatabaseException , ExecutionException , TimeoutException , TestFailure ,
0 commit comments