|
8 | 8 | import junit.framework.Test; |
9 | 9 | import junit.framework.TestCase; |
10 | 10 | import junit.framework.TestSuite; |
| 11 | +import org.jetbrains.annotations.NotNull; |
11 | 12 |
|
12 | 13 | import java.util.*; |
13 | 14 | import java.util.concurrent.CountDownLatch; |
@@ -460,6 +461,176 @@ public void onComplete() { |
460 | 461 | assertTrue(testSucceed); |
461 | 462 | } |
462 | 463 |
|
| 464 | + public void testQueryAllAfterClearCache() throws Exception { |
| 465 | + final AVQuery query = new AVQuery("Student"); |
| 466 | + query.orderByDescending(AVObject.KEY_CREATED_AT); |
| 467 | + query.limit(5); |
| 468 | + query.skip(1); |
| 469 | + query.findInBackground().subscribe(new Observer<List<AVObject>>() { |
| 470 | + public void onSubscribe(Disposable disposable) { |
| 471 | + |
| 472 | + } |
| 473 | + |
| 474 | + public void onNext(List<AVObject> o) { |
| 475 | + System.out.println("succeed to query at first time, result size: " + o.size()); |
| 476 | + query.clearCachedResult(); |
| 477 | + query.findInBackground().subscribe(new Observer<List<AVObject>>() { |
| 478 | + @Override |
| 479 | + public void onSubscribe(@NotNull Disposable disposable) { |
| 480 | + |
| 481 | + } |
| 482 | + |
| 483 | + @Override |
| 484 | + public void onNext(@NotNull List<AVObject> o) { |
| 485 | + System.out.println("succeed to query at second time, result size: " + o.size()); |
| 486 | + testSucceed = true; |
| 487 | + latch.countDown(); |
| 488 | + } |
| 489 | + |
| 490 | + @Override |
| 491 | + public void onError(@NotNull Throwable throwable) { |
| 492 | + System.out.println("failed to query at second time"); |
| 493 | + throwable.printStackTrace(); |
| 494 | + latch.countDown(); |
| 495 | + } |
| 496 | + |
| 497 | + @Override |
| 498 | + public void onComplete() { |
| 499 | + |
| 500 | + } |
| 501 | + }); |
| 502 | + |
| 503 | + } |
| 504 | + |
| 505 | + public void onError(Throwable throwable) { |
| 506 | + System.out.println("failed to query at first time"); |
| 507 | + throwable.printStackTrace(); |
| 508 | + latch.countDown(); |
| 509 | + } |
| 510 | + |
| 511 | + public void onComplete() { |
| 512 | + |
| 513 | + } |
| 514 | + }); |
| 515 | + latch.await(); |
| 516 | + assertTrue(testSucceed); |
| 517 | + |
| 518 | + } |
| 519 | + |
| 520 | + public void testQueryFirstAfterClearCache() throws Exception { |
| 521 | + final AVQuery query = new AVQuery("Student"); |
| 522 | + query.orderByDescending(AVObject.KEY_CREATED_AT); |
| 523 | + query.limit(5); |
| 524 | + query.skip(1); |
| 525 | + query.getFirstInBackground().subscribe(new Observer<AVObject>() { |
| 526 | + public void onSubscribe(Disposable disposable) { |
| 527 | + |
| 528 | + } |
| 529 | + |
| 530 | + public void onNext(AVObject o) { |
| 531 | + System.out.println("succeed to query at first time, result objectId: " + o.getObjectId()); |
| 532 | + query.clearCachedResult(); |
| 533 | + query.setCachePolicy(AVQuery.CachePolicy.CACHE_ELSE_NETWORK); |
| 534 | + query.getFirstInBackground().subscribe(new Observer<AVObject>() { |
| 535 | + @Override |
| 536 | + public void onSubscribe(@NotNull Disposable disposable) { |
| 537 | + |
| 538 | + } |
| 539 | + |
| 540 | + @Override |
| 541 | + public void onNext(@NotNull AVObject o) { |
| 542 | + System.out.println("succeed to query at second time, result objectId: " + o.getObjectId()); |
| 543 | + testSucceed = true; |
| 544 | + latch.countDown(); |
| 545 | + } |
| 546 | + |
| 547 | + @Override |
| 548 | + public void onError(@NotNull Throwable throwable) { |
| 549 | + System.out.println("failed to query at second time"); |
| 550 | + throwable.printStackTrace(); |
| 551 | + latch.countDown(); |
| 552 | + } |
| 553 | + |
| 554 | + @Override |
| 555 | + public void onComplete() { |
| 556 | + |
| 557 | + } |
| 558 | + }); |
| 559 | + |
| 560 | + } |
| 561 | + |
| 562 | + public void onError(Throwable throwable) { |
| 563 | + System.out.println("failed to query at first time"); |
| 564 | + throwable.printStackTrace(); |
| 565 | + latch.countDown(); |
| 566 | + } |
| 567 | + |
| 568 | + public void onComplete() { |
| 569 | + |
| 570 | + } |
| 571 | + }); |
| 572 | + latch.await(); |
| 573 | + assertTrue(testSucceed); |
| 574 | + |
| 575 | + } |
| 576 | + |
| 577 | + public void testQueryCountAfterClearCache() throws Exception { |
| 578 | + final AVQuery query = new AVQuery("Student"); |
| 579 | + query.orderByDescending(AVObject.KEY_CREATED_AT); |
| 580 | + query.limit(5); |
| 581 | + query.skip(1); |
| 582 | + query.countInBackground().subscribe(new Observer<Integer>() { |
| 583 | + public void onSubscribe(Disposable disposable) { |
| 584 | + |
| 585 | + } |
| 586 | + |
| 587 | + public void onNext(Integer o) { |
| 588 | + System.out.println("succeed to query at first time, count: " + o); |
| 589 | + query.clearCachedResult(); |
| 590 | + query.setCachePolicy(AVQuery.CachePolicy.CACHE_ELSE_NETWORK); |
| 591 | + query.countInBackground().subscribe(new Observer<Integer>() { |
| 592 | + @Override |
| 593 | + public void onSubscribe(@NotNull Disposable disposable) { |
| 594 | + |
| 595 | + } |
| 596 | + |
| 597 | + @Override |
| 598 | + public void onNext(@NotNull Integer o) { |
| 599 | + System.out.println("succeed to query at second time, count: " + o); |
| 600 | + testSucceed = true; |
| 601 | + latch.countDown(); |
| 602 | + } |
| 603 | + |
| 604 | + @Override |
| 605 | + public void onError(@NotNull Throwable throwable) { |
| 606 | + System.out.println("failed to query at second time"); |
| 607 | + throwable.printStackTrace(); |
| 608 | + latch.countDown(); |
| 609 | + } |
| 610 | + |
| 611 | + @Override |
| 612 | + public void onComplete() { |
| 613 | + |
| 614 | + } |
| 615 | + }); |
| 616 | + |
| 617 | + } |
| 618 | + |
| 619 | + public void onError(Throwable throwable) { |
| 620 | + System.out.println("failed to query at first time"); |
| 621 | + throwable.printStackTrace(); |
| 622 | + latch.countDown(); |
| 623 | + } |
| 624 | + |
| 625 | + public void onComplete() { |
| 626 | + |
| 627 | + } |
| 628 | + }); |
| 629 | + latch.await(); |
| 630 | + assertTrue(testSucceed); |
| 631 | + |
| 632 | + } |
| 633 | + |
463 | 634 | public void testDeepIncludeQuery() throws Exception { |
464 | 635 | AVQuery<AVObject> queryLikeRed = new AVQuery<>("FileUnitTest"); |
465 | 636 | queryLikeRed.include("taskId"); |
|
0 commit comments