Java 类io.reactivex.CompletableObserver 实例源码

项目:GitHub    文件:CompletableObserverExampleActivity.java   
private CompletableObserver getCompletableObserver() {
    return new CompletableObserver() {
        @Override
        public void onSubscribe(Disposable d) {
            Log.d(TAG, " onSubscribe : " + d.isDisposed());
        }

        @Override
        public void onComplete() {
            textView.append(" onComplete");
            textView.append(AppConstant.LINE_SEPARATOR);
            Log.d(TAG, " onComplete");
        }

        @Override
        public void onError(Throwable e) {
            textView.append(" onError : " + e.getMessage());
            textView.append(AppConstant.LINE_SEPARATOR);
            Log.d(TAG, " onError : " + e.getMessage());
        }
    };
}
项目:Rx2Animations    文件:AnimateCompletable.java   
@Override
protected void subscribeActual(final CompletableObserver completableObserver) {
    verifyMainThread();
    final View view = viewWeakRef.get();
    if (view == null) {
        completableObserver.onComplete();
        return;
    }

    final ViewPropertyAnimatorCompat animator = ViewCompat.animate(view);

    completableObserver.onSubscribe(createAnimationDisposable(animator, onAnimationCancelAction));

    if (preTransformActions != null) {
        applyActions(preTransformActions, animator);
        animator.setDuration(NONE).setStartDelay(NONE)
                .withEndAction(() -> runAnimation(completableObserver, animator))
                .start();
    } else {
        runAnimation(completableObserver, animator);
    }
}
项目:LocationAware    文件:LocationAlarmPresenter.java   
@Override public void onDeleteCheckPoint(int adapterPosition) {
  getCheckPointDataSource().deleteCheckPoint(allCheckPoints.get(adapterPosition))
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribeWith(new CompletableObserver() {
        @Override public void onSubscribe(Disposable d) {

        }

        @Override public void onComplete() {
          allCheckPoints.remove(adapterPosition);
          getView().removeMarker(adapterPosition);
          getView().notifyListAdapter();
        }

        @Override public void onError(Throwable e) {
          getView().showError("Delete Failed");
        }
      });
}
项目:DisposableAttach    文件:AttachDisposableCompletable.java   
@Override
protected void subscribeActual(CompletableObserver s) {
    CompletableObserver observer;
    try {
        observer = ObjectHelper.requireNonNull(s, "Null Observer");
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        // can't call onError because no way to know if a Disposable has been set or not
        // can't call onSubscribe because the call might have set a Disposable already
        RxJavaPlugins.onError(e);

        NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
        npe.initCause(e);
        throw npe;
    }

    source.subscribe(new AttachCompletableObserver(observer, this.compositeDisposable));
}
项目:RxConditions    文件:CompletableIfThen.java   
@Override
protected void subscribeActual(CompletableObserver observer) {
    boolean b;

    try {
        b = condition.getAsBoolean();
    } catch (Throwable ex) {
        EmptyDisposable.error(ex, observer);
        return;
    }

    if (b) {
        then.subscribe(observer);
    } else {
        orElse.subscribe(observer);
    }
}
项目:RxJava2-Android-Sample    文件:CompletableObserverExampleActivity.java   
private CompletableObserver getCompletableObserver() {
    return new CompletableObserver() {
        @Override
        public void onSubscribe(Disposable d) {
            Log.d(TAG, " onSubscribe : " + d.isDisposed());
        }

        @Override
        public void onComplete() {
            textView.append(" onComplete");
            textView.append(AppConstant.LINE_SEPARATOR);
            Log.d(TAG, " onComplete");
        }

        @Override
        public void onError(Throwable e) {
            textView.append(" onError : " + e.getMessage());
            textView.append(AppConstant.LINE_SEPARATOR);
            Log.d(TAG, " onError : " + e.getMessage());
        }
    };
}
项目:RxJava2-Android-Sample    文件:IgnoreElementsExampleActivity.java   
private CompletableObserver getObserver() {
    return new CompletableObserver() {

        @Override
        public void onSubscribe(Disposable d) {
            Log.d(TAG, " onSubscribe : " + d.isDisposed());
        }

        @Override
        public void onError(Throwable e) {
            textView.append(" onError : " + e.getMessage());
            textView.append(AppConstant.LINE_SEPARATOR);
            Log.d(TAG, " onError : " + e.getMessage());
        }

        @Override
        public void onComplete() {
            textView.append(" onComplete");
            textView.append(AppConstant.LINE_SEPARATOR);
            Log.d(TAG, " onComplete");
        }
    };
}
项目:trust-wallet-android    文件:CompletableErrorProxyOperator.java   
@Override
public CompletableObserver apply(CompletableObserver observer) throws Exception {
    return new DisposableCompletableObserver() {
        @Override
        public void onComplete() {
            if (!isDisposed()) {
                observer.onError(throwable);
            }
        }

        @Override
        public void onError(Throwable ex) {
            if (!isDisposed()) {
                observer.onError(ex);
            }
        }
    };
}
项目:vertx-jooq-async    文件:RXVertxDaoTestBase.java   
protected CompletableObserver failOrCountDownCompletableObserver(CountDownLatch latch) {
    return new CompletableObserver() {

        @Override
        public void onSubscribe(Disposable d) {

        }

        @Override
        public void onComplete() {
            latch.countDown();
        }

        @Override
        public void onError(Throwable e) {
            fail(e);
        }

    };
}
项目:science-journal    文件:MaybeConsumers.java   
/**
 * Performs the opposite translation from
 * {@link MaybeConsumers#fromCompletableObserver(CompletableObserver)}
 */
