use of rx.functions.Action1 in project Hystrix by Netflix.
the class HystrixObservableCommandTest method testRequestContextOnTimeout.
private RequestContextTestResults testRequestContextOnTimeout(ExecutionIsolationStrategy isolation, final Scheduler userScheduler) {
final RequestContextTestResults results = new RequestContextTestResults();
TestHystrixObservableCommand<Boolean> command = new TestHystrixObservableCommand<Boolean>(TestHystrixObservableCommand.testPropsBuilder(new TestCircuitBreaker()).setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter().withExecutionIsolationStrategy(isolation).withExecutionTimeoutInMilliseconds(50))) {
@Override
protected Observable<Boolean> construct() {
return Observable.create(new OnSubscribe<Boolean>() {
@Override
public void call(Subscriber<? super Boolean> s) {
results.isContextInitialized.set(HystrixRequestContext.isCurrentThreadInitialized());
results.originThread.set(Thread.currentThread());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// ignore the interrupted exception
}
}
}).subscribeOn(userScheduler);
}
};
results.command = command;
command.toObservable().doOnEach(new Action1<Notification<? super Boolean>>() {
@Override
public void call(Notification<? super Boolean> n) {
results.isContextInitializedObserveOn.set(HystrixRequestContext.isCurrentThreadInitialized());
results.observeOnThread.set(Thread.currentThread());
}
}).subscribe(results.ts);
results.ts.awaitTerminalEvent();
System.out.println("Run => Initialized: " + results.isContextInitialized.get() + " Thread: " + results.originThread.get());
System.out.println("Observed => Initialized: " + results.isContextInitializedObserveOn.get() + " Thread: " + results.observeOnThread.get());
assertEquals(1, results.ts.getOnErrorEvents().size());
assertTrue(command.getExecutionTimeInMilliseconds() > -1);
assertFalse(command.isSuccessfulExecution());
assertTrue(command.isResponseTimedOut());
assertCommandExecutionEvents(command, HystrixEventType.TIMEOUT, HystrixEventType.FALLBACK_MISSING);
assertEquals(0, command.metrics.getCurrentConcurrentExecutionCount());
assertSaneHystrixRequestLog(1);
return results;
}
use of rx.functions.Action1 in project Hystrix by Netflix.
the class HystrixObservableCommandTest method testRequestContextOnBadFailure.
private RequestContextTestResults testRequestContextOnBadFailure(ExecutionIsolationStrategy isolation, final Scheduler userScheduler) {
final RequestContextTestResults results = new RequestContextTestResults();
TestHystrixObservableCommand<Boolean> command = new TestHystrixObservableCommand<Boolean>(TestHystrixObservableCommand.testPropsBuilder(new TestCircuitBreaker()).setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter().withExecutionIsolationStrategy(isolation))) {
@Override
protected Observable<Boolean> construct() {
return Observable.create(new OnSubscribe<Boolean>() {
@Override
public void call(Subscriber<? super Boolean> s) {
results.isContextInitialized.set(HystrixRequestContext.isCurrentThreadInitialized());
results.originThread.set(Thread.currentThread());
throw new RuntimeException("bad onError");
}
}).subscribeOn(userScheduler);
}
};
results.command = command;
command.toObservable().doOnEach(new Action1<Notification<? super Boolean>>() {
@Override
public void call(Notification<? super Boolean> n) {
results.isContextInitializedObserveOn.set(HystrixRequestContext.isCurrentThreadInitialized());
results.observeOnThread.set(Thread.currentThread());
}
}).subscribe(results.ts);
results.ts.awaitTerminalEvent();
System.out.println("Run => Initialized: " + results.isContextInitialized.get() + " Thread: " + results.originThread.get());
System.out.println("Observed => Initialized: " + results.isContextInitializedObserveOn.get() + " Thread: " + results.observeOnThread.get());
assertEquals(1, results.ts.getOnErrorEvents().size());
assertTrue(command.getExecutionTimeInMilliseconds() > -1);
assertFalse(command.isSuccessfulExecution());
assertTrue(command.isFailedExecution());
assertCommandExecutionEvents(command, HystrixEventType.FAILURE, HystrixEventType.FALLBACK_MISSING);
assertEquals(0, command.metrics.getCurrentConcurrentExecutionCount());
assertSaneHystrixRequestLog(1);
return results;
}
use of rx.functions.Action1 in project MyJapanese by 54wall.
the class MainActivity method setViewPager.
@Override
public void setViewPager(final List<BannerItem> data) {
if (bannerSubscription != null && bannerSubscription.isUnsubscribed()) {
bannerSubscription.unsubscribe();
}
mBannerViewPager.setAdapter(new BannerPagerAdapter(getSupportFragmentManager(), data));
mCircleIndicator.setViewPager(mBannerViewPager);
bannerSubscription = Observable.timer(10, 10, TimeUnit.SECONDS).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
int next = (mBannerViewPager.getCurrentItem() + 1) % data.size();
mBannerViewPager.setCurrentItem(next);
}
});
}
use of rx.functions.Action1 in project frodo by android10.
the class LogEverythingObservable method get.
@Override
<T> Observable<T> get(T type) throws Throwable {
final StopWatch stopWatch = new StopWatch();
final Counter emittedItems = new Counter(joinPoint.getMethodName());
return ((Observable<T>) joinPoint.proceed()).doOnSubscribe(new Action0() {
@Override
public void call() {
stopWatch.start();
messageManager.printObservableOnSubscribe(observableInfo);
}
}).doOnEach(new Action1<Notification<? super T>>() {
@Override
public void call(Notification<? super T> notification) {
if (!observableInfo.getSubscribeOnThread().isPresent() && (notification.isOnNext() || notification.isOnError())) {
observableInfo.setSubscribeOnThread(Thread.currentThread().getName());
}
}
}).doOnNext(new Action1<T>() {
@Override
public void call(T value) {
emittedItems.increment();
messageManager.printObservableOnNextWithValue(observableInfo, value);
}
}).doOnError(new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
messageManager.printObservableOnError(observableInfo, throwable);
}
}).doOnCompleted(new Action0() {
@Override
public void call() {
messageManager.printObservableOnCompleted(observableInfo);
}
}).doOnTerminate(new Action0() {
@Override
public void call() {
stopWatch.stop();
observableInfo.setTotalExecutionTime(stopWatch.getTotalTimeMillis());
observableInfo.setTotalEmittedItems(emittedItems.tally());
messageManager.printObservableOnTerminate(observableInfo);
messageManager.printObservableItemTimeInfo(observableInfo);
}
}).doOnUnsubscribe(new Action0() {
@Override
public void call() {
if (!observableInfo.getObserveOnThread().isPresent()) {
observableInfo.setObserveOnThread(Thread.currentThread().getName());
}
messageManager.printObservableThreadInfo(observableInfo);
messageManager.printObservableOnUnsubscribe(observableInfo);
}
});
}
use of rx.functions.Action1 in project xDrip by NightscoutFoundation.
the class ShareTest method attemptRead.
public void attemptRead() {
final ReadDataShare readData = new ReadDataShare(this);
final Action1<Long> systemTimeListener = new Action1<Long>() {
@Override
public void call(Long s) {
Log.d(TAG, "Made the full round trip, got " + s + " as the system time");
Log.d("SYSTTIME", "Made the full round trip, got " + s + " as the system time");
final long addativeSystemTimeOffset = new Date().getTime() - s;
Log.d(TAG, "Made the full round trip, got " + addativeSystemTimeOffset + " offset");
Log.d("SYSTTIME", "Made the full round trip, got " + addativeSystemTimeOffset + " offset");
final Action1<CalRecord[]> calRecordListener = new Action1<CalRecord[]>() {
@Override
public void call(CalRecord[] calRecords) {
Log.d(TAG, "Made the full round trip, got " + calRecords.length + " Cal Records");
Calibration.create(calRecords, addativeSystemTimeOffset, getApplicationContext());
final Action1<SensorRecord[]> sensorRecordListener = new Action1<SensorRecord[]>() {
@Override
public void call(SensorRecord[] sensorRecords) {
Log.d(TAG, "Made the full round trip, got " + sensorRecords.length + " Sensor Records");
BgReading.create(sensorRecords, addativeSystemTimeOffset, getApplicationContext());
final Action1<EGVRecord[]> evgRecordListener = new Action1<EGVRecord[]>() {
@Override
public void call(EGVRecord[] egvRecords) {
Log.d(TAG, "Made the full round trip, got " + egvRecords.length + " EVG Records");
BgReading.create(egvRecords, addativeSystemTimeOffset, getApplicationContext());
}
};
readData.getRecentEGVs(evgRecordListener);
}
};
readData.getRecentSensorRecords(sensorRecordListener);
}
};
readData.getRecentCalRecords(calRecordListener);
}
};
readData.readSystemTime(systemTimeListener);
}
Aggregations