Skip to content

Commit ab740f3

Browse files
committed
readme now up to date for jdk9
1 parent 0a71dae commit ab740f3

File tree

1 file changed

+34
-43
lines changed

1 file changed

+34
-43
lines changed

Diff for: tck-flow/README.md

+34-43
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ and help Reactive Streams library implementers to validate their implementations
55

66
Since this version of the TCK is intended to verify the interfaces contained in Java 9 (under `java.util.concurrent.Flow.*`), at least Java `9` is required to run this TCK. If you're looking for the previous TCK that was intended for Reactive Streams prior to their inclusion in the JDK please look at []
77

8-
The TCK is implemented using **plain Java (1.6)** and **TestNG** tests, and should be possible to use from other JVM-based languages and testing libraries.
9-
108
## Structure of the TCK
119

1210
The TCK aims to cover all rules defined in the Specification, however for some rules outlined in the Specification it is
@@ -138,7 +136,7 @@ The expected behaviour from the returned implementation is to follow Rule 1.4 an
138136
with the order of emiting the `Subscription` and signaling the failure.
139137

140138
```java
141-
@Override public Publisher<T> createFailedPublisher() {
139+
@Override public Flow.Publisher<T> createFailedPublisher() {
142140
final String invalidData = "this input string is known it to be failed";
143141
return new MyPublisher(invalidData);
144142
}
@@ -157,24 +155,24 @@ In order to include it's tests in your test suite simply extend it, like this:
157155
```java
158156
package com.example.streams;
159157

160-
import org.reactivestreams.Publisher;
161-
import org.reactivestreams.Subscriber;
162-
import org.reactivestreams.tck.FlowPublisherVerification;
158+
import org.reactivestreams.tck.flow.FlowPublisherVerification;
163159
import org.reactivestreams.tck.TestEnvironment;
164160

