forked from reactive-streams/reactive-streams-jvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyncTriggeredDemandSubscriberTest.java
58 lines (48 loc) · 2.22 KB
/
SyncTriggeredDemandSubscriberTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/************************************************************************
* Licensed under Public Domain (CC0) *
* *
* To the extent possible under law, the person who associated CC0 with *
* this code has waived all copyright and related or neighboring *
* rights to this code. *
* *
* You should have received a copy of the CC0 legalcode along with this *
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.*
************************************************************************/
package org.reactivestreams.tck.flow;
import org.reactivestreams.tck.TestEnvironment;
import org.reactivestreams.tck.flow.FlowSubscriberBlackboxVerification;
import org.reactivestreams.tck.flow.support.SyncTriggeredDemandFlowSubscriber;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Flow;
@Test // Must be here for TestNG to find and run this, do not remove
public class SyncTriggeredDemandSubscriberTest extends FlowSubscriberBlackboxVerification<Integer> {
private ExecutorService e;
@BeforeClass void before() { e = Executors.newFixedThreadPool(4); }
@AfterClass void after() { if (e != null) e.shutdown(); }
public SyncTriggeredDemandSubscriberTest() {
super(new TestEnvironment());
}
@Test(enabled = false)
@Override
public void triggerFlowRequest(Flow.Subscriber<? super Integer> subscriber) {
((SyncTriggeredDemandFlowSubscriber<? super Integer>) subscriber).triggerDemand(1);
}
@Override public Flow.Subscriber<Integer> createFlowSubscriber() {
return new SyncTriggeredDemandFlowSubscriber<Integer>() {
private long acc;
@Override protected long foreach(final Integer element) {
acc += element;
return 1;
}
@Override public void onComplete() {
}
};
}
@Override public Integer createElement(int element) {
return element;
}
}