You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
+tck 2.9 blackbox verification should fully drive publisher
It should not use the helper publisher as it may signal asynchronously
as well as onComplete in undefined ways - we need to control the
publisher in this case because of the very specific test scenario
Copy file name to clipboardExpand all lines: tck/README.md
+39-21
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,7 @@ Specification rule abides the following naming convention: `spec###_DESC` where:
51
51
```
52
52
53
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:
@@ -180,36 +180,44 @@ Subscriber rules Verification is split up into two files (styles) of tests.
180
180
181
181
The Blackbox Verification tests do not require the implementation under test to be modified at all, yet they are *not* able to verify most rules. In Whitebox Verification, more control over `request()` calls etc. is required in order to validate rules more precisely.
182
182
183
-
### Helper Publisher implementations
183
+
### createElement and Helper Publisher implementations
184
184
Since testing a `Subscriber` is not possible without a corresponding `Publisher` the TCK Subscriber Verifications
185
-
both provide a default "helper publisher" to drive its test and also alow to replace this Publisher with a custom implementation.
185
+
both provide a default "*helper publisher*" to drive its test and also alow to replace this Publisher with a custom implementation.
186
+
The helper publisher is an asynchronous publisher by default - meaning that your subscriber can not blindly assume single threaded execution.
186
187
187
-
For simple Subscribers which are able to consume elements of *any type*, it is **highly recommmended** to extend the
188
-
SubscriberVerification (described below) classes providing the element type `java.lang.Integer`, like so: `... extends SubscriberBlackboxVerification<Integer>`.
189
-
The reason for this is, that the TCK contains a default Publisher implementation which is able to signal `Integer` elements,
190
-
thus alowing the implementer to strictly focus on only implementing a proper `Subscriber`, instead of having to implement
191
-
an additional Publisher only in order to drive the Subscribers tests. This is especially important for library implementers
192
-
which only want to implement a Subscriber – and do not want to spend time or thought on implementing a valid Publisher.
188
+
While the `Publisher` implementation is provided, creating the signal elements is not – this is because a given Subscriber
189
+
may for example only work with `HashedMessage` or some other specific kind of signal. The TCK is unable to generate such
190
+
special messages automatically, so we provide the `T createElement(Integer id)` method to be implemented as part of
191
+
Subscriber Verifications which should take the given ID and return an element of type `T` (where `T` is the type of
192
+
elements flowing into the `Subscriber<T>`, as known thanks to `... extends WhiteboxSubscriberVerification<T>`) representing
193
+
an element of the stream that will be passed on to the Subscriber.
193
194
194
-
If however any SubscriberVerification class is extended using a custom element type, e.g. like this `... extends SubscriberBlackboxVerification<Message>`,
195
-
*the TCK will immediatly fail the entire subscriber test class* as it is unable to properly create signals of type `Message`
196
-
(which can be some custom message type the `Subscriber` is able to consume). The exception thrown (`UnableToProvidePublisherException`)
197
-
contains some information and directs the implementer towards implementing a custom helper publisher,
198
-
which is done by overriding the `Publisher<T> createHelperPublisher(long elements)` method:
195
+
The simplest valid implemenation is to return the incoming `id`*as the element* in a verification using `Integer`s as element types:
returnnewPublisher<Message>() { /* IMPL HERE */ };
203
218
}
204
219
```
205
220
206
-
Summing up, we recommend implementing Subscribers which are able to consume any type of element, in this case the TCK
207
-
should be driven using `Integer` elements as default publishers are already implemented for this type. If the
208
-
`Subscriber` is unable to consume `Integer` elements, the implementer MUST implement a custom `Publisher<T>` that will
209
-
be able to signal the required element types. It is of course both possible and recommended to re-use existing
210
-
implemenations (which can be seen in the examples sub-project) to create these custom Publishers – an example of
211
-
such re-use can be found in [ProvidedHelperPublisherForSubscriberVerificationTest#createStringPublisher](https://github.com/reactive-streams/reactive-streams/blob/master/tck/src/test/java/org/reactivestreams/tck/ProvidedHelperPublisherForSubscriberVerificationTest.java#L215)
212
-
213
221
### Subscriber Blackbox Verification
214
222
215
223
Blackbox Verification does not require any additional work except from providing a `Subscriber` and `Publisher` instances to the TCK:
@@ -235,6 +243,11 @@ public class MySubscriberBlackboxVerificationTest extends SubscriberBlackboxVeri
235
243
publicSubscriber<Integer>createSubscriber() {
236
244
returnnewMySubscriber<Integer>();
237
245
}
246
+
247
+
@Override
248
+
publicIntegercreateElement(intelement) {
249
+
return element;
250
+
}
238
251
}
239
252
```
240
253
@@ -310,6 +323,11 @@ public class MySubscriberWhiteboxVerificationTest extends SubscriberWhiteboxVeri
0 commit comments