161+
import java.util.concurrent.Flow;
162+
165163
public class RangePublisherTest extends FlowPublisherVerification<Integer> {
166164

167165
public RangePublisherTest() {
168166
super(new TestEnvironment());
169167
}
170168

171169
@Override
172-
public Publisher<Integer> createPublisher(long elements) {
170+
public Flow.Publisher<Integer> createPublisher(long elements) {
173171
return new RangePublisher<Integer>(1, elements);
174172
}
175173

176174
@Override
177-
public Publisher<Integer> createFailedPublisher() {
175+
public Flow.Publisher<Integer> createFailedPublisher() {
178176
return new Publisher<Integer>() {
179177
@Override
180178
public void subscribe(Subscriber<Integer> s) {
@@ -187,7 +185,7 @@ public class RangePublisherTest extends FlowPublisherVerification<Integer> {
187185

188186
@Override
189187
public long maxElementsFromPublisher() {
190-
return Long.MAX_VALUE1;
188+
return Long.MAX_VALUE - 1;
191189
}
192190

193191
@Override
@@ -258,7 +256,7 @@ The helper `Publisher` is an asynchronous `Publisher` by default—meaning that
258256

259257
When extending `Subscriber` Verification classes a type parameter representing the element type passed through the stream must be given.
260258
Implementations are typically not sensitive to the type of element being signalled, but sometimes a `Subscriber` may be limited to only be able to work within a known set of types -
261-
like a `FileSubscriber extends Subscriber<ByteBuffer>` for example, that writes each element (ByteBuffer) it receives into a file.
259+
like a `FileSubscriber extends Flow.Subscriber<ByteBuffer>` for example, that writes each element (ByteBuffer) it receives into a file.
262260
For element type agnostic Subscribers the simplest way is to parameterize the tests using `Integer` and in the `createElement(int idx)` method (explained below in futher detail), return the incoming `int`.
263261
In case an implementation needs to work on a specific type, the verification class should be parameterized using that type (e.g. `class StringSubTest extends FlowSubscriberWhiteboxVerification<String>`) and the `createElement` method must be overriden to return a `String`.
264262

@@ -288,8 +286,8 @@ NOTE: The `createElement` method *MAY* be called *concurrently from multiple thr
288286
**Very advanced**: While it is not expected for many implementations having to do so, it is possible to take full control of the `Publisher` which will be driving the TCKs test. This can be achieved by implementing the `createHelperPublisher` method in which one can implement the `createHelperPublisher` method by returning a custom `Publisher` implementation which will then be used by the TCK to drive your `Subscriber` tests:
289287

290288
```java
291-
@Override public Publisher<Message> createHelperPublisher(long elements) {
292-
return new Publisher<Message>() { /* CUSTOM IMPL HERE WHICH OF COURSE ALSO SHOULD PASS THE TCK */ };
289+
@Override public Flow.Publisher<Message> createHelperPublisher(long elements) {
290+
return new Flow.Publisher<Message>() { /* CUSTOM IMPL HERE WHICH OF COURSE ALSO SHOULD PASS THE TCK */ };
293291
}
294292
```
295293

@@ -307,12 +305,11 @@ exteding (or delegating to) your implementation with additionally signalling and
307305
```java
308306
package com.example.streams;
309307

310-
import org.reactivestreams.Publisher;
311-
import org.reactivestreams.Subscriber;
312-
import org.reactivestreams.Subscription;
313-
import org.reactivestreams.tck.FlowSubscriberWhiteboxVerification;
308+
import org.reactivestreams.tck.flow.FlowSubscriberWhiteboxVerification;
314309
import org.reactivestreams.tck.TestEnvironment;
315310

311+
import java.util.concurrent.Flow;
312+
316313
public class MyFlowSubscriberWhiteboxVerificationTest extends FlowSubscriberWhiteboxVerification<Integer> {
317314

318315
public MyFlowSubscriberWhiteboxVerificationTest() {
@@ -323,12 +320,12 @@ public class MyFlowSubscriberWhiteboxVerificationTest extends FlowSubscriberWhit
323320
// class SyncSubscriber<T> extends Subscriber<T> { /* ... */ }
324321

325322
@Override
326-
public Subscriber<Integer> createSubscriber(final WhiteboxSubscriberProbe<Integer> probe) {
323+
public Flow.Subscriber<Integer> createSubscriber(final WhiteboxSubscriberProbe<Integer> probe) {
327324
// in order to test the SyncSubscriber we must instrument it by extending it,
328325
// and calling the WhiteboxSubscriberProbe in all of the Subscribers methods:
329326
return new SyncSubscriber<Integer>() {
330327
@Override
331-
public void onSubscribe(final Subscription s) {
328+
public void onSubscribe(final Flow.Subscription s) {
332329
super.onSubscribe(s);
333330

334331
// register a successful Subscription, and create a Puppet,
@@ -386,20 +383,19 @@ at the expense of not being able to verify as much as the `FlowSubscriberWhitebo
386383
```java
387384
package com.example.streams;
388385

389-
import org.reactivestreams.Publisher;
390-
import org.reactivestreams.Subscriber;
391-
import org.reactivestreams.Subscription;
392-
import org.reactivestreams.tck.FlowSubscriberBlackboxVerification;
386+
import org.reactivestreams.tck.flow.FlowSubscriberBlackboxVerification;
393387
import org.reactivestreams.tck.TestEnvironment;
394388

389+
import java.util.concurrent.Flow;
390+
395391
public class MyFlowSubscriberBlackboxVerificationTest extends FlowSubscriberBlackboxVerification<Integer> {
396392

397393
public MyFlowSubscriberBlackboxVerificationTest() {
398394
super(new TestEnvironment());
399395
}
400396

401397
@Override
402-
public Subscriber<Integer> createSubscriber() {
398+
public Flow.Subscriber<Integer> createSubscriber() {
403399
return new MySubscriber<Integer>();
404400
}
405401

@@ -451,14 +447,12 @@ An `IdentityFlowProcessorVerification` tests the given `Processor` for all `Subs
451447
```java
452448
package com.example.streams;
453449

454-
import org.reactivestreams.Processor;
455-
import org.reactivestreams.Publisher;
456-
import org.reactivestreams.Subscriber;
457-
import org.reactivestreams.Subscription;
458-
import org.reactivestreams.tck.IdentityFlowProcessorVerification;
459-
import org.reactivestreams.tck.FlowSubscriberWhiteboxVerification;
450+
import org.reactivestreams.tck.flow.IdentityFlowProcessorVerification;
451+
import org.reactivestreams.tck.flow.FlowSubscriberWhiteboxVerification;
460452
import org.reactivestreams.tck.TestEnvironment;
461453

454+
import java.util.concurrent.Flow;
455+
462456
public class MyIdentityFlowProcessorVerificationTest extends IdentityFlowProcessorVerification<Integer> {
463457

464458
public static final long DEFAULT_TIMEOUT_MILLIS = 300L;
@@ -470,19 +464,19 @@ public class MyIdentityFlowProcessorVerificationTest extends IdentityFlowProcess
470464
}
471465

472466
@Override
473-
public Processor<Integer, Integer> createIdentityProcessor(int bufferSize) {
467+
public Flow.Processor<Integer, Integer> createIdentityProcessor(int bufferSize) {
474468
return new MyIdentityProcessor<Integer, Integer>(bufferSize);
475469
}
476470

477471
@Override
478-
public Publisher<Integer> createHelperPublisher(long elements) {
472+
public Flow.Publisher<Integer> createHelperPublisher(long elements) {
479473
return new MyRangePublisher<Integer>(1, elements);
480474
}
481475

482476
// ENABLE ADDITIONAL TESTS
483477

484478
@Override
485-
public Publisher<Integer> createFailedPublisher() {
479+
public Flow.Publisher<Integer> createFailedPublisher() {
486480
// return Publisher that only signals onError instead of null to run additional tests
487481
// see this methods JavaDocs for more details on how the returned Publisher should work.
488482
return null;
@@ -517,15 +511,12 @@ cannot implement). Below is a recommended pattern to skip tests inherited from t
517511
```java
518512
package com.example.streams;
519513

520-
import org.reactivestreams.Processor;
521-
import org.reactivestreams.Publisher;
522-
import org.reactivestreams.Subscriber;
523-
import org.reactivestreams.Subscription;
524-
import org.reactivestreams.tck.IdentityFlowProcessorVerification;
514+
import org.reactivestreams.tck.flow.IdentityFlowProcessorVerification;
525515
import org.reactivestreams.tck.TestEnvironment;
526516
import org.testng.annotations.AfterClass;
527517
import org.testng.annotations.BeforeClass;
528518

519+
import java.util.concurrent.Flow;
529520
import java.util.concurrent.ExecutorService;
530521
import java.util.concurrent.Executors;
531522

@@ -554,12 +545,12 @@ public class MyIdentityProcessorTest extends IdentityFlowProcessorVerification<I
554545
}
555546

556547
@Override
557-
public Processor<Integer, Integer> createIdentityProcessor(int bufferSize) {
548+
public Flow.Processor<Integer, Integer> createIdentityProcessor(int bufferSize) {
558549
return new MyProcessor<Integer, Integer>(bufferSize); // return implementation to be tested
559550
}
560551

561552
@Override
562-
public Publisher<Integer> createFailedPublisher() {
553+
public Flow.Publisher<Integer> createFailedPublisher() {
563554
return null; // returning null means that the tests validating a failed publisher will be skipped
564555
}
565556

@@ -606,12 +597,12 @@ class IterablePublisherTest(env: TestEnvironment, publisherShutdownTimeout: Long
606597
this(new TestEnvironment(500), 1000)
607598
}
608599

609-
def createPublisher(elements: Long): Publisher[Int] = ???
600+
def createFlowPublisher(elements: Long): Flow.Publisher[Int] = ???
610601

611602
// example error state publisher implementation
612-
override def createFailedPublisher(): Publisher[Int] =
613-
new Publisher[Int] {
614-
override def subscribe(s: Subscriber[Int]): Unit =
603+
override def createFailedFlowPublisher(): Flow.Publisher[Int] =
604+
new Flow.Publisher[Int] {
605+
override def subscribe(s: Flow.Subscriber[Int]): Unit =
615606
s.onError(new Exception("Unable to serve subscribers right now!"))
616607
}
617608

0 commit comments

Comments
 (0)