@@ -66,7 +66,7 @@ Explanations:
66
66
@Test public void optional_spec104_mustSignalOnErrorWhenFails() throws Throwable
67
67
```
68
68
69
- ... means that this test case is optional, it covers a * MAY* or * SHOULD* Rule of the Specification. This prefix is also used if more configuration is needed in order to run it, e.g. ` @Additional(implement = "createErrorStatePublisher") @Test ` signals the implementer that in order to include this test case in his test runs, (s)he must implement the ` Publisher<T> createErrorStatePublisher() ` method.
69
+ ... means that this test case is optional, it covers a * MAY* or * SHOULD* Rule of the Specification.
70
70
71
71
``` java
72
72
@Test public void stochastic_spec103_mustSignalOnMethodsSequentially() throws Throwable
@@ -116,6 +116,27 @@ In order to inform the TCK that your Publiher is not able to signal completion,
116
116
}
117
117
```
118
118
119
+ ### Testing a "failed" Publisher
120
+ The Reactive Streams spec mandates certain behaviours for Publishers which are "failed",
121
+ e.g. it was unable to initialize a connection it needs to emit elements.
122
+ It may be useful to specifically such known to be failed Publisher using the TCK.
123
+
124
+ In order to run additional tests on your failed publisher you can implement the ` createFailedPublisher ` method.
125
+ The expected behaviour from the returned implementation is to follow Rule 1.4 and Rule 1.9 - which are concerned
126
+ with the order of emiting the Subscription and signaling the failure.
127
+
128
+ ``` java
129
+ @Override public Publisher<T > createFailedPublisher() {
130
+ final String invalidData = " this input string is known it to be failed" ;
131
+ return new MyPublisher (invalidData);
132
+ }
133
+ ```
134
+
135
+ In case you don't really have a known up-front error state you can put your Publisher into,
136
+ you can easily ignore these tests by returning ` null ` from the ` createFailedPublisher ` method.
137
+ It is important to remember that it is ** illegal** to signal ` onNext / onComplete / onError ` before
138
+ you signal the ` Subscription ` , for details on this rule refer to the Reactive Streams specification.
139
+
119
140
## Publisher Verification
120
141
121
142
` PublisherVerification ` tests verify Publisher as well as some Subscription Rules of the Specification.
@@ -142,7 +163,7 @@ public class RangePublisherTest extends PublisherVerification<Integer> {
142
163
}
143
164
144
165
@Override
145
- public Publisher<Integer > createErrorStatePublisher () {
166
+ public Publisher<Integer > createFailedPublisher () {
146
167
return new Publisher<Integer > () {
147
168
@Override
148
169
public void subscribe (Subscriber<Integer > s ) {
@@ -427,8 +448,7 @@ public class MyIdentityProcessorVerificationTest extends IdentityProcessorVerifi
427
448
// ENABLE ADDITIONAL TESTS
428
449
429
450
@Override
430
- public Publisher<Integer > createErrorStatePublisher () {
431
- // return error state Publisher instead of null to run additional tests
451
+ public Publisher<Integer > createFailedPublisher () {
432
452
return null ;
433
453
}
434
454
@@ -504,7 +524,7 @@ class IterablePublisherTest(env: TestEnvironment, publisherShutdownTimeout: Long
504
524
def createPublisher (elements : Long ): Publisher [Int ] = ???
505
525
506
526
// example error state publisher implementation
507
- override def createErrorStatePublisher (): Publisher [Int ] =
527
+ override def createFailedPublisher (): Publisher [Int ] =
508
528
new Publisher [Int ] {
509
529
override def subscribe (s : Subscriber [Int ]): Unit = {
510
530
s.onError(new Exception (" Unable to serve subscribers right now!" ))
0 commit comments