当前位置: 首页>>代码示例>>Java>>正文


Java PublishSubject.create方法代码示例

本文整理汇总了Java中io.reactivex.subjects.PublishSubject.create方法的典型用法代码示例。如果您正苦于以下问题:Java PublishSubject.create方法的具体用法?Java PublishSubject.create怎么用?Java PublishSubject.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.reactivex.subjects.PublishSubject的用法示例。


在下文中一共展示了PublishSubject.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPersistStderrReturnsADisposableThatStopsFurtherReads

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void testPersistStderrReturnsADisposableThatStopsFurtherReads() {
    final JobDAO dao = getInstance();
    final JobId jobId = dao.persist(STANDARD_VALID_REQUEST).getId();
    final Subject<byte[]> stderrSubject = PublishSubject.create();
    final AtomicBoolean stderrObsWasRead = new AtomicBoolean(false);
    final Observable<byte[]> stderrObs = stderrSubject.map(data -> {
        stderrObsWasRead.set(true);
        return data;
    });

    final Disposable disposable = dao.appendStderr(jobId, stderrObs);
    disposable.dispose();
    stderrSubject.onNext(TestHelpers.generateRandomBytes());

    assertThat(stderrObsWasRead.get());
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:18,代码来源:JobsDAOTest.java

示例2: main

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
public static void main(String[] args) {
    Subject<String> subject = PublishSubject.create();
    subject.map(String::length)
            .subscribe(System.out::println);
    subject.onNext("Alpha");
    subject.onNext("Beta");
    subject.onNext("Gamma");
    subject.onComplete();
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:10,代码来源:Ch5_20.java

示例3: start_openDrawerIntent_shouldOpenTheDrawer

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void start_openDrawerIntent_shouldOpenTheDrawer() {
  // given
  TestObserver<SnackbarMessageEvent> snackbarMessage$ = new TestObserver<>();
  PublishSubject<Trigger> openDrawerIntent = PublishSubject.create();
  given(view.openDrawerIntent$()).willReturn(openDrawerIntent);
  given(view.readAboutIntent$()).willReturn(noTriggers());
  given(view.openProjectOnGitHubIntent$()).willReturn(noTriggers());
  given(view.selectLanguageIntent$()).willReturn(noTriggers());
  DrawerPresenter presenter = new DrawerPresenter(
      "http://foo.com", Sink.of(snackbarMessage$), urlOpener
  );
  presenter.start(view);

  // when
  fire(openDrawerIntent);

  // then
  verify(view).openDrawerIntent$();
  verify(view).readAboutIntent$();
  verify(view).openProjectOnGitHubIntent$();
  verify(view).selectLanguageIntent$();
  verify(view).openDrawer(true);
  then(view).shouldHaveNoMoreInteractions();
  then(urlOpener).shouldHaveZeroInteractions();
  snackbarMessage$.assertNoValues();
}
 
开发者ID:xemantic,项目名称:github-users,代码行数:28,代码来源:DrawerPresenterTest.java

示例4: start_readAboutIntent_shouldPostToSnackbar

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void start_readAboutIntent_shouldPostToSnackbar() {
  // given
  TestObserver<SnackbarMessageEvent> snackbarMessage$ = new TestObserver<>();
  PublishSubject<Trigger> readAboutIntent = PublishSubject.create();
  given(view.openDrawerIntent$()).willReturn(noTriggers());
  given(view.readAboutIntent$()).willReturn(readAboutIntent);
  given(view.openProjectOnGitHubIntent$()).willReturn(noTriggers());
  given(view.selectLanguageIntent$()).willReturn(noTriggers());
  DrawerPresenter presenter = new DrawerPresenter(
      "http://foo.com",
      Sink.of(snackbarMessage$),
      urlOpener
  );
  presenter.start(view);

  // when
  fire(readAboutIntent);

  // then
  verify(view).openDrawerIntent$();
  verify(view).readAboutIntent$();
  verify(view).openProjectOnGitHubIntent$();
  verify(view).selectLanguageIntent$();
  then(view).shouldHaveNoMoreInteractions();
  then(urlOpener).shouldHaveZeroInteractions();
  snackbarMessage$.assertValueCount(1);
  SnackbarMessageEvent event = snackbarMessage$.values().get(0);
  assertThat(event.getMessage()).isEqualTo("To be implemented soon");
}
 
开发者ID:xemantic,项目名称:github-users,代码行数:31,代码来源:DrawerPresenterTest.java

示例5: testPersistStderrReadsDataFromObservable

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void testPersistStderrReadsDataFromObservable() {
    final JobDAO dao = getInstance();
    final JobId jobId = dao.persist(STANDARD_VALID_REQUEST).getId();
    final Subject<byte[]> stderrSubject = PublishSubject.create();
    final AtomicBoolean stderrObsWasRead = new AtomicBoolean(false);
    final Observable<byte[]> stderrObs = stderrSubject.map(data -> {
        stderrObsWasRead.set(true);
        return data;
    });

    dao.appendStderr(jobId, stderrObs);

    assertThat(stderrObsWasRead.get());
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:16,代码来源:JobsDAOTest.java

示例6: WallsImpl

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
public WallsImpl(INetworker networker, IStores repositories) {
    this.minorUpdatesPublisher = PublishSubject.create();
    this.majorUpdatesPublisher = PublishSubject.create();
    this.postInvalidatePublisher = PublishSubject.create();

    this.networker = networker;
    this.repositories = repositories;
    this.ownersInteractor = new OwnersInteractor(networker, repositories.owners());
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:10,代码来源:WallsImpl.java

示例7: onEvent_errorInSubscribedObservable_shouldStaySubscribedAndHandleNextEvents

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void onEvent_errorInSubscribedObservable_shouldStaySubscribedAndHandleNextEvents() throws Exception {
  // given
  List<String> received = new LinkedList<>();
  AtomicInteger counter = new AtomicInteger(0);
  PublishSubject<String> subject = PublishSubject.create();
  TestPresenter presenter = new TestPresenter();
  presenter
      .on(
          subject.doOnNext(value -> {
            if (counter.incrementAndGet() == 1) {
              throw new Exception("buzz");
            }
            received.add(value);
          })
      )
      .call(subscriber);

  // when
  subject.onNext("foo"); // throws exception
  subject.onNext("bar");

  // then
  verify(subscriber).accept("bar");
  verifyNoMoreInteractions(subscriber);
  assertThat(received).containsExactly("bar");
  uncaughtThrown.expect(Exception.class);
  uncaughtThrown.expectMessage("buzz");
}
 
开发者ID:xemantic,项目名称:github-users,代码行数:30,代码来源:PresenterTest.java

示例8: eventThrowsBadException

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void eventThrowsBadException() {
    PublishSubject<String> stream = PublishSubject.create();
    PublishSubject<String> lifecycle = PublishSubject.create();

    TestObserver<String> testObserver = stream
        .compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS))
        .test();

    // We get an error from the function for this lifecycle event
    lifecycle.onNext("ick");
    stream.onNext("1");

    testObserver.assertNoValues();

    // We only want to check for our IllegalArgumentException, but may have
    // to wade through a CompositeException to get at it.
    testObserver.assertError(new Predicate<Throwable>() {
        @Override
        public boolean test(Throwable throwable) throws Exception {
            if (throwable instanceof CompositeException) {
                CompositeException ce = (CompositeException) throwable;
                for (Throwable t : ce.getExceptions()) {
                    if (t instanceof IllegalArgumentException) {
                        return true;
                    }
                }
            }

            return false;
        }
    });
}
 
开发者ID:xufreshman,项目名称:RxLifeCycle,代码行数:34,代码来源:OutsideLifecycleExceptionTest.java

示例9: onEvent_errorInSubscription_shouldStaySubscribedAndHandleNextEvents

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void onEvent_errorInSubscription_shouldStaySubscribedAndHandleNextEvents() throws Exception {
  // given
  List<String> received = new LinkedList<>();
  AtomicInteger counter = new AtomicInteger(0);
  PublishSubject<String> subject = PublishSubject.create();
  TestPresenter presenter = new TestPresenter();
  doAnswer(invocation -> {
    if (counter.incrementAndGet() == 1) {
      throw new RuntimeException("buzz");
    }
    received.add(invocation.getArgument(0));
    return null;
  }).when(subscriber).accept(anyString());
  presenter.on(subject).call(subscriber);

  // when
  subject.onNext("foo"); // throws exception
  subject.onNext("bar");

  // then
  verify(subscriber).accept("foo");
  verify(subscriber).accept("bar");
  verifyNoMoreInteractions(subscriber);
  assertThat(received).containsExactly("bar");
  uncaughtThrown.expect(RuntimeException.class);
  uncaughtThrown.expectMessage("buzz");
}
 
开发者ID:xemantic,项目名称:github-users,代码行数:29,代码来源:PresenterTest.java

示例10: testExecuteWritesStderrToTheStderrListener

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void testExecuteWritesStderrToTheStderrListener() throws Throwable {
    final JobExecutor jobExecutor = getInstance();
    final String msgSuppliedToEcho = generateRandomString();
    final String bashArg = "echo " + msgSuppliedToEcho + " 1>&2"; // TODO: Naughty.
    final PersistedJob req =
            standardRequestWithCommand("bash", "-c", bashArg);
    final AtomicReference<byte[]> bytesEchoedToStderr = new AtomicReference<>(new byte[]{});
    final Subject<byte[]> stderrSubject = PublishSubject.create();

    stderrSubject.subscribe(bytes ->
            bytesEchoedToStderr.getAndUpdate(existingBytes ->
                    Bytes.concat(existingBytes, bytes)));

    final Semaphore s = new Semaphore(1);
    s.acquire();
    stderrSubject.doOnComplete(s::release).subscribe();

    final JobEventListeners listeners =
            createStderrListener(stderrSubject);

    jobExecutor.execute(req, listeners);

    s.tryAcquire(TestConstants.DEFAULT_TIMEOUT, MILLISECONDS);

    final String stringFromStderr = new String(bytesEchoedToStderr.get()).trim();
    assertThat(stringFromStderr).isEqualTo(msgSuppliedToEcho);
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:29,代码来源:JobExecutorTest.java

示例11: calculateProductScore

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Override
public StreamObserver<Product> calculateProductScore(StreamObserver<CalculateProductScoreResponse> responseObserver) {
  //define download stream behaviour
  PublishSubject<CalculateProductScoreResponse> downloadStream = PublishSubject.create();
  downloadStream
      .doOnNext(response -> {
        responseObserver.onNext(response);
        counter.labels("calculateProductScore_download", "success");
      })
      .doOnError(t -> {
        log.error("error on calculate product score response", t);
        responseObserver.onError(t);
        counter.labels("calculateProductScore_download", "failed");
      })
      .doOnComplete(() -> {
        log.info("calculate product score response done");
        responseObserver.onCompleted();
      })
      .subscribe();
  //define upload stream behaviour
  PublishSubject<Product> uploadStream = PublishSubject.create();
  uploadStream
      .doOnNext(product -> {
        log.debug(" calculate product score - {}", product);
        productDao.calculateProductScore(product, downloadStream);
        counter.labels("calculateProductScore_upload", "success");
      })
      .doOnError(t -> {
        log.info("client upload got error", t);
        downloadStream.onError(t);
        counter.labels("calculateProductScore_upload", "failed");
      })
      .doOnComplete(() -> {
        log.info("client upload complete");
        downloadStream.onComplete();
      })
      .subscribe();

  return new RxStreamObserver<>(uploadStream);

}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:42,代码来源:ProductReadService.java

示例12: getText

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
public Observable<String> getText() {
    mStringFromJs = PublishSubject.create();
    evalJavaScript("__bridge__.setStringFromJs(editor.getValue());");
    return mStringFromJs;
}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:6,代码来源:CodeMirrorEditor.java

示例13: onUserQueryEvent_2UsersToBeFoundWhenPageSizeIs1_shouldRetrieveAndDisplay1UserAndEnableLoadMore

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void onUserQueryEvent_2UsersToBeFoundWhenPageSizeIs1_shouldRetrieveAndDisplay1UserAndEnableLoadMore() {
  // given
  int pageSize = 1;
  int totalCount = 2;
  PublishSubject<UserQueryEvent> userQuery$ = PublishSubject.create();

  User user = mock(User.class);
  SearchResult result = mock(SearchResult.class);
  given(result.getTotalCount()).willReturn(totalCount);
  given(result.getItems()).willReturn(Collections.singletonList(user));
  given(userService.find("foo", 1, pageSize)).willReturn(Single.just(result));

  UserView userView = mock(UserView.class);
  UserPresenter userPresenter = mock(UserPresenter.class);

  given(view.loadMoreIntent$()).willReturn(noTriggers());

  UserListPresenter presenter = new UserListPresenter(
      userQuery$,
      userService,
      () -> userView,
      () -> userPresenter,
      pageSize,
      DEFAULT_USER_SEARCH_LIMIT
  );
  presenter.start(view);

  // when
  userQuery$.onNext(new UserQueryEvent("foo"));

  // then
  InOrder inOrder = inOrder(view, userService, userPresenter);
  inOrder.verify(view).loadMoreIntent$();
  inOrder.verify(view).enableLoadMore(false);
  inOrder.verify(view).loadingFirstPage(true);
  inOrder.verify(userService).find("foo", 1, pageSize);
  inOrder.verify(view).loadingFirstPage(false);
  inOrder.verify(view).clear();
  inOrder.verify(userPresenter).start(user, userView);
  inOrder.verify(view).add(userView);
  inOrder.verify(view).enableLoadMore(true);
  verifyNoMoreInteractions(view, userService, userPresenter);
}
 
开发者ID:xemantic,项目名称:github-users,代码行数:45,代码来源:UserListPresenterTest.java

示例14: setup

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Before
public void setup() {
    stream = PublishSubject.create();
    lifecycle = PublishSubject.create();
}
 
开发者ID:xufreshman,项目名称:RxLifeCycle,代码行数:6,代码来源:UntilEventTransformerObservableTest.java

示例15: setup

import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Before
public void setup() {
    lifecycle = PublishSubject.create();
    testScheduler = new TestScheduler();
}
 
开发者ID:xufreshman,项目名称:RxLifeCycle,代码行数:6,代码来源:UntilLifecycleTransformerSingleTest.java


注:本文中的io.reactivex.subjects.PublishSubject.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。