Skip to content

Commit

Permalink
[build] Fix reactor#891 Mostly build under JDK9, add JDK9 build in Tr…
Browse files Browse the repository at this point in the history
…avis CI

This commit builds under both JDK8 and JDK9 in Travis CI.
Minus a couple of caveats, it fixes the JDK9 build with various changes:

Version Bumps
 - Update to Gradle 4.2.1 for full compatibility with JDK9
 - Bump asciidoctor plugin^[1]
 - Bump Mockito^[2] and Jacoco to their latest JDK9-compatible versions
 - Bump AssertJ to 3.8.0^[3]
 - Bump Kotlin Gradle Plugin to 1.5.51^[4]

[1] Asciidoctor Caveat:
***********************
In JDK9, don't build the PDF as no compatible combination of
asciidoctorJ-pdf could be found...

[2] Tests Adaptation, Mockito Caveats:
**************************************
Fix scan tests that use mocks of non-Scannable PARENTs/ACTUALs

Added MockUtils with interfaces that help creating Scannable mocks that
also implement another interface for combinations not naturally found in
production code.

See Mockito issue mockito/mockito#357, which
is probably the cause why these used to pass on JDK 8.

[3] AssertJ Caveat:
*******************
Added workaround to an AssertJ issue in Java 8, see:
assertj/assertj#1046