public static CompletableObserver toCompletableObserver(final MaybeConsumer<Success> c) {
    return new CompletableObserver() {
        @Override
        public void onSubscribe(@NonNull Disposable d) {
            // do nothing
        }

        @Override
        public void onComplete() {
            c.success(Success.SUCCESS);
        }

        @Override
        public void onError(@NonNull Throwable e) {
            c.fail(throwableToException(e));
        }
    };
}
项目:science-journal    文件:LoggingConsumer.java   
public static CompletableObserver observe(String tag, String operation) {
    return new CompletableObserver() {
        @Override
        public void onSubscribe(Disposable d) {

        }

        @Override
        public void onComplete() {

        }

        @Override
        public void onError(Throwable e) {
            complain(e, tag, operation);
        }
    };
}
项目:delern    文件:DeckTest.java   
@Test
public void decks_renamed() {
    List<Deck> renamedData = mUser.save().andThen((final CompletableObserver cs) -> {
        Deck deck = new Deck(mUser);
        deck.setName("ToRename");
        deck.setAccepted(true);
        deck.create().subscribe(cs);
    }).andThen((ObservableSource<List<Deck>>) observer ->
            mUser.fetchChildren(mUser.getChildReference(Deck.class), Deck.class)
                    .subscribe(observer)
    ).firstOrError().flatMapCompletable(data -> {
        assertTrue(data.size() == 1 && data.get(0).getName().equals("ToRename"));
        Deck fetchedDeck = data.get(0);
        fetchedDeck.setName("Renamed");
        return fetchedDeck.save();
    }).andThen((ObservableSource<List<Deck>>) observer ->
            mUser.fetchChildren(mUser.getChildReference(Deck.class), Deck.class)
                    .subscribe(observer)
    ).firstOrError().blockingGet();
    assertTrue(renamedData.size() == 1 && renamedData.get(0).getName()
            .equals("Renamed"));
}
项目:delern    文件:DeckTest.java   
@Test
public void decks_changedDeckType() {
    List<Deck> deckTypeData = mUser.save().andThen((final CompletableObserver cs) -> {
        Deck deck = new Deck(mUser);
        deck.setName("DeckType");
        deck.setAccepted(true);
        deck.create().subscribe(cs);
    }).andThen((ObservableSource<List<Deck>>) observer ->
            mUser.fetchChildren(mUser.getChildReference(Deck.class), Deck.class)
                    .subscribe(observer)
    ).firstOrError().flatMapCompletable(data -> {
        assertTrue(data.size() == 1 && data.get(0).getName().equals("DeckType"));
        Deck fetchedDeck = data.get(0);
        fetchedDeck.setDeckType(DeckType.SWISS.name());
        return fetchedDeck.save();
    }).andThen((ObservableSource<List<Deck>>) observer ->
            mUser.fetchChildren(mUser.getChildReference(Deck.class), Deck.class)
                    .subscribe(observer)
    ).firstOrError().blockingGet();
    assertTrue(deckTypeData.size() == 1 && deckTypeData.get(0).getDeckType()
            .equals(DeckType.SWISS.name()));
}
项目:delern    文件:DeckTest.java   
@Test
public void decks_createdAndDeleted() throws Exception {
    List<Deck> deletedDeck = mUser.save().andThen((final CompletableObserver cs) -> {
        Deck deck = new Deck(mUser);
        deck.setName("Created");
        deck.setAccepted(true);
        deck.create().subscribe(cs);
    }).andThen((ObservableSource<List<Deck>>) observer ->
            mUser.fetchChildren(mUser.getChildReference(Deck.class), Deck.class)
                    .subscribe(observer)
    ).firstOrError().flatMapCompletable(data -> {
        assertTrue(data.size() == 1 && data.get(0).getName().equals("Created"));
        return data.get(0).delete();
    }).andThen((ObservableSource<List<Deck>>) observer ->
            mUser.fetchChildren(mUser.getChildReference(Deck.class), Deck.class)
                    .subscribe(observer)
    ).firstOrError().blockingGet();
    assertTrue(deletedDeck.size() == 0);
}
项目:delern    文件:CardTest.java   
@Test
public void cards_createdAndFetched() throws Exception {
    final Deck deck = new Deck(mUser);
    List<Card> cards = mUser.save().andThen((final CompletableObserver cs) -> {
        deck.setName("CreateCards");
        deck.setAccepted(true);
        deck.create().subscribe(cs);
    }).andThen((ObservableSource<List<Deck>>) observer ->
            mUser.fetchChildren(mUser.getChildReference(Deck.class), Deck.class)
                    .subscribe(observer)
    ).firstOrError().flatMapCompletable(data -> {
        assertTrue(data.size() == 1 && data.get(0).getName().equals("CreateCards"));
        Card newCard = new Card(data.get(0));
        newCard.setFront("frontSide");
        newCard.setBack("backSide");
        return newCard.create();
    }).andThen((ObservableSource<List<Card>>) observer ->
            deck.fetchChildren(deck.getChildReference(Card.class), Card.class)
                    .subscribe(observer)
    ).firstOrError().blockingGet();
    assertTrue(cards.size() == 1 && cards.get(0).getFront().equals("frontSide") &&
            cards.get(0).getBack().equals("backSide"));
}
项目:RxJava2-Android-Samples    文件:CompletableObserverExampleActivity.java   
private CompletableObserver getCompletableObserver() {
    return new CompletableObserver() {
        @Override
        public void onSubscribe(Disposable d) {
            Log.d(TAG, " onSubscribe : " + d.isDisposed());
        }

        @Override
        public void onComplete() {
            textView.append(" onComplete");
            textView.append(AppConstant.LINE_SEPARATOR);
            Log.d(TAG, " onComplete");
        }

        @Override
        public void onError(Throwable e) {
            textView.append(" onError : " + e.getMessage());
            textView.append(AppConstant.LINE_SEPARATOR);
            Log.d(TAG, " onError : " + e.getMessage());
        }
    };
}
项目:vertx-jooq    文件:RXVertxDaoTestBase.java   
protected  CompletableObserver failOrCountDownCompletableObserver(CountDownLatch latch) {
    return new CompletableObserver() {

        @Override
        public void onSubscribe(Disposable d) {

        }

        @Override
        public void onComplete() {
            latch.countDown();
        }

        @Override
        public void onError(Throwable e) {
            fail(e);
        }

    };
}
项目:resilience4j    文件:CircuitBreakerCompletableObserverTest.java   
@Test
public void shouldHonorDisposedWhenCallingOnComplete() throws Exception {
    // Given
    Disposable disposable = mock(Disposable.class);
    CompletableObserver childObserver = mock(CompletableObserver.class);
    CompletableObserver decoratedObserver = CircuitBreakerOperator.of(circuitBreaker).apply(childObserver);
    decoratedObserver.onSubscribe(disposable);

    // When
    ((Disposable) decoratedObserver).dispose();
    decoratedObserver.onComplete();

    // Then
    verify(childObserver, never()).onComplete();
    assertSingleSuccessfulCall();
}
项目:resilience4j    文件:CircuitBreakerCompletableObserverTest.java   
@Test
public void shouldHonorDisposedWhenCallingOnError() throws Exception {
    // Given
    Disposable disposable = mock(Disposable.class);
    CompletableObserver childObserver = mock(CompletableObserver.class);
    CompletableObserver decoratedObserver = CircuitBreakerOperator.of(circuitBreaker).apply(childObserver);
    decoratedObserver.onSubscribe(disposable);

    // When
    ((Disposable) decoratedObserver).dispose();
    decoratedObserver.onError(new IllegalStateException());

    // Then
    verify(childObserver, never()).onError(any());
    assertSingleFailedCall();
}
项目:resilience4j    文件:BulkheadCompletableObserverTest.java   
@Test
public void shouldHonorDisposedWhenCallingOnComplete() throws Exception {
    // Given
    Disposable disposable = mock(Disposable.class);
    CompletableObserver childObserver = mock(CompletableObserver.class);
    CompletableObserver decoratedObserver = BulkheadOperator.of(bulkhead).apply(childObserver);
    decoratedObserver.onSubscribe(disposable);

    // When
    ((Disposable) decoratedObserver).dispose();
    decoratedObserver.onComplete();

    // Then
    verify(childObserver, never()).onComplete();
    assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}
