rx.Observable.test()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中rx.Observable.test()方法的一些代码示例,展示了Observable.test()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.test()方法的具体详情如下:
包路径:rx.Observable
类名称:Observable
方法名:test

Observable.test介绍

暂无

代码示例

代码示例来源:origin: akarnokd/RxJava2Interop

@Test
public void v1RequestZero() {
  toV1Observable(Flowable.range(1, 5))
  .filter(new Func1<Integer, Boolean>() {
    @Override
    public Boolean call(Integer v) {
      return v % 2 == 0;
    }
  })
  .test()
  .assertResult(2, 4);
}

代码示例来源:origin: akarnokd/RxJava2Interop

@Test
public void fo2ToFo1Crash() {
  FlowableOperator<Integer, Integer> transformer = new FlowableOperator<Integer, Integer>() {
    @Override
    public org.reactivestreams.Subscriber<? super Integer> apply(final org.reactivestreams.Subscriber<? super Integer> o) {
      throw new IllegalArgumentException();
    }
  };
  Observable.just(1)
  .lift(toV1Operator(transformer))
  .test()
  .assertFailure(IllegalArgumentException.class);
}

代码示例来源:origin: akarnokd/RxJava2Interop

@Test
public void ft2ToFt1() {
  FlowableTransformer<Integer, Integer> transformer = new FlowableTransformer<Integer, Integer>() {
    @Override
    public Flowable<Integer> apply(Flowable<Integer> o) {
      return o.map(new Function<Integer, Integer>() {
        @Override
        public Integer apply(Integer v) {
          return v + 1;
        }
      });
    }
  };
  rx.Observable.just(1)
  .compose(toV1Transformer(transformer))
  .test()
  .assertResult(2);
}

代码示例来源:origin: akarnokd/RxJava2Interop

@Test
public void ot2ToOt1() {
  ObservableTransformer<Integer, Integer> transformer = new ObservableTransformer<Integer, Integer>() {
    @Override
    public io.reactivex.Observable<Integer> apply(io.reactivex.Observable<Integer> o) {
      return o.map(new Function<Integer, Integer>() {
        @Override
        public Integer apply(Integer v) {
          return v + 1;
        }
      });
    }
  };
  rx.Observable.just(1)
    .compose(toV1Transformer(transformer, BackpressureStrategy.BUFFER))
    .test()
    .assertResult(2);
}

代码示例来源:origin: akarnokd/RxJava2Interop

@Test
public void fo2ToFo1() {
  FlowableOperator<Integer, Integer> transformer = new FlowableOperator<Integer, Integer>() {
    @Override
    public org.reactivestreams.Subscriber<? super Integer> apply(final org.reactivestreams.Subscriber<? super Integer> o) {
      return new org.reactivestreams.Subscriber<Integer>() {
        @Override
        public void onSubscribe(Subscription s) {
          o.onSubscribe(s);
        }
        @Override
        public void onNext(Integer t) {
          o.onNext(t + 1);
        }
        @Override
        public void onError(Throwable e) {
          o.onError(e);
        }
        @Override
        public void onComplete() {
          o.onComplete();
        }
      };
    }
  };
  Observable.just(1)
  .lift(toV1Operator(transformer))
  .test()
  .assertResult(2);
}

代码示例来源:origin: com.microsoft.azure/spring-integration-azure-test

@Test
public void testSendByte() {
  AssertableSubscriber<String> subscriber =
      subscribe(destination, byte[].class).map(Message::getPayload).cast(byte[].class).map(String::new)
                        .test();
  sendSubscribeOperation.sendRx(destination, byteMessage);
  subscriber.assertValue(payload).assertNoErrors();
}

代码示例来源:origin: com.microsoft.azure/spring-integration-azure-test

@Test
public void testSendUser() {
  AssertableSubscriber<User> subscriber =
      subscribe(destination, User.class).map(Message::getPayload).cast(User.class).test();
  sendSubscribeOperation.sendRx(destination, userMessage);
  subscriber.assertValue(user).assertNoErrors();
}

代码示例来源:origin: com.microsoft.azure/spring-integration-azure-test

@Test
public void testSendString() {
  AssertableSubscriber<String> subscriber =
      subscribe(destination, String.class).map(Message::getPayload).cast(String.class).test();
  sendSubscribeOperation.sendRx(destination, stringMessage);
  subscriber.assertValue(payload).assertNoErrors();
}

代码示例来源:origin: com.microsoft.azure/spring-integration-azure-test

