Skip to content

Commit 5fa310d

Browse files
committed
Merge pull request #246 from ktoso/wip-readme-fixups-ktoso
=tck general tck/readme.md cleanup so it matches current code / spec
2 parents 2fe7c48 + 929a891 commit 5fa310d

File tree

2 files changed

+83
-30
lines changed

2 files changed

+83
-30
lines changed

tck/README.md

Lines changed: 80 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ The TCK is implemented using **plain Java (1.6)** and **TestNG** tests, and shou
1010
The TCK aims to cover all rules defined in the Specification, however for some rules outlined in the Specification it is
1111
not possible (or viable) to construct automated tests, thus the TCK does not claim to completely verify an implementation, however it is very helpful and is able to validate the most important rules.
1212

13-
The TCK is split up into 4 files JUnit 4 test classes which should be extended by implementers, providing their `Publisher` / `Subscriber` implementations for the test harness to validate them. The tests are split in the following way:
13+
The TCK is split up into 4 TestNG test classes which should be extended by implementers, providing their `Publisher` / `Subscriber` implementations for the test harness to validate them. The tests are split in the following way:
1414

1515
* `PublisherVerification`
16-
* `SubscriberBlackboxVerification`
1716
* `SubscriberWhiteboxVerification`
17+
* `SubscriberBlackboxVerification`
1818
* `IdentityProcessorVerification`
1919