项目:resilience4j    文件:BulkheadCompletableObserverTest.java   
@Test
public void shouldHonorDisposedWhenCallingOnError() throws Exception {
    // Given
    Disposable disposable = mock(Disposable.class);
    CompletableObserver childObserver = mock(CompletableObserver.class);
    CompletableObserver decoratedObserver = BulkheadOperator.of(bulkhead).apply(childObserver);
    decoratedObserver.onSubscribe(disposable);

    // When
    ((Disposable) decoratedObserver).dispose();
    decoratedObserver.onError(new IllegalStateException());

    // Then
    verify(childObserver, never()).onError(any());
    assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}
项目:resilience4j    文件:BulkheadCompletableObserverTest.java   
@Test
public void shouldNotReleaseBulkheadWhenWasDisposedAfterNotPermittedSubscribe() throws Exception {
    // Given
    Disposable disposable = mock(Disposable.class);
    CompletableObserver childObserver = mock(CompletableObserver.class);
    CompletableObserver decoratedObserver = BulkheadOperator.of(bulkhead).apply(childObserver);
    bulkhead.isCallPermitted();
    assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0);
    decoratedObserver.onSubscribe(disposable);

    // When
    ((Disposable) decoratedObserver).dispose();

    // Then
    assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0);
}
项目:vertx-rx    文件:CompletableHelper.java   
/**
 * Adapts an Vert.x {@code Handler<AsyncResult<T>>} to an RxJava2 {@link SingleObserver}.
 * <p>
 * The returned observer can be subscribed to an {@link Single#subscribe(SingleObserver)}.
 *
 * @param handler the handler to adapt
 * @return the observer
 */
