本文整理了Java中rx.Subscription.isUnsubscribed()
方法的一些代码示例,展示了Subscription.isUnsubscribed()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Subscription.isUnsubscribed()
方法的具体详情如下:
包路径:rx.Subscription
类名称:Subscription
方法名:isUnsubscribed
[英]Indicates whether this Subscription is currently unsubscribed.
[中]指示此订阅当前是否已取消订阅。
代码示例来源:origin: ivacf/archi
@Override
public void destroy() {
this.context = null;
if (subscription != null && !subscription.isUnsubscribed()) subscription.unsubscribe();
}
代码示例来源:origin: ivacf/archi
@Override
public void destroy() {
if (subscription != null && !subscription.isUnsubscribed()) subscription.unsubscribe();
subscription = null;
context = null;
dataListener = null;
}
代码示例来源:origin: cymcsg/UltimateAndroid
public static void unsubscribeIfNotNull(Subscription subscription) {
if (subscription != null && !subscription.isUnsubscribed()) {
subscription.unsubscribe();
}
}
}
代码示例来源:origin: konmik/nucleus
/**
* Checks if a restartable is unsubscribed.
*
* @param restartableId id of the restartable.
* @return true if the subscription is null or unsubscribed, false otherwise.
*/
public boolean isUnsubscribed(int restartableId) {
Subscription subscription = restartableSubscriptions.get(restartableId);
return subscription == null || subscription.isUnsubscribed();
}
代码示例来源:origin: konmik/nucleus
/**
* {@inheritDoc}
*/
@CallSuper
@Override
protected void onSave(Bundle state) {
for (int i = requested.size() - 1; i >= 0; i--) {
int restartableId = requested.get(i);
Subscription subscription = restartableSubscriptions.get(restartableId);
if (subscription != null && subscription.isUnsubscribed())
requested.remove(i);
}
state.putIntegerArrayList(REQUESTED_KEY, requested);
}
代码示例来源:origin: konmik/nucleus
@Test
public void testAdd() throws Exception {
RxPresenter presenter = new RxPresenter();
Subscription mock = Mockito.mock(Subscription.class);
when(mock.isUnsubscribed()).thenReturn(false);
presenter.add(mock);
presenter.onDestroy();
verify(mock, times(1)).unsubscribe();
verify(mock, atLeastOnce()).isUnsubscribed();
verifyNoMoreInteractions(mock);
}
代码示例来源:origin: konmik/nucleus
@Test
public void testAddRemove() throws Exception {
RxPresenter presenter = new RxPresenter();
Subscription mock = Mockito.mock(Subscription.class);
when(mock.isUnsubscribed()).thenReturn(false);
presenter.add(mock);
presenter.remove(mock);
verify(mock, atLeastOnce()).isUnsubscribed();
verify(mock, times(1)).unsubscribe();
presenter.onDestroy();
verifyNoMoreInteractions(mock);
}
代码示例来源:origin: ivacf/archi
recyclerViewVisibility.set(View.INVISIBLE);
infoMessageVisibility.set(View.INVISIBLE);
if (subscription != null && !subscription.isUnsubscribed()) subscription.unsubscribe();
ArchiApplication application = ArchiApplication.get(context);
GithubService githubService = application.getGithubService();
代码示例来源:origin: konmik/nucleus
@Test
public void testCompletedRestartable() throws Exception {
Func0<Subscription> restartable = mock(Func0.class);
Subscription subscription = mock(Subscription.class);
RxPresenter presenter = new RxPresenter();
presenter.create(null);
when(restartable.call()).thenReturn(subscription);
when(subscription.isUnsubscribed()).thenReturn(true);
presenter.restartable(1, restartable);
verifyNoMoreInteractions(restartable);
presenter.start(1);
}
代码示例来源:origin: konmik/nucleus
@Test
public void testRestartableIsUnsubscribed() throws Exception {
RxPresenter presenter = new RxPresenter();
presenter.create(null);
Func0<Subscription> restartable = mock(Func0.class);
Subscription subscription = mock(Subscription.class);
when(restartable.call()).thenReturn(subscription);
when(subscription.isUnsubscribed()).thenReturn(false);
presenter.restartable(1, restartable);
assertTrue(presenter.isUnsubscribed(1));
}
代码示例来源:origin: konmik/nucleus
@Test
public void testCompletedRestartableIsUnsubscribed() throws Exception {
RxPresenter presenter = new RxPresenter();
presenter.create(null);
Func0<Subscription> restartable = mock(Func0.class);
Subscription subscription = mock(Subscription.class);
when(restartable.call()).thenReturn(subscription);
when(subscription.isUnsubscribed()).thenReturn(true);
presenter.restartable(1, restartable);
assertTrue(presenter.isUnsubscribed(1));
presenter.start(1);
assertTrue(presenter.isUnsubscribed(1));
}
代码示例来源:origin: konmik/nucleus
@Test
public void testStartedRestartableIsNotUnsubscribed() throws Exception {
RxPresenter presenter = new RxPresenter();
presenter.create(null);
Func0<Subscription> restartable = mock(Func0.class);
Subscription subscription = mock(Subscription.class);
when(restartable.call()).thenReturn(subscription);
when(subscription.isUnsubscribed()).thenReturn(false);
presenter.restartable(1, restartable);
assertTrue(presenter.isUnsubscribed(1));
presenter.start(1);
assertFalse(presenter.isUnsubscribed(1));
}
代码示例来源:origin: ReactiveX/RxNetty
@Test(timeout = 60000)
public void testRemoveNonDelayedTasks() throws Exception {
RxJavaEventloopScheduler scheduler = new RxJavaEventloopScheduler(new NioEventLoopGroup());
final EventloopWorker worker = (EventloopWorker) scheduler.createWorker();
final EventloopWorker worker2 = (EventloopWorker) scheduler.createWorker();
assertThat("New worker already has subscriptions.", worker.hasScheduledSubscriptions(), is(false));
final AtomicBoolean isScheduledBeforeExecute = new AtomicBoolean();
final CountDownLatch executed = new CountDownLatch(1);
Subscription subscription = worker.schedule(new Action0() {
@Override
public void call() {
isScheduledBeforeExecute.set(worker.hasScheduledSubscriptions());
worker2.schedule(new Action0() {
@Override
public void call() {
executed.countDown();
}
});
}
});
executed.await();
assertThat("No scheduled subscriptions on executing the action.", isScheduledBeforeExecute.get(), is(true));
assertThat("Action not unsubscribed.", subscription.isUnsubscribed(), is(true));
assertThat("Subscription not removed post execution.", worker.hasScheduledSubscriptions(), is(false));
}
代码示例来源:origin: ReactiveX/RxNetty
@Test(timeout = 60000)
public void testRemoveDelayedTasks() throws Exception {
RxJavaEventloopScheduler scheduler = new RxJavaEventloopScheduler(new NioEventLoopGroup());
final EventloopWorker worker = (EventloopWorker) scheduler.createWorker();
final EventloopWorker worker2 = (EventloopWorker) scheduler.createWorker();
assertThat("New worker already has subscriptions.", worker.hasDelayScheduledSubscriptions(), is(false));
final AtomicBoolean isScheduledBeforeExecute = new AtomicBoolean();
final CountDownLatch executed = new CountDownLatch(1);
Subscription subscription = worker.schedule(new Action0() {
@Override
public void call() {
isScheduledBeforeExecute.set(worker.hasDelayScheduledSubscriptions());
worker2.schedule(new Action0() {
@Override
public void call() {
executed.countDown();
}
});
}
}, 1, TimeUnit.MILLISECONDS);
executed.await();
assertThat("No scheduled subscriptions on executing the action.", isScheduledBeforeExecute.get(), is(true));
assertThat("Action not unsubscribed.", subscription.isUnsubscribed(), is(true));
assertThat("Subscription not removed post execution.", worker.hasDelayScheduledSubscriptions(), is(false));
}
代码示例来源:origin: apache/usergrid
@Test
@Category(ExperimentalTest.class )
public void testPublish() throws InterruptedException {
final int count = 10;
final CountDownLatch latch = new CountDownLatch( count+1 );
final Subscription connectedObservable =
Observable.range( 0, count )
.doOnNext( integer -> latch.countDown() )
.doOnCompleted( () -> latch.countDown() ).subscribeOn( Schedulers.io() )
.subscribe();
final boolean completed = latch.await( 3, TimeUnit.SECONDS );
assertTrue( "publish1 behaves as expected", completed );
final boolean completedSubscription = connectedObservable.isUnsubscribed();
assertTrue( "Subscription complete", completedSubscription );
}
代码示例来源:origin: konmik/nucleus
@Test
public void testCompletedRestartableDoesNoRestart() throws Exception {
RxPresenter presenter = new RxPresenter();
presenter.onCreate(null);
Func0<Subscription> restartable = mock(Func0.class);
Subscription subscription = mock(Subscription.class);
when(restartable.call()).thenReturn(subscription);
when(subscription.isUnsubscribed()).thenReturn(false);
presenter.restartable(1, restartable);
verifyNoMoreInteractions(restartable);
presenter.start(1);
verify(restartable, times(1)).call();
verifyNoMoreInteractions(restartable);
when(subscription.isUnsubscribed()).thenReturn(true);
Bundle bundle = BundleMock.mock();
presenter.onSave(bundle);
presenter = new RxPresenter();
presenter.onCreate(bundle);
presenter.restartable(1, restartable);
verifyNoMoreInteractions(restartable);
}
代码示例来源:origin: konmik/nucleus
@Test
public void testRestartable() throws Exception {
RxPresenter presenter = new RxPresenter();
presenter.create(null);
Func0<Subscription> restartable = mock(Func0.class);
Subscription subscription = mock(Subscription.class);
when(restartable.call()).thenReturn(subscription);
when(subscription.isUnsubscribed()).thenReturn(false);
presenter.restartable(1, restartable);
verifyNoMoreInteractions(restartable);
presenter.start(1);
verify(restartable, times(1)).call();
verifyNoMoreInteractions(restartable);
Bundle bundle = BundleMock.mock();
presenter.onSave(bundle);
presenter = new RxPresenter();
presenter.create(bundle);
presenter.restartable(1, restartable);
verify(restartable, times(2)).call();
verifyNoMoreInteractions(restartable);
}
代码示例来源:origin: konmik/nucleus
@Test
public void testStopRestartable() throws Exception {
RxPresenter presenter = new RxPresenter();
presenter.onCreate(null);
Func0<Subscription> restartable = mock(Func0.class);
Subscription subscription = mock(Subscription.class);
when(restartable.call()).thenReturn(subscription);
when(subscription.isUnsubscribed()).thenReturn(false);
presenter.restartable(1, restartable);
verifyNoMoreInteractions(restartable);
presenter.start(1);
verify(restartable, times(1)).call();
verifyNoMoreInteractions(restartable);
presenter.stop(1);
Bundle bundle = BundleMock.mock();
presenter.onSave(bundle);
presenter = new RxPresenter();
presenter.onCreate(bundle);
presenter.restartable(1, restartable);
verify(restartable, times(1)).call();
verifyNoMoreInteractions(restartable);
}
代码示例来源:origin: ReactiveX/RxNetty
@Test(timeout = 60000)
public void testDispose() throws Exception {
ListenerWithSub l = holderRule.addAListener();
holderRule.getHolder().dispose();
assertThat("On complete not called on dispose.", l.listener.getOnCompletedCount(), is(1));
assertThat("Listener not unsubscribed on dispose.", l.subscription.isUnsubscribed(), is(true));
assertThat("Listener not removed on dispose.", holderRule.getHolder().getAllListeners(),
not(contains(l.listener)));
}
代码示例来源:origin: ReactiveX/RxNetty
@Test(timeout = 60000)
public void testDisposeWithExceptions() throws Exception {
final MockEventListener listener1 = new MockEventListener(true);
final MockEventListener listener2 = new MockEventListener();
Subscription subscription1 = holderRule.getHolder().subscribe(listener1);
Subscription subscription2 = holderRule.getHolder().subscribe(listener2);
assertThat("Listeners not added.", holderRule.getHolder().getAllListeners(), hasSize(2));
assertThat("Listeners not added.", holderRule.getHolder().getAllListeners(), contains(listener1, listener2));
try {
holderRule.getHolder().dispose();
throw new AssertionError("Error not thrown on dispose.");
} catch (Exception e) {
// Expected.
}
assertThat("First listener not completed.", listener1.getOnCompletedCount(), is(1));
assertThat("Second listener not completed.", listener2.getOnCompletedCount(), is(1));
assertThat("First listener not unsubscribed.", subscription1.isUnsubscribed(), is(true));
assertThat("Second listener not unsubscribed.", subscription2.isUnsubscribed(), is(true));
assertThat("Listeners not removed post dispose.", holderRule.getHolder().getAllListeners(), is(empty()));
}
内容来源于网络,如有侵权,请联系作者删除!