2020
The next sections include examples on how these can be used and describe the various configuration options.
@@ -32,53 +32,63 @@ The TCK is provided as binary artifact on [Maven Central](http://search.maven.or
3232

3333
Please refer to the [Reactive Streams Specification](https://github.com/reactive-streams/reactive-streams-jvm) for the current latest version number. Make sure that the API and TCK dependency versions are equal.
3434

35-
### Types of tests
35+
### Test method naming convention
3636

3737
Since the TCK is aimed at Reactive Stream implementers, looking into the sources of the TCK is well expected,
3838
and should help during a libraries implementation cycle.
3939

4040
In order to make mapping between test cases and Specification rules easier, each test case covering a specific
41-
Specification rule abides the following naming convention: `spec###_DESC` where:
41+
Specification rule abides the following naming convention: `TYPE_spec###_DESC` where:
4242

43+
* `TYPE` is one of: [#type-required](required), [#type-optional](optional), [#type-stochastic](stochastic) or [#type-untested](untested) which describe if this test is covering a Rule that MUST or SHOULD be implemented. The specific words are explained in detail below.
4344
* `###` is the Rule number (`1.xx` Rules are about Publishers, `2.xx` Rules are about Subscribers etc.)
4445
* `DESC` is a short explanation of what exactly is being tested in this test case, as sometimes one Rule may have multiple test cases in order to cover the entire Rule.
4546

47+
Here is an example test method signature:
48+
4649
```java
4750
// Verifies rule: https://github.com/reactive-streams/reactive-streams-jvm#1.1
48-
@Test public void required_spec101_subscriptionRequestMustResultInTheCorrectNumberOfProducedElements() throws Throwable
51+
@Test public void required_spec101_subscriptionRequestMustResultInTheCorrectNumberOfProducedElements() throws Throwable {
4952
// ...
5053
}
5154
```
5255

53-
The prefixes of the names of the test methods are used in order to signify the character of the test. For example, these are the kinds of prefixes you may find:
54-
"`required_`", "`optional_`", "`stochastic_`", "`untested_`".
55-
56-
Explanations:
56+
#### Test types explained:
5757

5858
```java
5959
@Test public void required_spec101_subscriptionRequestMustResultInTheCorrectNumberOfProducedElements() throws Throwable
6060
```
6161

62-
... means that this test case is a hard requirement, it covers a *MUST* or *MUST NOT* Rule of the Specification.
62+
<a name="type-required"></a>
63+
The `required_` means that this test case is a hard requirement, it covers a *MUST* or *MUST NOT* Rule of the Specification.
6364

6465

6566
```java
6667
@Test public void optional_spec104_mustSignalOnErrorWhenFails() throws Throwable
6768
```
6869

69-
... means that this test case is optional, it covers a *MAY* or *SHOULD* Rule of the Specification.
70+
<a name="type-optional"></a>
71+
The `optional_` means that this test case is optional, it covers a *MAY* or *SHOULD* Rule of the Specification.
72+
This prefix is also used if more configuration is needed in order to run it, e.g.
73+
`@Additional(implement = "createFailedPublisher") @Test` signals the implementer that in order to run this test
74+
one has to implement the `Publisher<T> createFailedPublisher()` method.
7075

7176
```java
7277
@Test public void stochastic_spec103_mustSignalOnMethodsSequentially() throws Throwable
7378
```
7479

75-
... means that the Rule is either racy, and/or inherently hard to verify without heavy modification of the tested implementation. Usually this means that this test case can yield false positives ("be green") even if for some case, the given implementation may violate the tested behaviour.
80+
<a name="type-stochastic"></a>
81+
The `stochastic_` means that the Rule is either racy, and/or inherently hard to verify without heavy modification of the tested implementation.
82+
Usually this means that this test case can yield false positives ("be green") even if for some case, the given implementation may violate the tested behaviour.
7683

7784
```java
7885
@Test public void untested_spec106_mustConsiderSubscriptionCancelledAfterOnErrorOrOnCompleteHasBeenCalled() throws Throwable
7986
```
8087

81-
... means that the test case is not implemented, either because it is inherently hard to verify (e.g. Rules which use the wording "*SHOULD consider X as Y*") or have not been implemented yet (though we hope we have implemented all we could!). Such tests will show up in your test runs as `SKIPPED`, with a message pointing out that the TCK is unable to validate this Rule. We would be delighted if you can figure out a way to deterministically test Rules, which have been marked with this prefix – pull requests are very welcome!
88+
<a name="type-untested"></a>
89+
The `untested_` means that the test case is not implemented, either because it is inherently hard to verify (e.g. Rules which use
90+
the wording "*SHOULD consider X as Y*"). Such tests will show up in your test runs as `SKIPPED`, with a message pointing out that the TCK is unable to validate this Rule. If you figure out a way to deterministically test Rules which have been
91+
marked with this prefix – pull requests are encouraged!
8292

8393
### Test isolation
8494

@@ -188,9 +198,11 @@ public class RangePublisherTest extends PublisherVerification<Integer> {
188198

189199
Notable configuration options include:
190200

191-
* `maxElementsFromPublisher` – which should only be overridden in case the Publisher under test is not able to provide arbitrary length streams, e.g. it's wrapping a `Future<T>` and thus can only publish up to 1 element. In such case you should return `1` from this method. It will cause all tests which require more elements in order to validate a certain Rule to be skipped,
192-
* `boundedDepthOfOnNextAndRequestRecursion` – which should only be overridden in case of synchronous Publishers. This number will be used to validate if a
193-
`Subscription` actually solves the "unbounded recursion" problem (Rule 3.3).
201+
* `maxElementsFromPublisher` – must be overridden in case the Publisher being tested is of bounded length, e.g. it's wrapping a `Future<T>` and thus can only publish up to 1 element, in which case you
202+
would return `1` from this method. It will cause all tests which require more elements in order to validate a certain
203+
Rule to be skipped,
204+
* `boundedDepthOfOnNextAndRequestRecursion` – which must be overridden when verifying synchronous Publishers.
205+
This number returned by this method will be used to validate if a `Subscription` adheres to Rule 3.3 and avoids "unbounded recursion".
194206

195207
### Timeout configuration
196208
Publisher tests make use of two kinds of timeouts, one is the `defaultTimeoutMillis` which corresponds to all methods used
@@ -200,7 +212,7 @@ by the Publisher.
200212

201213
In order to configure these timeouts (for example when running on a slow continious integtation machine), you can either:
202214

203-
**Use env variables** to set these timeouts, in which case the you can just:
215+
**Use env variables** to set these timeouts, in which case the you can do:
204216

205217
```bash
206218
export DEFAULT_TIMEOUT_MILLIS=300
@@ -260,7 +272,7 @@ The `createElement` method MAY be called from multiple
260272
threads, so in case of more complicated implementations, please be aware of this fact.
261273

262274
**Very Advanced**: While we do not expect many implementations having to do so, it is possible to take full control of the `Publisher`
263-
which will be driving the TCKs test. You can do this by implementing the `createHelperPublisher` method in which you can implement your
275+
which will be driving the TCKs test. This can be achieved by implementing the `createHelperPublisher` method in which you can implement your
264276
own Publisher which will then be used by the TCK to drive your Subscriber tests:
265277

266278
```java
@@ -342,6 +354,7 @@ public class MySubscriberWhiteboxVerificationTest extends SubscriberWhiteboxVeri
342354
// register a successful subscription, and create a Puppet,
343355
// for the WhiteboxVerification to be able to drive its tests:
344356
probe.registerOnSubscribe(new SubscriberPuppet() {
357+
345358
@Override
346359
public void triggerRequest(long elements) {
347360
s.request(elements);
@@ -356,18 +369,21 @@ public class MySubscriberWhiteboxVerificationTest extends SubscriberWhiteboxVeri
356369

357370
@Override
358371
public void onNext(Integer element) {
372+
// in addition to normal Subscriber work that you're testing, register onNext with the probe
359373
super.onNext(element);
360374
probe.registerOnNext(element);
361375
}
362376

363377
@Override
364378
public void onError(Throwable cause) {
379+
// in addition to normal Subscriber work that you're testing, register onError with the probe
365380
super.onError(cause);
366381
probe.registerOnError(cause);
367382
}
368383

369384
@Override
370385
public void onComplete() {
386+
// in addition to normal Subscriber work that you're testing, register onComplete with the probe
371387
super.onComplete();
372388
probe.registerOnComplete();
373389
}
@@ -400,7 +416,7 @@ public class MySubscriberTest extends BlackboxSubscriberVerification<Integer> {
400416
public static final long DEFAULT_TIMEOUT_MILLIS = 300L;
401417

402418
public RangePublisherTest() {
403-
super(new MySubscriberTest(DEFAULT_TIMEOUT_MILLIS));
419+
super(new TestEnvironment(DEFAULT_TIMEOUT_MILLIS));
404420
}
405421

406422
// ...
@@ -453,10 +469,13 @@ public class MyIdentityProcessorVerificationTest extends IdentityProcessorVerifi
453469

454470
@Override
455471
public Publisher<Integer> createFailedPublisher() {
472+
// return Publisher that only signals onError instead of null to run additional tests
473+
// see this methods JavaDocs for more details on how the returned Publisher should work.
456474
return null;
457475
}
458476

459477
// OPTIONAL CONFIGURATION OVERRIDES
478+
// override these only if you understand why you'd need to do so for your impl.
460479

461480
@Override
462481
public long maxElementsFromPublisher() {
@@ -482,30 +501,63 @@ to skip tests inherited from the TCK's base classes:
482501
```java
483502
package com.example.streams;
484503

504+
import org.reactivestreams.Processor;
505+
import org.reactivestreams.Publisher;
506+
import org.reactivestreams.Subscriber;
507+
import org.reactivestreams.Subscription;
485508
import org.reactivestreams.tck.IdentityProcessorVerification;
509+
import org.reactivestreams.tck.TestEnvironment;
510+
import org.testng.annotations.AfterClass;
511+
import org.testng.annotations.BeforeClass;
512+
513+
import java.util.concurrent.ExecutorService;
514+
import java.util.concurrent.Executors;
515+
516+
public class MyIdentityProcessorTest extends IdentityProcessorVerification<Integer> {
517+
518+
private ExecutorService e;
486519

487-
public class SkippingIdentityProcessorTest extends IdentityProcessorVerification<Integer> {
520+
@BeforeClass
521+
public void before() { e = Executors.newFixedThreadPool(4); }
522+
523+
@AfterClass
524+
public void after() { if (e != null) e.shutdown(); }
488525

489526
public SkippingIdentityProcessorTest() {
490-
super(new TestEnvironment(500, true), 1000);
527+
super(new TestEnvironment());
528+
}
529+
530+
@Override
531+
public ExecutorService publisherExecutorService() {
532+
return e;
533+
}
534+
535+
@Override
536+
public Integer createElement(int element) {
537+
return element;
491538
}
492539

493540
@Override
494541
public Processor<Integer, Integer> createIdentityProcessor(int bufferSize) {
495-
return /* ... */;
542+
return new MyProcessor<Integer, Integer>(buffer Size); // return your implementation
496543
}
497544

498-
@Override // override the test method, and provide a reason on why you're doing so in the notVerified() message
499-
public void spec999_mustDoVeryCrazyThings() throws Throwable {
500-
notVerified("Unable to implement test because ...");
545+
@Override
546+
public Publisher<Integer> createFailedPublisher() {
547+
return null; // returning null means that the tests validating a failed publisher will be skipped
501548
}
502549

503550
}
504551
```
505552

506-
## Upgrade story
553+
## Upgrading the TCK to newer versions
554+
While we do not expect the Reactive Streams specification to change in the forseeable future,
555+
it *may happen* that some semantics may need to change at some point. In this case you should expect test
556+
methods being phased out in terms of deprecation or removal, new tests may also be added over time.
507557

508-
**TODO** - What is our story about updating the TCK? How do we make sure that implementations don't accidentally miss some change in the spec, if the TCK is unable to fail verify the new behavior? Comments are very welcome, discussion about this is under-way in [Issue #99 – TCK Upgrade Story](https://github.com/reactive-streams/reactive-streams-jvm/issues/99).
558+
In general this should not be of much concern, unless overriding test methods in your test suite.
559+
We ask implementers who find the need of overriding provided test methods to reach out via opening tickets
560+
on the `reactive-streams/reactive-streams-jvm` project, so we can discuss the use case and, most likely, improve the TCK.
509561

510562
## Using the TCK from other languages
511563

@@ -542,4 +594,4 @@ class IterablePublisherTest(env: TestEnvironment, publisherShutdownTimeout: Long
542594

543595
Contributions to this document are very welcome!
544596

545-
If you're implementing reactive streams using the TCK in some language, please feel free to share an example on how to best use it from your language of choice.
597+
When implementing Reactive Streams using the TCK in some language, please feel free to share an example on how to best use it from your language of choice.

tck/src/test/java/org/reactivestreams/tck/IdentityProcessorVerificationDelegationTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package org.reactivestreams.tck;
22

3-
import org.testng.AssertJUnit;
43
import org.testng.annotations.Test;
54

65
import java.lang.reflect.Method;
76
import java.util.ArrayList;
87
import java.util.List;
98

9+
import static org.testng.AssertJUnit.assertTrue;
10+
1011
/**
1112
* The {@link org.reactivestreams.tck.IdentityProcessorVerification} must also run all tests from
1213
* {@link org.reactivestreams.tck.PublisherVerification} and {@link org.reactivestreams.tck.SubscriberWhiteboxVerification}.
@@ -52,7 +53,7 @@ private void assertSuiteDelegatedAllTests(Class<?> delegatingFrom, List<String>
5253
delegatingFrom,
5354
targetTest, targetClass.getSimpleName(), targetTest);
5455

55-
AssertJUnit.assertTrue(msg, testsInclude(allTests, targetTest));
56+
assertTrue(msg, testsInclude(allTests, targetTest));
5657
}
5758
}
5859

0 commit comments

Comments
 (0)