[4] Kotlin Caveats:
*******************
 - Fixed building of Javadoc under JDK9 polluted by Kotlin classes that
 are deemed invalid by the Java 9 doclet. (these used to be ignored in
 Java 8)
 - Dokka is not building, so we exclude kdocZip (and thus dokka) under
 JDK9 (see Kotlin/dokka#220)
  • Loading branch information
simonbasle committed Oct 6, 2017
1 parent b2317ca commit d95e196
Show file tree
Hide file tree
Showing 39 changed files with 146 additions and 57 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#jenv local configuration
.java-version

.gradletasknamecache
.DS_Store
bin
build
Expand All @@ -16,4 +20,4 @@ classes
exportToHtml
.pmd
.ruleset
.rulesets
.rulesets
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: java
jdk:
- oraclejdk8
- oraclejdk9

sudo: required

Expand Down
25 changes: 18 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ buildscript {
}

plugins {
id 'org.asciidoctor.convert' version '1.5.2'
id 'org.asciidoctor.convert' version '1.5.6'
id "me.champeau.gradle.jmh" version "0.4.4" apply false
id "org.jetbrains.dokka" version "0.9.15"
id "me.champeau.gradle.japicmp" version "0.2.5"
Expand All @@ -57,8 +57,8 @@ ext {
logbackVersion = '1.1.2'

// Testing
assertJVersion = '3.6.1'
mockitoVersion = '2.7.22'
assertJVersion = '3.8.0'
mockitoVersion = '2.10.0'

javadocLinks = ["http://docs.oracle.com/javase/8/docs/api/",
"http://docs.oracle.com/javaee/6/api/",
Expand All @@ -70,7 +70,6 @@ ext {
'rx;resolution:=optional',
'com.google;resolution:=optional',
'*']

}

configure(subprojects) { p ->
Expand Down Expand Up @@ -111,7 +110,7 @@ configure(subprojects) { p ->
}

jacoco {
toolVersion = '0.7.7.201606060606'
toolVersion = '0.7.9'
}

jacocoTestReport {
Expand Down Expand Up @@ -288,6 +287,11 @@ project('reactor-core') {
options.tags = [ "apiNote:a:API Note:", "implSpec:a:Implementation Requirements:",
"implNote:a:Implementation Note:" ]

// In Java 9, javadoc generator will complain if it finds invalid class files in the classpath
// And Kotlin produces such classes, plus kotlin plugin puts them in the main sourceSet
classpath = sourceSets.main.output.filter { !it.absolutePath.contains("kotlin") }
classpath += sourceSets.main.compileClasspath

maxMemory = "1024m"
destinationDir = new File(project.buildDir, "docs/javadoc")
}
Expand Down Expand Up @@ -361,7 +365,8 @@ project('reactor-core') {
archives sourcesJar
archives javadocJar
archives docsZip
archives kdocZip
if (!JavaVersion.current().isJava9Compatible())
archives kdocZip
}

jacocoTestReport.dependsOn testNG
Expand Down Expand Up @@ -423,6 +428,11 @@ project('reactor-test') {
options.tags = [ "apiNote:a:API Note:", "implSpec:a:Implementation Requirements:",
"implNote:a:Implementation Note:" ]

// In Java 9, javadoc generator will complain if it finds invalid class files in the classpath
// And Kotlin produces such classes, plus kotlin plugin puts them in the main sourceSet
classpath = sourceSets.main.output.filter { !it.absolutePath.contains("kotlin") }
classpath += sourceSets.main.compileClasspath

maxMemory = "1024m"
destinationDir = new File(project.buildDir, "docs/javadoc")
}
Expand Down Expand Up @@ -469,7 +479,8 @@ project('reactor-test') {
}

artifacts {
archives kdocZip
if (!JavaVersion.current().isJava9Compatible())
archives kdocZip
}

jar.finalizedBy(japicmp)
Expand Down
8 changes: 7 additions & 1 deletion gradle/doc.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ configure(rootProject) {
include "index.asciidoc"
}
outputDir file("$buildDir/reactor-code/build/asciidoc")
backends = ['html5', 'pdf']
//TODO remove once a working combination of asciidoctorj, asciidoctorj-pdf and asciidoctor-gradle-plugin is found
if (JavaVersion.current().isJava9Compatible()) {
backends = ['html5']
}
else {
backends = ['html5', 'pdf']
}
logDocuments = true
options = [
doctype: 'book'
Expand Down
2 changes: 1 addition & 1 deletion gradle/setup.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

task wrapper(type: Wrapper, description: "Create a Gradle self-download wrapper") {
group = 'Project Setup'
gradleVersion = 4.2
gradleVersion = "4.2.1"
}

configure(subprojects) { p ->
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Tue Sep 26 10:19:46 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.junit.Test;
import org.mockito.Mockito;
import org.reactivestreams.Processor;
import org.reactivestreams.Publisher;
import reactor.core.Scannable;

Expand All @@ -29,7 +28,7 @@ public class DelegateProcessorTest {

@Test
public void scanReturnsDownStreamForParentElseDelegates() {
Publisher<?> downstream = Mockito.mock(Publisher.class);
Publisher<?> downstream = Mockito.mock(FluxOperator.class);

IllegalStateException boom = new IllegalStateException("boom");
InnerConsumer<?> upstream = Mockito.mock(InnerConsumer.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.junit.Assert;
import org.junit.Test;
import org.reactivestreams.Subscriber;
import reactor.core.CoreSubscriber;
import reactor.core.Scannable;
import reactor.test.StepVerifier;
import reactor.test.subscriber.AssertSubscriber;
Expand Down Expand Up @@ -254,7 +253,7 @@ public void subscriberCancels() {
@Test
@SuppressWarnings("unchecked")
public void scanInner() {
CoreSubscriber<? super String> actual = mock(CoreSubscriber.class);
InnerConsumer<? super String> actual = mock(InnerConsumer.class);
DirectProcessor<String> parent = new DirectProcessor<>();

DirectProcessor.DirectInner<String> test =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.LockSupport;
import java.util.stream.Stream;

import org.junit.Assert;
import org.junit.Ignore;
Expand Down Expand Up @@ -266,10 +267,15 @@ public void state(){
assertThat(tp.getPending()).isEqualTo(0);
assertThat(tp.getBufferSize()).isEqualTo(Queues.SMALL_BUFFER_SIZE);
assertThat(tp.isCancelled()).isFalse();
assertThat(tp.inners()).isEmpty();

//workaround https://github.com/joel-costigliola/assertj-core/issues/1046
Stream inners = tp.inners();
assertThat(inners).isEmpty();

Disposable d1 = tp.subscribe();
assertThat(tp.inners()).hasSize(1);
//workaround https://github.com/joel-costigliola/assertj-core/issues/1046
inners = tp.inners();
assertThat(inners).hasSize(1);

FluxSink<Integer> s = tp.sink();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import reactor.core.CoreSubscriber;
import reactor.core.Fuseable;
import reactor.core.Scannable;
import reactor.test.MockUtils;
import reactor.test.subscriber.AssertSubscriber;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -94,11 +95,10 @@ public void arrayContainsNull() {
.assertNotComplete();
}


@Test
public void scanConditionalSubscription() {
@SuppressWarnings("unchecked")
Fuseable.ConditionalSubscriber<? super Object> subscriber = Mockito.mock(Fuseable.ConditionalSubscriber.class);
Fuseable.ConditionalSubscriber<? super Object> subscriber = Mockito.mock(MockUtils.TestScannableConditionalSubscriber.class);

FluxArray.ArrayConditionalSubscription<Object> test =
new FluxArray.ArrayConditionalSubscription<>(subscriber,
Expand Down Expand Up @@ -126,7 +126,7 @@ public void scanConditionalSubscription() {
@Test
public void scanConditionalSubscriptionRequested() {
@SuppressWarnings("unchecked")
Fuseable.ConditionalSubscriber<? super Object> subscriber = Mockito.mock(Fuseable.ConditionalSubscriber.class);
Fuseable.ConditionalSubscriber<? super Object> subscriber = Mockito.mock(MockUtils.TestScannableConditionalSubscriber.class);
//the mock will not drain the request, so it can be tested
Mockito.when(subscriber.tryOnNext(Mockito.any()))
.thenReturn(false);
Expand All @@ -143,7 +143,7 @@ public void scanConditionalSubscriptionRequested() {
@Test
public void scanConditionalSubscriptionCancelled() {
@SuppressWarnings("unchecked")
Fuseable.ConditionalSubscriber<? super Object> subscriber = Mockito.mock(Fuseable.ConditionalSubscriber.class);
Fuseable.ConditionalSubscriber<? super Object> subscriber = Mockito.mock(MockUtils.TestScannableConditionalSubscriber.class);

FluxArray.ArrayConditionalSubscription<Object> test =
new FluxArray.ArrayConditionalSubscription<>(subscriber, new Object[] {"foo", "bar", "baz"});
Expand All @@ -155,7 +155,7 @@ public void scanConditionalSubscriptionCancelled() {

@Test
public void scanSubscription() {
@SuppressWarnings("unchecked") CoreSubscriber<String> subscriber = Mockito.mock(CoreSubscriber.class);
@SuppressWarnings("unchecked") InnerOperator<String, String> subscriber = Mockito.mock(InnerOperator.class);
FluxArray.ArraySubscription<String> test =
new FluxArray.ArraySubscription<>(subscriber, new String[] {"foo", "bar", "baz"});

Expand All @@ -179,7 +179,7 @@ public void scanSubscription() {
@Test
public void scanSubscriptionCancelled() {
@SuppressWarnings("unchecked")
CoreSubscriber<String> subscriber = Mockito.mock(CoreSubscriber.class);
CoreSubscriber<String> subscriber = Mockito.mock(InnerOperator.class);
FluxArray.ArraySubscription<String> test =
new FluxArray.ArraySubscription<>(subscriber, new String[] {"foo", "bar", "baz"});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

package reactor.core.publisher;

import java.util.function.Consumer;

import org.junit.Test;
import org.mockito.Mockito;
import reactor.core.Disposable;
import reactor.core.Scannable;
import reactor.test.MockUtils;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -27,7 +31,7 @@ public class FluxAutoConnectFuseableTest {
@Test
public void scanMain() {
@SuppressWarnings("unchecked")
ConnectableFlux<String> source = Mockito.mock(ConnectableFlux.class);
ConnectableFlux<String> source = Mockito.mock(MockUtils.TestScannableConnectableFlux.class);
Mockito.when(source.getPrefetch()).thenReturn(888);
FluxAutoConnectFuseable<String> test = new FluxAutoConnectFuseable<>(source, 123, d -> { });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.mockito.Mockito;
import reactor.core.Disposable;
import reactor.core.Scannable;
import reactor.test.MockUtils;
import reactor.test.subscriber.AssertSubscriber;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -82,7 +83,7 @@ public void connectAfterMany() {
@Test
public void scanMain() {
@SuppressWarnings("unchecked")
ConnectableFlux<String> source = Mockito.mock(ConnectableFlux.class);
ConnectableFlux<String> source = Mockito.mock(MockUtils.TestScannableConnectableFlux.class);
Mockito.when(source.getPrefetch()).thenReturn(888);
FluxAutoConnect<String> test = new FluxAutoConnect<>(source, 123, d -> { });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import reactor.core.CoreSubscriber;
import reactor.core.Fuseable;
import reactor.core.Scannable;
import reactor.test.MockUtils;
import reactor.test.StepVerifier;
import reactor.test.publisher.FluxOperatorTest;
import reactor.test.subscriber.AssertSubscriber;
Expand Down Expand Up @@ -442,7 +443,7 @@ public void scanSubscriber() {
@Test
public void scanConditionalSubscriber() {
@SuppressWarnings("unchecked")
Fuseable.ConditionalSubscriber<String> actual = Mockito.mock(Fuseable.ConditionalSubscriber.class);
Fuseable.ConditionalSubscriber<String> actual = Mockito.mock(MockUtils.TestScannableConditionalSubscriber.class);
FluxDistinct.DistinctConditionalSubscriber<String, Integer, Set<Integer>> test =
new FluxDistinct.DistinctConditionalSubscriber<>(actual, new HashSet<>(), String::hashCode);
Subscription parent = Operators.emptySubscription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import reactor.core.CoreSubscriber;
import reactor.core.Fuseable;
import reactor.core.Scannable;
import reactor.test.MockUtils;
import reactor.test.publisher.FluxOperatorTest;
import reactor.test.subscriber.AssertSubscriber;

Expand Down Expand Up @@ -249,7 +250,7 @@ public void scanSubscriber() {
@Test
public void scanConditionalSubscriber() {
@SuppressWarnings("unchecked")
Fuseable.ConditionalSubscriber<String> actual = Mockito.mock(Fuseable.ConditionalSubscriber.class);
Fuseable.ConditionalSubscriber<String> actual = Mockito.mock(MockUtils.TestScannableConditionalSubscriber.class);
FluxDistinctUntilChanged.DistinctUntilChangedConditionalSubscriber<String, Integer> test = new FluxDistinctUntilChanged.DistinctUntilChangedConditionalSubscriber<>(
actual, String::hashCode, Objects::equals);
Subscription parent = Operators.emptySubscription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void normalOnRequest() {

@Test
public void scanSubscription() {
@SuppressWarnings("unchecked") CoreSubscriber<String> subscriber = Mockito.mock(CoreSubscriber.class);
@SuppressWarnings("unchecked") CoreSubscriber<String> subscriber = Mockito.mock(InnerOperator.class);
FluxErrorOnRequest.ErrorSubscription test =
new FluxErrorOnRequest.ErrorSubscription(subscriber, new IllegalStateException("boom"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import reactor.core.CoreSubscriber;
import reactor.core.Fuseable;
import reactor.core.Scannable;
import reactor.test.MockUtils;
import reactor.test.publisher.FluxOperatorTest;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -46,7 +47,7 @@ public void scanSubscriber() {
@Test
public void scanConditionalSubscriber() {
@SuppressWarnings("unchecked")
Fuseable.ConditionalSubscriber<String> actual = Mockito.mock(Fuseable.ConditionalSubscriber.class);
Fuseable.ConditionalSubscriber<String> actual = Mockito.mock(MockUtils.TestScannableConditionalSubscriber.class);
FluxFilterFuseable.FilterFuseableConditionalSubscriber<String> test = new FluxFilterFuseable.FilterFuseableConditionalSubscriber<>(actual, t -> true);
Subscription parent = Operators.emptySubscription();
test.onSubscribe(parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import reactor.core.CoreSubscriber;
import reactor.core.Fuseable;
import reactor.core.Scannable;
import reactor.test.MockUtils;
import reactor.test.publisher.FluxOperatorTest;
import reactor.test.subscriber.AssertSubscriber;

Expand Down Expand Up @@ -264,7 +265,7 @@ public void scanSubscriber() {
@Test
public void scanConditionalSubscriber() {
@SuppressWarnings("unchecked")
Fuseable.ConditionalSubscriber<String> actual = Mockito.mock(Fuseable.ConditionalSubscriber.class);
Fuseable.ConditionalSubscriber<String> actual = Mockito.mock(MockUtils.TestScannableConditionalSubscriber.class);
FluxFilter.FilterConditionalSubscriber<String> test = new FluxFilter.FilterConditionalSubscriber<>(actual, t -> true);
Subscription parent = Operators.emptySubscription();
test.onSubscribe(parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Stream;
import java.util.function.Function;

import org.junit.Assert;
Expand Down Expand Up @@ -954,7 +955,9 @@ void assertAfterOnCompleteInnerState2(InnerConsumer s) {

@SuppressWarnings("unchecked")
void assertAfterOnSubscribeInnerState(InnerProducer s) {
assertThat(s.inners()).hasSize(1);
//workaround https://github.com/joel-costigliola/assertj-core/issues/1046
Stream inners = s.inners();
assertThat(inners).hasSize(1);
}

void assertBeforeOnSubscribeInnerState(InnerConsumer s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ public void testPublishingTwice() {

@Test
public void scanOperator() {
Flux<Integer> source = Flux.range(1, 10);
Flux<Integer> source = Flux.range(1, 10).map(i -> i - 1);

FluxFlattenIterable<Integer, Integer> test = new FluxFlattenIterable<>(source, i -> new ArrayList<>(i), 35, Queues.one());

assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(source);
Expand Down
Loading

0 comments on commit d95e196

Please sign in to comment.