forked from reactive-streams/reactive-streams-jvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+tck reactive-streams#236 example subscriber whitebox tested, and whi…
…tebox fixed
- Loading branch information
Showing
6 changed files
with
163 additions
and
90 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
examples/src/test/java/org/reactivestreams/example/unicast/SyncSubscriberWhiteboxTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.reactivestreams.example.unicast; | ||
|
||
import org.reactivestreams.Subscriber; | ||
import org.reactivestreams.Subscription; | ||
import org.reactivestreams.tck.SubscriberBlackboxVerification; | ||
import org.reactivestreams.tck.SubscriberWhiteboxVerification; | ||
import org.reactivestreams.tck.TestEnvironment; | ||
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; | ||
|
||
@Test // Must be here for TestNG to find and run this, do not remove | ||
public class SyncSubscriberWhiteboxTest extends SubscriberWhiteboxVerification<Integer> { | ||
|
||
private ExecutorService e; | ||
@BeforeClass void before() { e = Executors.newFixedThreadPool(4); } | ||
@AfterClass void after() { if (e != null) e.shutdown(); } | ||
|
||
public SyncSubscriberWhiteboxTest() { | ||
super(new TestEnvironment()); | ||
} | ||
|
||
@Override | ||
public Subscriber<Integer> createSubscriber(final WhiteboxSubscriberProbe<Integer> probe) { | ||
return new SyncSubscriber<Integer>() { | ||
@Override | ||
public void onSubscribe(final Subscription s) { | ||
super.onSubscribe(s); | ||
|
||
probe.registerOnSubscribe(new SubscriberPuppet() { | ||
@Override | ||
public void triggerRequest(long elements) { | ||
s.request(elements); | ||
} | ||
|
||
@Override | ||
public void signalCancel() { | ||
s.cancel(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onNext(Integer element) { | ||
super.onNext(element); | ||
probe.registerOnNext(element); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable cause) { | ||
super.onError(cause); | ||
probe.registerOnError(cause); | ||
} | ||
|
||
@Override | ||
public void onComplete() { | ||
super.onComplete(); | ||
probe.registerOnComplete(); | ||
} | ||
|
||
@Override | ||
protected boolean foreach(Integer element) { | ||
return true; | ||
} | ||
}; | ||
} | ||
|
||
@Override public Integer createElement(int element) { | ||
return element; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters