-
Notifications
You must be signed in to change notification settings - Fork 534
Add SubmissionPublisher TCK test #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SubmissionPublisher TCK test #415
Conversation
Travis still runs with Java 9.0.0 :( |
public void run() { | ||
while (sp.getNumberOfSubscribers() == 0) { | ||
try { | ||
Thread.sleep(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread.onSpinWait()? :)
} | ||
} | ||
|
||
for (int i = 0; i < elements; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add && sp.getNumberOfSubscribers() > 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if there are no subscribers, the loop will rush through without blocking.
} | ||
|
||
for (int i = 0; i < elements; i++) { | ||
sp.submit(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this stop blocking if all subscribers cancel their subscriptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so. This test passes for me:
SubmissionPublisher<Integer> sp = new SubmissionPublisher<>(
ForkJoinPool.commonPool(), 1);
TestConsumer<Integer> tc1 = new TestConsumer<>(0L);
TestConsumer<Integer> tc2 = new TestConsumer<>(0L);
sp.subscribe(tc1);
sp.subscribe(tc2);
CountDownLatch cdl = new CountDownLatch(1);
SchedulerServices.single().schedule(() -> {
for (int i = 0; i < 512; i++) {
sp.submit(i);
}
cdl.countDown();
});
Thread.sleep(1000);
assertEquals(1, cdl.getCount());
tc1.cancel();
tc2.cancel();
assertTrue(cdl.await(5, TimeUnit.SECONDS));
@reactive-streams/contributors Merging this tomorrow unless someone requests more time to review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks! Very cool to have the SubmissionPublisher tested here.
Perhaps we should eventually look into running against new releases of the JDK in case something changes without anyone noticing? Though I guess Doug would let us know then
Great work, @akarnokd! Thank you |
Yes, thanks very much @akarnokd ! |
This PR adds a
SubmissionPublisher
TCK test to theflow-tck
subproject.I've tested it with both Java 9.0.1 (via Gradle) and the custom patch from Doug Lea's comment (via IntelliJ's own test runner configured).