@Override public Throwable apply(Notification<Object> t) throws Exception { return t.getError(); }
@Override public Throwable apply(Notification<Object> t) throws Exception { return t.getError(); }
@Override public String toString() { Object o = value; if (o == null) { return "OnCompleteNotification"; } if (isError(o)) { return "OnErrorNotification[" + getError(o) + "]"; } return "OnNextNotification[" + value + "]"; }
@Override public String toString() { Object o = value; if (o == null) { return "OnCompleteNotification"; } if (isError(o)) { return "OnErrorNotification[" + getError(o) + "]"; } return "OnNextNotification[" + value + "]"; }
@Override public String toString() { Object o = value; if (o == null) { return "OnCompleteNotification"; } if (isError(o)) { return "OnErrorNotification[" + getError(o) + "]"; } return "OnNextNotification[" + value + "]"; }
@Override protected void onDrop(Notification<T> n) { if (n.isOnError()) { RxJavaCommonPlugins.onError(n.getError()); } } }
/** * Returns the container Throwable error if this notification is an onError * signal, null otherwise. * @return the Throwable error contained or null * @see #isOnError() */ @Nullable public Throwable getError() { Object o = value; if (isError(o)) { return getError(o); } return null; }
/** * Returns the container Throwable error if this notification is an onError * signal, null otherwise. * @return the Throwable error contained or null * @see #isOnError() */ @Nullable public Throwable getError() { Object o = value; if (isError(o)) { return getError(o); } return null; }
/** * Returns the container Throwable error if this notification is an onError * signal, null otherwise. * @return the Throwable error contained or null * @see #isOnError() */ @Nullable public Throwable getError() { Object o = value; if (isError(o)) { return getError(o); } return null; }
@Override public boolean hasNext() { if (iteratorNotification != null && iteratorNotification.isOnError()) { throw ExceptionHelper.wrapOrThrow(iteratorNotification.getError()); } if (iteratorNotification == null) { try { BlockingHelper.verifyNonBlocking(); notify.acquire(); } catch (InterruptedException ex) { dispose(); iteratorNotification = Notification.createOnError(ex); throw ExceptionHelper.wrapOrThrow(ex); } Notification<T> n = value.getAndSet(null); iteratorNotification = n; if (n.isOnError()) { throw ExceptionHelper.wrapOrThrow(n.getError()); } } return iteratorNotification.isOnNext(); }
@Override public boolean hasNext() { if (iteratorNotification != null && iteratorNotification.isOnError()) { throw ExceptionHelper.wrapOrThrow(iteratorNotification.getError()); } if (iteratorNotification == null) { try { BlockingHelper.verifyNonBlocking(); notify.acquire(); } catch (InterruptedException ex) { dispose(); iteratorNotification = Notification.createOnError(ex); throw ExceptionHelper.wrapOrThrow(ex); } Notification<T> n = value.getAndSet(null); iteratorNotification = n; if (n.isOnError()) { throw ExceptionHelper.wrapOrThrow(n.getError()); } } return iteratorNotification.isOnNext(); }
@Override public boolean hasNext() { if (iteratorNotification != null && iteratorNotification.isOnError()) { throw ExceptionHelper.wrapOrThrow(iteratorNotification.getError()); } if (iteratorNotification == null || iteratorNotification.isOnNext()) { if (iteratorNotification == null) { try { BlockingHelper.verifyNonBlocking(); notify.acquire(); } catch (InterruptedException ex) { dispose(); iteratorNotification = Notification.createOnError(ex); throw ExceptionHelper.wrapOrThrow(ex); } Notification<T> n = value.getAndSet(null); iteratorNotification = n; if (n.isOnError()) { throw ExceptionHelper.wrapOrThrow(n.getError()); } } } return iteratorNotification.isOnNext(); }
@Test public void testMaterialize1() { // null will cause onError to be triggered before "three" can be // returned final TestAsyncErrorObservable o1 = new TestAsyncErrorObservable("one", "two", null, "three"); TestLocalObserver observer = new TestLocalObserver(); Observable<Notification<String>> m = Observable.unsafeCreate(o1).materialize(); m.subscribe(observer); try { o1.t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } assertFalse(observer.onError); assertTrue(observer.onComplete); assertEquals(3, observer.notifications.size()); assertTrue(observer.notifications.get(0).isOnNext()); assertEquals("one", observer.notifications.get(0).getValue()); assertTrue(observer.notifications.get(1).isOnNext()); assertEquals("two", observer.notifications.get(1).getValue()); assertTrue(observer.notifications.get(2).isOnError()); assertEquals(NullPointerException.class, observer.notifications.get(2).getError().getClass()); }
@Test public void testMaterialize1() { // null will cause onError to be triggered before "three" can be // returned final TestAsyncErrorObservable o1 = new TestAsyncErrorObservable("one", "two", null, "three"); TestNotificationSubscriber observer = new TestNotificationSubscriber(); Flowable<Notification<String>> m = Flowable.unsafeCreate(o1).materialize(); m.subscribe(observer); try { o1.t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } assertFalse(observer.onError); assertTrue(observer.onComplete); assertEquals(3, observer.notifications.size()); assertTrue(observer.notifications.get(0).isOnNext()); assertEquals("one", observer.notifications.get(0).getValue()); assertTrue(observer.notifications.get(1).isOnNext()); assertEquals("two", observer.notifications.get(1).getValue()); assertTrue(observer.notifications.get(2).isOnError()); assertEquals(NullPointerException.class, observer.notifications.get(2).getError().getClass()); }
@Test public void valueOfOnCompleteIsNull() { Notification<Integer> notification = Notification.createOnComplete(); assertNull(notification.getValue()); assertNull(notification.getError()); assertTrue(notification.isOnComplete()); }
@Test public void testBackpressureWithEmissionThenError() { TestSubscriber<Notification<Integer>> ts = new TestSubscriber<Notification<Integer>>(0L); IllegalArgumentException ex = new IllegalArgumentException(); Flowable.fromIterable(Arrays.asList(1)).concatWith(Flowable.<Integer> error(ex)).materialize() .subscribe(ts); ts.assertNoValues(); ts.request(1); ts.assertValueCount(1); assertTrue(ts.values().get(0).isOnNext()); ts.request(1); ts.assertValueCount(2); assertTrue(ts.values().get(1).isOnError()); assertEquals(ex, ts.values().get(1).getError()); ts.assertComplete(); }