Skip to content

Commit f8d203d

Browse files
committed
=tck reactive-streams#384 dont check for cause message when checking 3.9
1 parent 11469fa commit f8d203d

File tree

5 files changed

+84
-7
lines changed

5 files changed

+84
-7
lines changed

tck/src/main/java/org/reactivestreams/tck/IdentityProcessorVerification.java

+5
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,11 @@ public void required_spec309_requestZeroMustSignalIllegalArgumentException() thr
370370
public void required_spec309_requestNegativeNumberMustSignalIllegalArgumentException() throws Throwable {
371371
publisherVerification.required_spec309_requestNegativeNumberMustSignalIllegalArgumentException();
372372
}
373+
374+
@Override @Test
375+
public void optional_spec309_requestNegativeNumberMaySignalIllegalArgumentExceptionWithSpecificMessage() throws Throwable {
376+
publisherVerification.optional_spec309_requestNegativeNumberMaySignalIllegalArgumentExceptionWithSpecificMessage();
377+
}
373378

374379
@Override @Test
375380
public void required_spec312_cancelMustMakeThePublisherToEventuallyStopSignaling() throws Throwable {

tck/src/main/java/org/reactivestreams/tck/PublisherVerification.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ public void required_spec309_requestZeroMustSignalIllegalArgumentException() thr
896896
@Override public void run(Publisher<T> pub) throws Throwable {
897897
final ManualSubscriber<T> sub = env.newManualSubscriber(pub);
898898
sub.request(0);
899-
sub.expectErrorWithMessage(IllegalArgumentException.class, "3.9"); // we do require implementations to mention the rule number at the very least
899+
sub.expectError(IllegalArgumentException.class);
900900
}
901901
});
902902
}
@@ -909,7 +909,22 @@ public void run(Publisher<T> pub) throws Throwable {
909909
final ManualSubscriber<T> sub = env.newManualSubscriber(pub);
910910
final Random r = new Random();
911911
sub.request(-r.nextInt(Integer.MAX_VALUE) - 1);
912-
sub.expectErrorWithMessage(IllegalArgumentException.class, "3.9"); // we do require implementations to mention the rule number at the very least
912+
// we do require implementations to mention the rule number at the very least, or mentioning that the non-negative request is the problem
913+
sub.expectError(IllegalArgumentException.class);
914+
}
915+
});
916+
}
917+
918+
@Override @Test
919+
public void optional_spec309_requestNegativeNumberMaySignalIllegalArgumentExceptionWithSpecificMessage() throws Throwable {
920+
optionalActivePublisherTest(10, false, new PublisherTestRun<T>() {
921+
@Override
922+
public void run(Publisher<T> pub) throws Throwable {
923+
final ManualSubscriber<T> sub = env.newManualSubscriber(pub);
924+
final Random r = new Random();
925+
sub.request(-r.nextInt(Integer.MAX_VALUE) - 1);
926+
// we do require implementations to mention the rule number at the very least, or mentioning that the non-negative request is the problem
927+
sub.expectErrorWithMessage(IllegalArgumentException.class, Arrays.asList("3.9", "non-positive subscription request", "negative subscription request"));
913928
}
914929
});
915930
}

tck/src/main/java/org/reactivestreams/tck/TestEnvironment.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.reactivestreams.tck.support.SubscriberBufferOverflowException;
1818
import org.reactivestreams.tck.support.Optional;
1919

20+
import java.util.Collections;
2021
import java.util.LinkedList;
2122
import java.util.List;
2223
import java.util.concurrent.ArrayBlockingQueue;
@@ -513,14 +514,24 @@ public void expectCompletion(long timeoutMillis, String errorMsg) throws Interru
513514
public <E extends Throwable> void expectErrorWithMessage(Class<E> expected, String requiredMessagePart) throws Exception {
514515
expectErrorWithMessage(expected, requiredMessagePart, env.defaultTimeoutMillis());
515516
}
517+
public <E extends Throwable> void expectErrorWithMessage(Class<E> expected, List<String> requiredMessagePartAlternatives) throws Exception {
518+
expectErrorWithMessage(expected, requiredMessagePartAlternatives, env.defaultTimeoutMillis());
519+
}
516520

517521
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
518522
public <E extends Throwable> void expectErrorWithMessage(Class<E> expected, String requiredMessagePart, long timeoutMillis) throws Exception {
523+
expectErrorWithMessage(expected, Collections.singletonList(requiredMessagePart), timeoutMillis);
524+
}
525+
public <E extends Throwable> void expectErrorWithMessage(Class<E> expected, List<String> requiredMessagePartAlternatives, long timeoutMillis) throws Exception {
519526
final E err = expectError(expected, timeoutMillis);
520527
final String message = err.getMessage();
521-
assertTrue(message.contains(requiredMessagePart),
528+
529+
boolean contains = false;
530+
for (String requiredMessagePart : requiredMessagePartAlternatives)
531+
if (message.contains(requiredMessagePart)) contains = true; // not short-circuting loop, it is expected to
532+
assertTrue(contains,
522533
String.format("Got expected exception [%s] but missing message part [%s], was: %s",
523-
err.getClass(), requiredMessagePart, err.getMessage()));
534+
err.getClass(), "anyOf: " + requiredMessagePartAlternatives, err.getMessage()));
524535
}
525536

