|
19 | 19 |
|
20 | 20 | import java.util.*;
|
21 | 21 | import java.util.concurrent.*;
|
| 22 | +import java.util.concurrent.atomic.AtomicInteger; |
22 | 23 |
|
23 | 24 | import org.junit.*;
|
24 | 25 | import org.mockito.*;
|
@@ -1439,4 +1440,64 @@ public void run() {
|
1439 | 1440 | assertEquals("Round: " + i, 5, items);
|
1440 | 1441 | }
|
1441 | 1442 | }
|
| 1443 | + |
| 1444 | + @SuppressWarnings("unchecked") |
| 1445 | + @Test |
| 1446 | + public void noCompletionCancelExact() { |
| 1447 | + final AtomicInteger counter = new AtomicInteger(); |
| 1448 | + |
| 1449 | + Observable.<Integer>empty() |
| 1450 | + .doOnDispose(new Action() { |
| 1451 | + @Override |
| 1452 | + public void run() throws Exception { |
| 1453 | + counter.getAndIncrement(); |
| 1454 | + } |
| 1455 | + }) |
| 1456 | + .buffer(5, TimeUnit.SECONDS) |
| 1457 | + .test() |
| 1458 | + .awaitDone(5, TimeUnit.SECONDS) |
| 1459 | + .assertResult(Collections.<Integer>emptyList()); |
| 1460 | + |
| 1461 | + assertEquals(0, counter.get()); |
| 1462 | + } |
| 1463 | + |
| 1464 | + @SuppressWarnings("unchecked") |
| 1465 | + @Test |
| 1466 | + public void noCompletionCancelSkip() { |
| 1467 | + final AtomicInteger counter = new AtomicInteger(); |
| 1468 | + |
| 1469 | + Observable.<Integer>empty() |
| 1470 | + .doOnDispose(new Action() { |
| 1471 | + @Override |
| 1472 | + public void run() throws Exception { |
| 1473 | + counter.getAndIncrement(); |
| 1474 | + } |
| 1475 | + }) |
| 1476 | + .buffer(5, 10, TimeUnit.SECONDS) |
| 1477 | + .test() |
| 1478 | + .awaitDone(5, TimeUnit.SECONDS) |
| 1479 | + .assertResult(Collections.<Integer>emptyList()); |
| 1480 | + |
| 1481 | + assertEquals(0, counter.get()); |
| 1482 | + } |
| 1483 | + |
| 1484 | + @SuppressWarnings("unchecked") |
| 1485 | + @Test |
| 1486 | + public void noCompletionCancelOverlap() { |
| 1487 | + final AtomicInteger counter = new AtomicInteger(); |
| 1488 | + |
| 1489 | + Observable.<Integer>empty() |
| 1490 | + .doOnDispose(new Action() { |
| 1491 | + @Override |
| 1492 | + public void run() throws Exception { |
| 1493 | + counter.getAndIncrement(); |
| 1494 | + } |
| 1495 | + }) |
| 1496 | + .buffer(10, 5, TimeUnit.SECONDS) |
| 1497 | + .test() |
| 1498 | + .awaitDone(5, TimeUnit.SECONDS) |
| 1499 | + .assertResult(Collections.<Integer>emptyList()); |
| 1500 | + |
| 1501 | + assertEquals(0, counter.get()); |
| 1502 | + } |
1442 | 1503 | }
|
0 commit comments