169 |
|
} |
170 |
|
|
171 |
|
/** |
172 |
< |
* A null Executor argument to SubmissionPublisher constructor throws NPE |
172 |
> |
* A null Executor argument to SubmissionPublisher constructor |
173 |
> |
* throws NullPointerException |
174 |
|
*/ |
175 |
|
public void testConstructor3() { |
176 |
|
try { |
181 |
|
|
182 |
|
/** |
183 |
|
* A negative capacity argument to SubmissionPublisher constructor |
184 |
< |
* throws IAE |
184 |
> |
* throws IllegalArgumentException |
185 |
|
*/ |
186 |
|
public void testConstructor4() { |
187 |
|
Executor e = Executors.newFixedThreadPool(1); |
193 |
|
|
194 |
|
/** |
195 |
|
* A closed publisher reports isClosed with no closedException and |
196 |
< |
* throws ISE upon attempted submission; a subsequent close or |
197 |
< |
* closeExceptionally has no additional effect. |
196 |
> |
* throws IllegalStateException upon attempted submission; a |
197 |
> |
* subsequent close or closeExceptionally has no additional |
198 |
> |
* effect. |
199 |
|
*/ |
200 |
|
public void testClose() { |
201 |
|
SubmissionPublisher<Integer> p = basicPublisher(); |
215 |
|
|
216 |
|
/** |
217 |
|
* A publisher closedExceptionally reports isClosed with the |
218 |
< |
* closedException and throws ISE upon attempted submission; a |
219 |
< |
* subsequent close or closeExceptionally has no additional |
220 |
< |
* effect. |
218 |
> |
* closedException and throws IllegalStateException upon attempted |
219 |
> |
* submission; a subsequent close or closeExceptionally has no |
220 |
> |
* additional effect. |
221 |
|
*/ |
222 |
|
public void testCloseExceptionally() { |
223 |
|
SubmissionPublisher<Integer> p = basicPublisher(); |
402 |
|
* Cancelling a subscription eventually causes no more onNexts to be issued |
403 |
|
*/ |
404 |
|
public void testCancel() { |
405 |
< |
SubmissionPublisher<Integer> p = basicPublisher(); |
405 |
> |
SubmissionPublisher<Integer> p = |
406 |
> |
new SubmissionPublisher<Integer>(basicExecutor, 4); // must be < 20 |
407 |
|
TestSubscriber s1 = new TestSubscriber(); |
408 |
|
TestSubscriber s2 = new TestSubscriber(); |
409 |
|
p.subscribe(s1); |
495 |
|
s1.request = false; |
496 |
|
p.subscribe(s1); |
497 |
|
s1.awaitSubscribe(); |
498 |
< |
assertTrue(p.estimateMinimumDemand() == 0); |
498 |
> |
assertEquals(0, p.estimateMinimumDemand()); |
499 |
|
TestSubscriber s2 = new TestSubscriber(); |
500 |
|
p.subscribe(s2); |
501 |
|
p.submit(1); |
536 |
|
} |
537 |
|
|
538 |
|
/** |
539 |
< |
* Negative request causes error |
539 |
> |
* Non-positive request causes error |
540 |
|
*/ |
541 |
|
public void testRequest3() { |
542 |
|
SubmissionPublisher<Integer> p = basicPublisher(); |
543 |
|
TestSubscriber s1 = new TestSubscriber(); |
544 |
|
TestSubscriber s2 = new TestSubscriber(); |
545 |
+ |
TestSubscriber s3 = new TestSubscriber(); |
546 |
|
p.subscribe(s1); |
547 |
|
p.subscribe(s2); |
548 |
+ |
p.subscribe(s3); |
549 |
+ |
s3.awaitSubscribe(); |
550 |
|
s2.awaitSubscribe(); |
551 |
|
s1.awaitSubscribe(); |
552 |
|
s1.sn.request(-1L); |
553 |
+ |
s3.sn.request(0L); |
554 |
|
p.submit(1); |
555 |
|
p.submit(2); |
556 |
|
p.close(); |
560 |
|
s1.awaitError(); |
561 |
|
assertEquals(1, s1.errors); |
562 |
|
assertTrue(s1.lastError instanceof IllegalArgumentException); |
563 |
+ |
s3.awaitError(); |
564 |
+ |
assertEquals(1, s3.errors); |
565 |
+ |
assertTrue(s3.lastError instanceof IllegalArgumentException); |
566 |
|
} |
567 |
|
|
568 |
|
/** |
569 |
|
* estimateMinimumDemand reports 0 until request, nonzero after |
570 |
< |
* request, and zero again after delivery |
570 |
> |
* request |
571 |
|
*/ |
572 |
|
public void testEstimateMinimumDemand() { |
573 |
|
TestSubscriber s = new TestSubscriber(); |
578 |
|
assertEquals(0, p.estimateMinimumDemand()); |
579 |
|
s.sn.request(1); |
580 |
|
assertEquals(1, p.estimateMinimumDemand()); |
571 |
– |
p.submit(1); |
572 |
– |
s.awaitNext(1); |
573 |
– |
assertEquals(0, p.estimateMinimumDemand()); |
581 |
|
} |
582 |
|
|
583 |
|
/** |
640 |
|
p.subscribe(s1); |
641 |
|
p.subscribe(s2); |
642 |
|
for (int i = 1; i <= 20; ++i) { |
636 |
– |
assertTrue(p.estimateMinimumDemand() <= 1); |
643 |
|
assertTrue(p.submit(i) >= 0); |
644 |
|
} |
645 |
|
p.close(); |