|
15 | 15 | */ |
16 | 16 | package rx.internal.operators; |
17 | 17 |
|
18 | | -import static org.junit.Assert.assertEquals; |
19 | | -import static org.junit.Assert.assertTrue; |
20 | | -import static org.junit.Assert.fail; |
| 18 | +import static org.junit.Assert.*; |
21 | 19 | import static org.mockito.Matchers.any; |
22 | 20 | import static org.mockito.Matchers.anyString; |
23 | 21 | import static org.mockito.Mockito.inOrder; |
|
28 | 26 | import static org.mockito.Mockito.verifyNoMoreInteractions; |
29 | 27 |
|
30 | 28 | import java.util.Arrays; |
| 29 | +import java.util.concurrent.CountDownLatch; |
31 | 30 | import java.util.concurrent.atomic.AtomicBoolean; |
32 | 31 | import java.util.concurrent.atomic.AtomicInteger; |
33 | 32 | import java.util.concurrent.atomic.AtomicLong; |
| 33 | +import java.util.concurrent.atomic.AtomicReference; |
34 | 34 |
|
35 | 35 | import org.junit.Test; |
36 | 36 | import org.mockito.InOrder; |
|
43 | 43 | import rx.Subscription; |
44 | 44 | import rx.functions.Action1; |
45 | 45 | import rx.functions.Func1; |
46 | | -import rx.internal.operators.OperatorTake; |
47 | 46 | import rx.observers.Subscribers; |
48 | 47 | import rx.observers.TestSubscriber; |
49 | 48 | import rx.schedulers.Schedulers; |
@@ -365,4 +364,28 @@ public void request(long n) { |
365 | 364 | }).take(1).subscribe(ts); |
366 | 365 | assertEquals(1, requested.get()); |
367 | 366 | } |
| 367 | + |
| 368 | + @Test |
| 369 | + public void testInterrupt() throws InterruptedException { |
| 370 | + final AtomicReference<Object> exception = new AtomicReference<Object>(); |
| 371 | + final CountDownLatch latch = new CountDownLatch(1); |
| 372 | + Observable.just(1).subscribeOn(Schedulers.computation()).take(1).subscribe(new Action1<Integer>() { |
| 373 | + |
| 374 | + @Override |
| 375 | + public void call(Integer t1) { |
| 376 | + try { |
| 377 | + Thread.sleep(100); |
| 378 | + } catch (Exception e) { |
| 379 | + exception.set(e); |
| 380 | + e.printStackTrace(); |
| 381 | + } finally { |
| 382 | + latch.countDown(); |
| 383 | + } |
| 384 | + } |
| 385 | + |
| 386 | + }); |
| 387 | + |
| 388 | + latch.await(); |
| 389 | + assertNull(exception.get()); |
| 390 | + } |
368 | 391 | } |
0 commit comments