-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error Handling: OnErrorNotImplemented and java.lang.Error #839
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -268,33 +268,6 @@ public void testMergeList() { | |
verify(stringObserver, times(2)).onNext("hello"); | ||
} | ||
|
||
@Test | ||
public void testUnSubscribe() { | ||
TestObservable tA = new TestObservable(); | ||
TestObservable tB = new TestObservable(); | ||
|
||
@SuppressWarnings("unchecked") | ||
Observable<String> m = Observable.create(mergeDelayError(Observable.create(tA), Observable.create(tB))); | ||
Subscription s = m.subscribe(stringObserver); | ||
|
||
tA.sendOnNext("Aone"); | ||
tB.sendOnNext("Bone"); | ||
s.unsubscribe(); | ||
tA.sendOnNext("Atwo"); | ||
tB.sendOnNext("Btwo"); | ||
tA.sendOnCompleted(); | ||
tB.sendOnCompleted(); | ||
|
||
verify(stringObserver, never()).onError(any(Throwable.class)); | ||
verify(stringObserver, times(1)).onNext("Aone"); | ||
verify(stringObserver, times(1)).onNext("Bone"); | ||
assertTrue(tA.unsubscribed); | ||
assertTrue(tB.unsubscribed); | ||
verify(stringObserver, never()).onNext("Atwo"); | ||
verify(stringObserver, never()).onNext("Btwo"); | ||
verify(stringObserver, never()).onCompleted(); | ||
} | ||
|
||
@Test | ||
public void testMergeArrayWithThreading() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed this because it was relying on |
||
final TestASynchronousObservable o1 = new TestASynchronousObservable(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,92 +17,30 @@ | |
|
||
import static org.mockito.Matchers.*; | ||
import static org.mockito.Mockito.*; | ||
import static rx.operators.OperationSynchronize.*; | ||
|
||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import rx.Observable; | ||
import rx.Observer; | ||
import rx.Subscription; | ||
import rx.observers.SafeSubscriber; | ||
import rx.observers.TestSubscriber; | ||
|
||
public class OperationSynchronizeTest { | ||
|
||
/** | ||
* Ensure onCompleted can not be called after an Unsubscribe | ||
*/ | ||
@Test | ||
public void testOnCompletedAfterUnSubscribe() { | ||
TestObservable t = new TestObservable(null); | ||
Observable<String> st = Observable.create(synchronize(Observable.create(t))); | ||
|
||
@SuppressWarnings("unchecked") | ||
Observer<String> w = mock(Observer.class); | ||
Subscription ws = st.subscribe(w); | ||
|
||
System.out.println("ws: " + ws); | ||
|
||
t.sendOnNext("one"); | ||
ws.unsubscribe(); | ||
System.out.println("send onCompleted"); | ||
t.sendOnCompleted(); | ||
|
||
verify(w, times(1)).onNext("one"); | ||
verify(w, Mockito.never()).onCompleted(); | ||
} | ||
|
||
/** | ||
* Ensure onNext can not be called after an Unsubscribe | ||
*/ | ||
@Test | ||
public void testOnNextAfterUnSubscribe() { | ||
TestObservable t = new TestObservable(null); | ||
Observable<String> st = Observable.create(synchronize(Observable.create(t))); | ||
|
||
@SuppressWarnings("unchecked") | ||
Observer<String> w = mock(Observer.class); | ||
Subscription ws = st.subscribe(w); | ||
|
||
t.sendOnNext("one"); | ||
ws.unsubscribe(); | ||
t.sendOnNext("two"); | ||
|
||
verify(w, times(1)).onNext("one"); | ||
verify(w, Mockito.never()).onNext("two"); | ||
} | ||
|
||
/** | ||
* Ensure onError can not be called after an Unsubscribe | ||
*/ | ||
@Test | ||
public void testOnErrorAfterUnSubscribe() { | ||
TestObservable t = new TestObservable(null); | ||
Observable<String> st = Observable.create(synchronize(Observable.create(t))); | ||
|
||
@SuppressWarnings("unchecked") | ||
Observer<String> w = mock(Observer.class); | ||
Subscription ws = st.subscribe(w); | ||
|
||
t.sendOnNext("one"); | ||
ws.unsubscribe(); | ||
t.sendOnError(new RuntimeException("bad")); | ||
|
||
verify(w, times(1)).onNext("one"); | ||
verify(w, Mockito.never()).onError(any(Throwable.class)); | ||
} | ||
public class SafeSubscriberTest { | ||
|
||
/** | ||
* Ensure onNext can not be called after onError | ||
*/ | ||
@Test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these are invalid for |
||
public void testOnNextAfterOnError() { | ||
TestObservable t = new TestObservable(null); | ||
Observable<String> st = Observable.create(synchronize(Observable.create(t))); | ||
Observable<String> st = Observable.create(t); | ||
|
||
@SuppressWarnings("unchecked") | ||
Observer<String> w = mock(Observer.class); | ||
@SuppressWarnings("unused") | ||
Subscription ws = st.subscribe(w); | ||
Subscription ws = st.subscribe(new SafeSubscriber<String>(new TestSubscriber<String>(w))); | ||
|
||
t.sendOnNext("one"); | ||
t.sendOnError(new RuntimeException("bad")); | ||
|
@@ -119,12 +57,12 @@ public void testOnNextAfterOnError() { | |
@Test | ||
public void testOnCompletedAfterOnError() { | ||
TestObservable t = new TestObservable(null); | ||
Observable<String> st = Observable.create(synchronize(Observable.create(t))); | ||
Observable<String> st = Observable.create(t); | ||
|
||
@SuppressWarnings("unchecked") | ||
Observer<String> w = mock(Observer.class); | ||
@SuppressWarnings("unused") | ||
Subscription ws = st.subscribe(w); | ||
Subscription ws = st.subscribe(new SafeSubscriber<String>(new TestSubscriber<String>(w))); | ||
|
||
t.sendOnNext("one"); | ||
t.sendOnError(new RuntimeException("bad")); | ||
|
@@ -141,12 +79,12 @@ public void testOnCompletedAfterOnError() { | |
@Test | ||
public void testOnNextAfterOnCompleted() { | ||
TestObservable t = new TestObservable(null); | ||
Observable<String> st = Observable.create(synchronize(Observable.create(t))); | ||
Observable<String> st = Observable.create(t); | ||
|
||
@SuppressWarnings("unchecked") | ||
Observer<String> w = mock(Observer.class); | ||
@SuppressWarnings("unused") | ||
Subscription ws = st.subscribe(w); | ||
Subscription ws = st.subscribe(new SafeSubscriber<String>(new TestSubscriber<String>(w))); | ||
|
||
t.sendOnNext("one"); | ||
t.sendOnCompleted(); | ||
|
@@ -164,12 +102,12 @@ public void testOnNextAfterOnCompleted() { | |
@Test | ||
public void testOnErrorAfterOnCompleted() { | ||
TestObservable t = new TestObservable(null); | ||
Observable<String> st = Observable.create(synchronize(Observable.create(t))); | ||
Observable<String> st = Observable.create(t); | ||
|
||
@SuppressWarnings("unchecked") | ||
Observer<String> w = mock(Observer.class); | ||
@SuppressWarnings("unused") | ||
Subscription ws = st.subscribe(w); | ||
Subscription ws = st.subscribe(new SafeSubscriber<String>(new TestSubscriber<String>(w))); | ||
|
||
t.sendOnNext("one"); | ||
t.sendOnCompleted(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,7 @@ public Notification<String> call(Notification<T> expectedNotfication, Notificati | |
message.append(" ").append(expectedNotfication.getValue()); | ||
if (expectedNotfication.hasThrowable()) | ||
message.append(" ").append(expectedNotfication.getThrowable()); | ||
return new Notification<String>("equals " + message.toString()); | ||
return Notification.createOnNext("equals " + message.toString()); | ||
} | ||
else { | ||
StringBuilder error = new StringBuilder(); | ||
|
@@ -116,7 +116,7 @@ public Notification<String> call(Notification<T> expectedNotfication, Notificati | |
error.append(" ").append(actualNotification.getThrowable()); | ||
error.append(">"); | ||
|
||
return new Notification<String>(new AssertionError(error.toString())); | ||
return Notification.createOnError(new AssertionError(error.toString())); | ||
} | ||
} | ||
}; | ||
|
@@ -131,9 +131,9 @@ public Notification<String> call(Notification<String> a, Notification<String> b) | |
fail |= b.isOnError(); | ||
|
||
if (fail) | ||
return new Notification<String>(new AssertionError(message)); | ||
return Notification.createOnError(new AssertionError(message)); | ||
else | ||
return new Notification<String>(message); | ||
return Notification.createOnNext(message); | ||
} | ||
}; | ||
|
||
|
@@ -142,9 +142,9 @@ public Notification<String> call(Notification<String> a, Notification<String> b) | |
public Notification<Void> call(Notification<String> outcome) { | ||
if (outcome.isOnError()) { | ||
String fullMessage = (message != null ? message + ": " : "") + "Observables are different\n\t" + outcome.getThrowable().getMessage(); | ||
return new Notification<Void>(new AssertionError(fullMessage)); | ||
return Notification.createOnError(new AssertionError(fullMessage)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed these while debugging why the |
||
} | ||
return new Notification<Void>(); | ||
return Notification.createOnCompleted(); | ||
} | ||
}).dematerialize(); | ||
return outcomeObservable; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/** | ||
* Copyright 2014 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package rx.util; | ||
|
||
import org.junit.Test; | ||
|
||
import rx.Observable; | ||
import rx.Observer; | ||
import rx.subjects.PublishSubject; | ||
import rx.util.functions.Action1; | ||
|
||
public class ExceptionsTest { | ||
|
||
@Test(expected = OnErrorNotImplementedException.class) | ||
public void testOnErrorNotImplementedIsThrown() { | ||
Observable.from(1, 2, 3).subscribe(new Action1<Integer>() { | ||
|
||
@Override | ||
public void call(Integer t1) { | ||
throw new RuntimeException("hello"); | ||
} | ||
|
||
}); | ||
} | ||
|
||
@Test(expected = StackOverflowError.class) | ||
public void testStackOverflowIsThrown() { | ||
final PublishSubject<Integer> a = PublishSubject.create(); | ||
final PublishSubject<Integer> b = PublishSubject.create(); | ||
new Observer<Integer>() { | ||
|
||
@Override | ||
public void onCompleted() { | ||
|
||
} | ||
|
||
@Override | ||
public void onError(Throwable e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
@Override | ||
public void onNext(Integer args) { | ||
System.out.println(args); | ||
} | ||
}; | ||
a.subscribe(new Observer<Integer>() { | ||
|
||
@Override | ||
public void onCompleted() { | ||
|
||
} | ||
|
||
@Override | ||
public void onError(Throwable e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
@Override | ||
public void onNext(Integer args) { | ||
System.out.println(args); | ||
} | ||
}); | ||
b.subscribe(); | ||
a.subscribe(new Observer<Integer>() { | ||
|
||
@Override | ||
public void onCompleted() { | ||
|
||
} | ||
|
||
@Override | ||
public void onError(Throwable e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
@Override | ||
public void onNext(Integer args) { | ||
b.onNext(args + 1); | ||
} | ||
}); | ||
b.subscribe(new Observer<Integer>() { | ||
|
||
@Override | ||
public void onCompleted() { | ||
|
||
} | ||
|
||
@Override | ||
public void onError(Throwable e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
@Override | ||
public void onNext(Integer args) { | ||
a.onNext(args + 1); | ||
} | ||
}); | ||
a.onNext(1); | ||
} | ||
|
||
@Test(expected = ThreadDeath.class) | ||
public void testThreadDeathIsThrown() { | ||
Observable.from(1).subscribe(new Observer<Integer>() { | ||
|
||
@Override | ||
public void onCompleted() { | ||
|
||
} | ||
|
||
@Override | ||
public void onError(Throwable e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
@Override | ||
public void onNext(Integer t) { | ||
throw new ThreadDeath(); | ||
} | ||
|
||
}); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made this class only be responsible for synchronization, not contract enforcement.
It was colliding with error handling logic in
SafeSubscriber
and swallowing errors trying to be thrown.