public static <T> CompletableObserver toObserver(Handler<AsyncResult<T>> handler) {
  AtomicBoolean completed = new AtomicBoolean();
  return new CompletableObserver() {
    @Override
    public void onSubscribe(@NonNull Disposable d) {
    }
    @Override
    public void onComplete() {
      if (completed.compareAndSet(false, true)) {
        handler.handle(io.vertx.core.Future.succeededFuture());
      }
    }
    public void onSuccess() {
      if (completed.compareAndSet(false, true)) {
        handler.handle(io.vertx.core.Future.succeededFuture());
      }
    }
    @Override
    public void onError(Throwable error) {
      if (completed.compareAndSet(false, true)) {
        handler.handle(io.vertx.core.Future.failedFuture(error));
      }
    }
  };
}
项目:Rx2Animations    文件:RxValueAnimator.java   
@Override
protected void subscribeActual(final CompletableObserver completableObserver) {
    verifyMainThread();
    final UpdateListener updateListener = new UpdateListener(completableObserver, valueUpdateAction);
    final AnimationEndListener endListener = new AnimationEndListener(completableObserver, valueAnimator, animationCancelAction);
    final ValueAnimatorDisposable animatorDisposable = new ValueAnimatorDisposable(valueAnimator, updateListener, endListener);
    completableObserver.onSubscribe(animatorDisposable);

    valueAnimator.addUpdateListener(updateListener);
    valueAnimator.addListener(endListener);
    valueAnimator.start();
}
项目:Reactive-Programming-With-Java-9    文件:Demo_ignoreElements.java   
public static void main(String[] args) {
    // TODO Auto-generated method stub
    String[] fruits = { "mango", "pineapple", "apple", "mango", "papaya" };
    Observable.fromArray(fruits).ignoreElements().subscribe(
        new CompletableObserver() {
        long time=0;
        @Override
        public void onSubscribe(Disposable disposable) {
            // TODO Auto-generated method stub
            time=System.currentTimeMillis();
            System.out.println(disposable.isDisposed()+"\t"+time);


        }
        @Override
        public void onError(Throwable throwable) {
            // TODO Auto-generated method stub
            throwable.printStackTrace();
        }

        @Override
        public void onComplete() {
            // TODO Auto-generated method stub
            System.out.println("completed");
            long time_to_complete=System.currentTimeMillis()-time;
            System.out.println("process completedin: "+time_to_complete+"ms");

        }
    });



}
项目:RxTask    文件:CompletableTask.java   
@Override
protected void subscribeActual(CompletableObserver observer) {
    Task<Void> task = run();
    CompletableTaskCallback callback = new CompletableTaskCallback(task, observer);
    observer.onSubscribe(callback);
    task.addOnCompleteListener(callback);
}
项目:android-rss-feed-reader    文件:ResetPasswordPresenter.java   
@Override
public void resetPassword(String email) {
    if (!mUserInfoValidator.isEmailValid(email)) {
        getView().showEmailError(R.string.email_error);
        return;
    }

    getView().showProgress(R.string.progress_message_authenticating);
    mUserManager.resetPassword(email).subscribe(new CompletableObserver() {
        @Override
        public void onSubscribe(Disposable d) {

        }

        @Override
        public void onComplete() {
            getView().hideProgress();
            getView().navigateToMain();
        }

        @Override
        public void onError(Throwable e) {
            getView().hideProgress();
            getView().showSnackBar(e.getMessage());
        }
    });
}
项目:android-rss-feed-reader    文件:SignUpPresenter.java   
@Override
public void signUp(String email, String password) {
    if (!mValidator.isEmailValid(email)) {
        getView().showEmailError(R.string.email_error);
        return;
    }

    if (!mValidator.isPasswordValid(password)) {
        getView().showPasswordError(R.string.password_error);
        return;
    }

    getView().showProgress(R.string.progress_message_loading);
    mUserManager.createUser(email, password).subscribe(new CompletableObserver() {
        @Override
        public void onComplete() {
            getView().hideProgress();
            getView().navigateToMain();
        }

        @Override
        public void onSubscribe(Disposable d) {

        }

        @Override
        public void onError(Throwable e) {
            getView().hideProgress();
            getView().showSnackBar(e.getMessage());
        }
    });
}
项目:science-journal    文件:MaybeConsumers.java   
/**
 * MaybeConsumer<Success> is very similar to {@link CompletableObserver} in JavaRX.  Both are
 * looking for either a signal that a process has succeeded, or that it has failed with some
 * exception.  For the time period where we are still using both interfaces, we will find it
 * useful to be able to switch between them.
 *
 * @return a {@link MaybeConsumer<Success>} that pipes {@link MaybeConsumer#success(Object)}
 *         to {@link CompletableObserver#onComplete()}, and
 *         {@link MaybeConsumer#fail(Exception)} to
 *         {@link CompletableObserver#onError(Throwable)}
 */
