當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。