use of rx.observers.TestSubscriber in project MovieGuide by esoxjem.
the class MovieDetailsPresenterImplTest method shouldBeAbleToShowTrailers.
@Test
public void shouldBeAbleToShowTrailers() {
TestScheduler testScheduler = new TestScheduler();
TestSubscriber<List<Video>> testSubscriber = new TestSubscriber<>();
Observable<List<Video>> responseObservable = Observable.just(videos).subscribeOn(testScheduler);
responseObservable.subscribe(testSubscriber);
when(movieDetailsInteractor.getTrailers(anyString())).thenReturn(responseObservable);
movieDetailsPresenter.showTrailers(movie);
testScheduler.triggerActions();
testSubscriber.assertNoErrors();
testSubscriber.assertCompleted();
verify(view).showTrailers(videos);
}
use of rx.observers.TestSubscriber in project MovieGuide by esoxjem.
the class MoviesListingPresenterImplTest method shouldBeAbleToDisplayMovies.
@Test
public void shouldBeAbleToDisplayMovies() {
TestScheduler testScheduler = new TestScheduler();
TestSubscriber<List<Movie>> testSubscriber = new TestSubscriber<>();
Observable<List<Movie>> responseObservable = Observable.just(movies).subscribeOn(testScheduler);
responseObservable.subscribe(testSubscriber);
when(interactor.fetchMovies()).thenReturn(responseObservable);
presenter.setView(view);
testScheduler.triggerActions();
testSubscriber.assertNoErrors();
testSubscriber.onCompleted();
verify(view).showMovies(movies);
}
use of rx.observers.TestSubscriber in project Hystrix by Netflix.
the class HystrixCollapserTest method testUnsubscribeFromSomeDuplicateArgsDoesNotRemoveFromBatch.
@Test
public void testUnsubscribeFromSomeDuplicateArgsDoesNotRemoveFromBatch() throws Exception {
final int NUM = 10;
List<Observable<Integer>> observables = new ArrayList<Observable<Integer>>();
for (int i = 0; i < NUM; i++) {
MyCollapser c = new MyCollapser("5", true);
observables.add(c.toObservable());
}
List<TestSubscriber<Integer>> subscribers = new ArrayList<TestSubscriber<Integer>>();
List<Subscription> subscriptions = new ArrayList<Subscription>();
for (final Observable<Integer> o : observables) {
final TestSubscriber<Integer> sub = new TestSubscriber<Integer>();
subscribers.add(sub);
Subscription s = o.subscribe(sub);
subscriptions.add(s);
}
//unsubscribe from all but 1
for (int i = 0; i < NUM - 1; i++) {
Subscription s = subscriptions.get(i);
s.unsubscribe();
}
Thread.sleep(100);
//all subscribers with an active subscription should receive the same value
for (TestSubscriber<Integer> sub : subscribers) {
if (!sub.isUnsubscribed()) {
sub.awaitTerminalEvent(1000, TimeUnit.MILLISECONDS);
System.out.println("Subscriber received : " + sub.getOnNextEvents());
sub.assertNoErrors();
sub.assertValues(5);
} else {
System.out.println("Subscriber is unsubscribed");
}
}
}
use of rx.observers.TestSubscriber in project Hystrix by Netflix.
the class HystrixCommandTest method testObservableTimeoutNoFallbackThreadContext.
/**
* See https://github.com/Netflix/Hystrix/issues/212
*/
@Test
public void testObservableTimeoutNoFallbackThreadContext() {
TestSubscriber<Object> ts = new TestSubscriber<Object>();
final AtomicReference<Thread> onErrorThread = new AtomicReference<Thread>();
final AtomicBoolean isRequestContextInitialized = new AtomicBoolean();
TestHystrixCommand<Integer> command = getCommand(ExecutionIsolationStrategy.THREAD, AbstractTestHystrixCommand.ExecutionResult.SUCCESS, 200, AbstractTestHystrixCommand.FallbackResult.UNIMPLEMENTED, 50);
command.toObservable().doOnError(new Action1<Throwable>() {
@Override
public void call(Throwable t1) {
System.out.println("onError: " + t1);
System.out.println("onError Thread: " + Thread.currentThread());
System.out.println("ThreadContext in onError: " + HystrixRequestContext.isCurrentThreadInitialized());
onErrorThread.set(Thread.currentThread());
isRequestContextInitialized.set(HystrixRequestContext.isCurrentThreadInitialized());
}
}).subscribe(ts);
ts.awaitTerminalEvent();
assertTrue(isRequestContextInitialized.get());
assertTrue(onErrorThread.get().getName().startsWith("HystrixTimer"));
List<Throwable> errors = ts.getOnErrorEvents();
assertEquals(1, errors.size());
Throwable e = errors.get(0);
if (errors.get(0) instanceof HystrixRuntimeException) {
HystrixRuntimeException de = (HystrixRuntimeException) e;
assertNotNull(de.getFallbackException());
assertTrue(de.getFallbackException() instanceof UnsupportedOperationException);
assertNotNull(de.getImplementingClass());
assertNotNull(de.getCause());
assertTrue(de.getCause() instanceof TimeoutException);
} else {
fail("the exception should be ExecutionException with cause as HystrixRuntimeException");
}
assertTrue(command.getExecutionTimeInMilliseconds() > -1);
assertTrue(command.isResponseTimedOut());
assertCommandExecutionEvents(command, HystrixEventType.TIMEOUT, HystrixEventType.FALLBACK_MISSING);
assertNotNull(command.getExecutionException());
assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount());
assertSaneHystrixRequestLog(1);
}
use of rx.observers.TestSubscriber in project Hystrix by Netflix.
the class HystrixObservableCommandTest method testObservableTimeoutNoFallbackThreadContext.
/**
* See https://github.com/Netflix/Hystrix/issues/212
*/
@Test
public void testObservableTimeoutNoFallbackThreadContext() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
final AtomicReference<Thread> onErrorThread = new AtomicReference<Thread>();
final AtomicBoolean isRequestContextInitialized = new AtomicBoolean();
TestHystrixObservableCommand<Integer> command = getCommand(ExecutionIsolationStrategy.SEMAPHORE, AbstractTestHystrixCommand.ExecutionResult.SUCCESS, 200, AbstractTestHystrixCommand.FallbackResult.UNIMPLEMENTED, 100);
command.toObservable().doOnError(new Action1<Throwable>() {
@Override
public void call(Throwable t1) {
System.out.println("onError: " + t1);
System.out.println("onError Thread: " + Thread.currentThread());
System.out.println("ThreadContext in onError: " + HystrixRequestContext.isCurrentThreadInitialized());
onErrorThread.set(Thread.currentThread());
isRequestContextInitialized.set(HystrixRequestContext.isCurrentThreadInitialized());
}
}).subscribe(ts);
ts.awaitTerminalEvent();
assertTrue(isRequestContextInitialized.get());
assertTrue(onErrorThread.get().getName().startsWith("HystrixTimer"));
List<Throwable> errors = ts.getOnErrorEvents();
assertEquals(1, errors.size());
Throwable e = errors.get(0);
if (errors.get(0) instanceof HystrixRuntimeException) {
HystrixRuntimeException de = (HystrixRuntimeException) e;
assertNotNull(de.getFallbackException());
assertTrue(de.getFallbackException() instanceof UnsupportedOperationException);
assertNotNull(de.getImplementingClass());
assertNotNull(de.getCause());
assertTrue(de.getCause() instanceof TimeoutException);
} else {
fail("the exception should be ExecutionException with cause as HystrixRuntimeException");
}
assertTrue(command.getExecutionTimeInMilliseconds() > -1);
assertTrue(command.isResponseTimedOut());
assertNotNull(command.getExecutionException());
assertCommandExecutionEvents(command, HystrixEventType.TIMEOUT, HystrixEventType.FALLBACK_MISSING);
assertEquals(0, command.metrics.getCurrentConcurrentExecutionCount());
assertSaneHystrixRequestLog(1);
assertFalse(command.isExecutedInThread());
}
Aggregations