本文整理匯總了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());
}
示例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();
}
示例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();
}
示例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");
}
示例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());
}
示例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());
}
示例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");
}
示例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;
}
});
}
示例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");
}
示例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);
}
示例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);
}
示例12: getText
import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
public Observable<String> getText() {
mStringFromJs = PublishSubject.create();
evalJavaScript("__bridge__.setStringFromJs(editor.getValue());");
return mStringFromJs;
}
示例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);
}
示例14: setup
import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
@Before
public void setup() {
stream = PublishSubject.create();
lifecycle = PublishSubject.create();
}
示例15: setup
import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
@Before
public void setup() {
lifecycle = PublishSubject.create();
testScheduler = new TestScheduler();
}