@Test
public void testSendReceiveWithRecordCheckpointMode() {
  setCheckpointConfig(CheckpointConfig.builder().checkpointMode(CheckpointMode.RECORD).build());
  AssertableSubscriber<User> subscriber =
      subscribe(destination, User.class).map(Message::getPayload).cast(User.class).test();
  Arrays.stream(messages).forEach(m -> sendSubscribeOperation.sendRx(destination, m));
  subscriber.assertValueCount(messages.length).assertNoErrors();
  verifyCheckpointSuccessCalled(messages.length);
}

代码示例来源:origin: vert-x3/vertx-rx

protected void assertTableContainsInitDataOnly() throws Exception {
 client.rxGetConnection().flatMapObservable(conn -> {
  return uniqueNames(conn).doAfterTerminate(conn::close);
 }).test()
  .awaitTerminalEvent()
  .assertCompleted()
  .assertValues(NAMES.stream().sorted().distinct().toArray(String[]::new));
}

代码示例来源:origin: akarnokd/akarnokd-misc

@Test
  public void test() {
    Observable.error(new IOException())
    .retryWhen(new RetryWhenObservable(5, 1))
    .test()
    .awaitTerminalEvent()
    .assertFailure(IOException.class);
  }
}

代码示例来源:origin: com.microsoft.azure/spring-integration-azure-test

@Test
public void testSendReceiveWithManualCheckpointMode() {
  setCheckpointConfig(CheckpointConfig.builder().checkpointMode(CheckpointMode.MANUAL).build());
  Observable<Message<?>> observable = subscribe(destination, User.class);
  AssertableSubscriber<User> userSubscriber = observable.map(Message::getPayload).cast(User.class).test();
  sendSubscribeOperation.sendRx(destination, userMessage);
  userSubscriber.assertValue(user).assertNoErrors();
  verifyCheckpointSuccessCalled(0);
}

代码示例来源:origin: spotify/mobius

@Test
 public void shouldPropagateErrorsFromUpstream() throws Exception {
  final Throwable expected = new RuntimeException("expected");

  AssertableSubscriber<Integer> subscriber =
    input.compose(RxConnectables.toTransformer(connectable)).test();

  input.onError(expected);

  subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
  subscriber.assertError(expected);
 }
}

代码示例来源:origin: spotify/mobius

@Test
 public void shouldPropagateIncomingErrorsAsUnrecoverable() throws Exception {
  PublishSubject<Integer> input = PublishSubject.create();

  AssertableSubscriber<String> subscriber = input.compose(loop).test();

  Exception expected = new RuntimeException("expected");

  input.onError(expected);

  subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
  subscriber.assertError(new UnrecoverableIncomingException(expected));
 }
}

代码示例来源:origin: vert-x3/vertx-rx

@Test
public void inTransactionFailure() throws Exception {
 Exception error = new Exception();
 inTransaction(error).test()
  .awaitTerminalEvent()
  .assertError(error)
  .assertValues(namesWithExtraFolks());
 assertTableContainsInitDataOnly();
}

代码示例来源:origin: spotify/mobius

@Test
public void effectPerformerInvokesFunctionWithReceivedEffectAndEmitsReturnedEvents() {
 PublishSubject<String> upstream = PublishSubject.create();
 TestScheduler scheduler = new TestScheduler();
 Function<String, Integer> function = s -> s.length();
 AssertableSubscriber<Integer> observer =
   upstream.compose(Transformers.fromFunction(function, scheduler)).test();
 upstream.onNext("Hello");
 scheduler.triggerActions();
 observer.assertValue(5);
}

代码示例来源:origin: spotify/mobius

@Test
public void shouldPropagateErrorsFromConnectable() throws Exception {
 AssertableSubscriber<Integer> subscriber =
   input.compose(RxConnectables.toTransformer(connectable)).test();
 input.onNext("crash");
 subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
 subscriber.assertFailureAndMessage(RuntimeException.class, "crashing!");
}

代码示例来源:origin: vert-x3/vertx-rx

@Test
public void inTransactionSuccess() throws Exception {
 inTransaction(null).test()
  .awaitTerminalEvent()
  .assertCompleted()
  .assertValues(namesWithExtraFolks());
}

代码示例来源:origin: spotify/mobius

@Test
public void shouldPropagateCompletion() throws Exception {
 AssertableSubscriber<Integer> subscriber =
   input.compose(RxConnectables.toTransformer(connectable)).test();
 input.onNext("hi");
 input.onCompleted();
 subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
 subscriber.assertCompleted();
}

代码示例来源:origin: spotify/mobius

@Test
public void consumerTransformerShouldPropagateCompletion() throws Exception {
 AssertableSubscriber<Object> subscriber =
   upstream.compose(Transformers.fromConsumer(consumer, scheduler)).test();
 upstream.onNext("hi");
 upstream.onCompleted();
 scheduler.triggerActions();
 subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
 subscriber.assertCompleted();
}

相关文章

Observable类方法