526537
public <E extends Throwable> E expectError(Class<E> expected) throws Exception {

tck/src/main/java/org/reactivestreams/tck/support/PublisherVerificationRules.java

+28-3
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ public interface PublisherVerificationRules {
471471
void required_spec307_afterSubscriptionIsCancelledAdditionalCancelationsMustBeNops() throws Throwable;
472472
/**
473473
* Asks for a short {@code Publisher} (length 10) and issues a {@code request(0)} which should trigger an {@code onError} call
474-
* with an {@code IllegalArgumentException} and the message containing the string "3.9" (reference to the rule number).
474+
* with an {@code IllegalArgumentException}.
475475
* <p>
476476
* <b>Verifies rule:</b> <a href='https://github.com/reactive-streams/reactive-streams-jvm#3.9'>3.9</a>
477477
* <p>
@@ -495,8 +495,8 @@ public interface PublisherVerificationRules {
495495
*/
496496
void required_spec309_requestZeroMustSignalIllegalArgumentException() throws Throwable;
497497
/**
498-
* Asks for a short {@code Publisher} (length 10) and issues a random, negative {@code request()} call which should trigger an {@code onError} call
499-
* with an {@code IllegalArgumentException} and the message containing the string "3.9" (reference to the rule number).
498+
* Asks for a short {@code Publisher} (length 10) and issues a random, negative {@code request()} call which should
499+
* trigger an {@code onError} call with an {@code IllegalArgumentException}.
500500
* <p>
501501
* <b>Verifies rule:</b> <a href='https://github.com/reactive-streams/reactive-streams-jvm#3.9'>3.9</a>
502502
* <p>
@@ -519,6 +519,31 @@ public interface PublisherVerificationRules {
519519
* </ul>
520520
*/
521521
void required_spec309_requestNegativeNumberMustSignalIllegalArgumentException() throws Throwable;
522+
/**
523+
* Asks for a short {@code Publisher} (length 10) and issues a random, negative {@code request()} call which should
524+
* trigger an {@code onError} call with an {@code IllegalArgumentException}.
525+
* <p>
526+
* <b>Verifies rule:</b> <a href='https://github.com/reactive-streams/reactive-streams-jvm#3.9'>3.9</a>
527+
* <p>
528+
* The test is not executed if {@link org.reactivestreams.tck.PublisherVerification#maxElementsFromPublisher()} is less than 10.
529+
* <p>
530+
* Note that this test expects the {@code IllegalArgumentException} being signalled through {@code onError}, not by
531+
* throwing from {@code request()} (which is also forbidden) or signalling the error by any other means (i.e., through the
532+
* {@code Thread.currentThread().getUncaughtExceptionHandler()} for example).
533+
* <p>
534+
* Note also that requesting and emission may happen concurrently and honoring this rule may require extra coordination within
535+
* the {@code Publisher}.
536+
* <p>
537+
* If this test fails, the following could be checked within the {@code Publisher} implementation:
538+
* <ul>
539+
* <li>the {@code TestEnvironment} has large enough timeout specified in case the {@code Publisher} has some time-delay behavior,</li>
540+
* <li>make sure the {@link #required_createPublisher1MustProduceAStreamOfExactly1Element()} and {@link #required_createPublisher3MustProduceAStreamOfExactly3Elements()} tests pass,</li>
541+
* <li>the {@code Publisher} can emit an {@code onError} in this particular case, even if there was no prior and legal
542+
* {@code request} call and even if the {@code Publisher} would like to emit items first before emitting an {@code onError}
543+
* in general.
544+
* </ul>
545+
*/
546+
void optional_spec309_requestNegativeNumberMaySignalIllegalArgumentExceptionWithSpecificMessage() throws Throwable;
522547
/**
523548
* Asks for a short {@code Publisher} (length 20), requests some items (less than the length), consumes one item then
524549
* cancels the sequence and verifies the publisher emitted at most the requested amount and stopped emitting (or terminated).

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

+21
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,27 @@ public void required_spec309_requestZeroMustSignalIllegalArgumentException_shoul
481481
}, "Expected onError");
482482
}
483483

484+
@Test
485+
public void required_spec309_requestZeroMustSignalIllegalArgumentException_shouldPass() throws Throwable {
486+
customPublisherVerification(new Publisher<Integer>() {
487+
@Override
488+
public void subscribe(final Subscriber<? super Integer> s) {
489+
s.onSubscribe(new Subscription() {
490+
@Override
491+
public void request(long n) {
492+
// we error out with any message, it does not have to contain any specific wording
493+
if (n <= 0) s.onError(new IllegalArgumentException("Illegal request value detected!"));
494+
}
495+
496+
@Override
497+
public void cancel() {
498+
// noop
499+
}
500+
});
501+
}
502+
}).required_spec309_requestZeroMustSignalIllegalArgumentException();
503+
}
504+
484505
@Test
485506
public void required_spec309_requestNegativeNumberMustSignalIllegalArgumentException_shouldFailBy_expectingOnError() throws Throwable {
486507
requireTestFailure(new ThrowingRunnable() {

0 commit comments

Comments
 (0)