public static MaybeConsumer<Success> fromCompletableObserver(final CompletableObserver o) {
    return new MaybeConsumer<Success>() {
        @Override
        public void success(Success value) {
            o.onComplete();
        }

        @Override
        public void fail(Exception e) {
            o.onError(e);
        }
    };
}
项目:delern    文件:DeckTest.java   
@Test
public void decks_createdAndFetched() throws Exception {
    List<Deck> data = mUser.save().andThen((final CompletableObserver cs) -> {
        Deck deck = new Deck(mUser);
        deck.setName("My Deck");
        deck.setAccepted(true);
        deck.create().subscribe(cs);
    }).andThen((ObservableSource<List<Deck>>) observer ->
            mUser.fetchChildren(mUser.getChildReference(Deck.class), Deck.class)
                    .subscribe(observer)
    ).firstOrError().blockingGet();
    assertTrue(data.size() == 1 && data.get(0).getName().equals("My Deck"));
}
项目:delern    文件:DeckTest.java   
@Test
public void decks_checkedUserDeck() {
    List<Deck> userDeck = mUser.save().andThen((final CompletableObserver cs) -> {
        Deck deck = new Deck(mUser);
        deck.setName("UsersDeck");
        deck.setAccepted(true);
        deck.create().subscribe(cs);
    }).andThen((ObservableSource<List<Deck>>) observer ->
            mUser.fetchChildren(mUser.getChildReference(Deck.class), Deck.class)
                    .subscribe(observer)
    ).firstOrError().blockingGet();
    assertTrue(userDeck.size() == 1 && userDeck.get(0).getName().equals("UsersDeck") &&
            mUser.equals(userDeck.get(0).getUser()));
}
项目:delern    文件:CardTest.java   
@Test
public void cards_createdAndDeleted() {
    final Deck deck = new Deck(mUser);
    List<Card> cards = mUser.save().andThen((final CompletableObserver cs) -> {
        deck.setName("TestDelete");
        deck.setAccepted(true);
        deck.create().subscribe(cs);
    }).andThen((ObservableSource<List<Deck>>) observer ->
            mUser.fetchChildren(mUser.getChildReference(Deck.class), Deck.class)
                    .subscribe(observer)
    ).firstOrError().flatMapCompletable(data -> {
        assertTrue(data.size() == 1 && data.get(0).getName().equals("TestDelete"));
        Card newCard = new Card(data.get(0));
        newCard.setFront("frontSide");
        newCard.setBack("backSide");
        return newCard.create();
    }).andThen((ObservableSource<List<Card>>) observer ->
            deck.fetchChildren(deck.getChildReference(Card.class), Card.class)
                    .subscribe(observer)
    ).firstOrError().flatMapCompletable(data -> {
        assertTrue(data.size() == 1 && data.get(0).getFront().equals("frontSide") &&
                data.get(0).getBack().equals("backSide"));
        return data.get(0).delete();
    }).andThen((ObservableSource<List<Card>>) observer ->
            deck.fetchChildren(deck.getChildReference(Card.class), Card.class)
                    .subscribe(observer)
    ).firstOrError().blockingGet();
    assertTrue(cards.size() == 0);
}
项目:delern    文件:CardTest.java   
@Test
public void cards_createdAndEdited() {
    final Deck deck = new Deck(mUser);
    List<Card> cards = mUser.save().andThen((final CompletableObserver cs) -> {
        deck.setName("TestRename");
        deck.setAccepted(true);
        deck.create().subscribe(cs);
    }).andThen((ObservableSource<List<Deck>>) observer ->
            mUser.fetchChildren(mUser.getChildReference(Deck.class), Deck.class)
                    .subscribe(observer)
    ).firstOrError().flatMapCompletable(data -> {
        assertTrue(data.size() == 1 && data.get(0).getName().equals("TestRename"));
        Card newCard = new Card(data.get(0));
        newCard.setFront("frontSide");
        newCard.setBack("backSide");
        return newCard.create();
    }).andThen((ObservableSource<List<Card>>) observer ->
            deck.fetchChildren(deck.getChildReference(Card.class), Card.class)
                    .subscribe(observer)
    ).firstOrError().flatMapCompletable(data -> {
        assertTrue((data.size() == 1 && data.get(0).getFront().equals("frontSide") &&
                data.get(0).getBack().equals("backSide")));
        data.get(0).setFront("frontSide2");
        data.get(0).setBack("backSide2");
        return data.get(0).save();
    }).andThen((ObservableSource<List<Card>>) observer ->
            deck.fetchChildren(deck.getChildReference(Card.class), Card.class)
                    .subscribe(observer)
    ).firstOrError().blockingGet();
    assertTrue(cards.size() == 1 && cards.get(0).getFront().equals("frontSide2") &&
            cards.get(0).getBack().equals("backSide2"));
}
项目:delern    文件:CardTest.java   
@Test
public void cards_createdAndAnsweredTrue() {
    final Deck deck = new Deck(mUser);
    List<ScheduledCard> scs = mUser.save().andThen((final CompletableObserver cs) -> {
        deck.setName("TestAnswer");
        deck.setAccepted(true);
        deck.create().subscribe(cs);
    }).andThen((ObservableSource<List<Deck>>) observer ->
            mUser.fetchChildren(mUser.getChildReference(Deck.class), Deck.class)
                    .subscribe(observer)
    ).firstOrError().flatMapCompletable((final List<Deck> data) -> {
        assertTrue(data.size() == 1 && data.get(0).getName().equals("TestAnswer"));
        Card newCard = new Card(data.get(0));
        newCard.setFront("frontSide");
        newCard.setBack("backSide");
        return newCard.create();
    }).andThen((ObservableSource<Card>) observer ->
            deck.startScheduledCardWatcher().subscribe(observer)
    ).firstOrError().flatMapCompletable((final Card card) ->
            card.answer(true)
    ).andThen((ObservableSource<List<ScheduledCard>>) observer ->
            deck.fetchChildren(deck.getChildReference(ScheduledCard.class), ScheduledCard.class)
                    .subscribe(observer)
    ).firstOrError().blockingGet();
    assertTrue(scs.size() == 1
            && scs.get(0).getLevel().equals(Level.L1.name()));
}
项目:delern    文件:CardTest.java   
@Test
public void cards_createdAndAnsweredFalse() {
    final Deck deck = new Deck(mUser);
    List<ScheduledCard> scs = mUser.save().andThen((final CompletableObserver cs) -> {
        deck.setName("TestAnswer");
        deck.setAccepted(true);
        deck.create().subscribe(cs);
    }).andThen((ObservableSource<List<Deck>>) observer ->
            mUser.fetchChildren(mUser.getChildReference(Deck.class), Deck.class)
                    .subscribe(observer)
    ).firstOrError().flatMapCompletable((final List<Deck> data) -> {
        assertTrue(data.size() == 1 && data.get(0).getName().equals("TestAnswer"));
        Card newCard = new Card(data.get(0));
        newCard.setFront("frontSide");
        newCard.setBack("backSide");
        return newCard.create();
    }).andThen((ObservableSource<Card>) observer ->
            deck.startScheduledCardWatcher().subscribe(observer)
    ).firstOrError().flatMapCompletable((final Card card) ->
            card.answer(false)
    ).andThen((ObservableSource<List<ScheduledCard>>) observer ->
            deck.fetchChildren(deck.getChildReference(ScheduledCard.class), ScheduledCard.class)
                    .subscribe(observer)
    ).firstOrError().blockingGet();
    assertTrue(scs.size() == 1
            && scs.get(0).getLevel().equals(Level.L0.name()));
}
项目:Fast-Android-Networking    文件:Rx2ApiTestActivity.java   
public void downloadImage(final View view) {
    String url = "http://i.imgur.com/AtbX9iX.png";
    Rx2AndroidNetworking.download(url, Utils.getRootDirPath(getApplicationContext()), "image1.png")
            .build()
            .setAnalyticsListener(new AnalyticsListener() {
                @Override
                public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
                    Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
                    Log.d(TAG, " bytesSent : " + bytesSent);
                    Log.d(TAG, " bytesReceived : " + bytesReceived);
                    Log.d(TAG, " isFromCache : " + isFromCache);
                }
            })
            .getDownloadCompletable()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new CompletableObserver() {
                @Override
                public void onSubscribe(@NonNull Disposable disposable) {

                }

                @Override
                public void onComplete() {
                    Log.d(TAG, "File download Completed");
                    Log.d(TAG, "onDownloadComplete isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
                }

                @Override
                public void onError(@NonNull Throwable throwable) {
                    Utils.logError(TAG, throwable);
                }
            });
}
项目:AutoDispose    文件:AutoDisposeCompletableObserverTest.java   
@Test public void verifyObserverDelegate() {
  final AtomicReference<CompletableObserver> atomicObserver = new AtomicReference<>();
  final AtomicReference<CompletableObserver> atomicAutoDisposingObserver =
      new AtomicReference<>();
  try {
    RxJavaPlugins.setOnCompletableSubscribe(
        new BiFunction<Completable, CompletableObserver, CompletableObserver>() {
          @Override
          public CompletableObserver apply(Completable source, CompletableObserver observer) {
            if (atomicObserver.get() == null) {
              atomicObserver.set(observer);
            } else if (atomicAutoDisposingObserver.get() == null) {
              atomicAutoDisposingObserver.set(observer);
              RxJavaPlugins.setOnObservableSubscribe(null);
            }
            return observer;
          }
        });
    Completable.complete()
        .as(autoDisposable(ScopeProvider.UNBOUND))
        .subscribe();

    assertThat(atomicAutoDisposingObserver.get()).isNotNull();
    assertThat(atomicAutoDisposingObserver.get()).isInstanceOf(
        AutoDisposingCompletableObserver.class);
    assertThat(
        ((AutoDisposingCompletableObserver) atomicAutoDisposingObserver.get()).delegateObserver())
        .isNotNull();
    assertThat(
        ((AutoDisposingCompletableObserver) atomicAutoDisposingObserver.get()).delegateObserver())
        .isSameAs(atomicObserver.get());
  } finally {
    RxJavaPlugins.reset();
  }
}
项目:GroceryStore    文件:RxUtil.java   
public static CompletableObserver emptyCompletableObserver() {
    return new CompletableObserver() {
        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onComplete() {
        }

        @Override
        public void onError(Throwable e) {
        }
    };
}
项目:resilience4j    文件:CircuitBreakerCompletableObserverTest.java   
@Test
public void shouldNotAffectCircuitBreakerWhenWasDisposedAfterNotPermittedSubscribe() throws Exception {
    // Given
    Disposable disposable = mock(Disposable.class);
    CompletableObserver childObserver = mock(CompletableObserver.class);
    CompletableObserver decoratedObserver = CircuitBreakerOperator.of(circuitBreaker).apply(childObserver);
    circuitBreaker.transitionToOpenState();
    decoratedObserver.onSubscribe(disposable);

    // When
    ((Disposable) decoratedObserver).dispose();

    // Then
    assertNoRegisteredCall();
}
项目:vertx-rx    文件:HelperTest.java   
@Test
public void testToCompletableObserverSuccess() {
  Future<String> fut = Future.future();
  CompletableObserver observer = CompletableHelper.toObserver(fut);
  Completable s = Completable.complete();
  s.subscribe(observer);
  assertTrue(fut.succeeded());
  assertNull(fut.result());
}