Skip to content
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

Use newly introduced BlockingOperationError in assertions #67

Merged
merged 2 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,12 @@ public final class BlockingOperationError extends Error {
private final BlockingMethod method;

public BlockingOperationError(BlockingMethod method) {
super();
super(String.format("Blocking call! %s", method));
this.method = method;
}

public BlockingMethod getMethod() {
return method;
}

@Override
public String toString() {
return super.toString() + ": " + String.format("Blocking call! %s", method);
}
}

2 changes: 1 addition & 1 deletion example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {
testCompile 'io.reactivex.rxjava2:rxjava:2.2.5'

testCompile 'junit:junit:4.12'
testCompile 'org.assertj:assertj-core:3.11.1'
testCompile 'org.assertj:assertj-core:3.14.0'

reactor_3_3_x 'io.projectreactor:reactor-core:3.3.0.RC1'
}
13 changes: 10 additions & 3 deletions example/src/test/java/com/example/CustomBlockingMethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.assertj.core.api.Assertions;
import org.junit.Test;
import reactor.blockhound.BlockHound;
import reactor.blockhound.BlockingMethod;
import reactor.blockhound.BlockingOperationError;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;

Expand All @@ -41,11 +43,16 @@ public void shouldReportCustomBlockingMethods() {
Throwable e = Assertions.catchThrowable(() -> {
Mono.fromRunnable(Blocking::block).hide().subscribeOn(Schedulers.parallel()).block(Duration.ofMillis(100));
});

assertThat(e)
.as("exception")
.isNotNull()
.hasMessageEndingWith("Blocking call! " + Blocking.class.getName() + ".block");
.hasCauseInstanceOf(BlockingOperationError.class);

assertThat(e.getCause()).isInstanceOfSatisfying(BlockingOperationError.class, cause -> {
assertThat(cause.getMethod())
.isNotNull()
.returns(Blocking.class.getName(), BlockingMethod::getClassName)
.returns("block", BlockingMethod::getName);
});
}

static class Blocking {
Expand Down
22 changes: 17 additions & 5 deletions example/src/test/java/com/example/ReactorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import reactor.blockhound.BlockHound;
import reactor.blockhound.BlockingMethod;
import reactor.blockhound.BlockingOperationError;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
Expand Down Expand Up @@ -213,7 +215,7 @@ public static Iterable<Object[]> data() {
}).onErrorReturn(SocketTimeoutException.class, "");
});

// tests.entrySet().removeIf(it -> !"java.lang.Thread.sleep".equals(it.getKey()));
tests.entrySet().removeIf(it -> !"java.lang.Thread.sleep".equals(it.getKey()));

return tests.entrySet().stream().map(it -> new Object[]{it.getKey(), it.getValue()}).collect(Collectors.toList());
}
Expand All @@ -238,11 +240,16 @@ public void negative() throws Exception {
var e = Assertions.catchThrowable(() -> {
mono.subscribeOn(Schedulers.parallel()).block(Duration.ofSeconds(1));
});
assertThat(e).isNotNull();
assertThat(e).hasCauseInstanceOf(BlockingOperationError.class);

e = e.getCause();
e.printStackTrace(System.out);

assertThat(e).hasMessageEndingWith("Blocking call! " + method);
assertThat(e).isInstanceOfSatisfying(BlockingOperationError.class, it -> {
assertThat(it.getMethod())
.isNotNull()
.returns(method, BlockingMethod::toString);
});
}

@Test
Expand All @@ -251,11 +258,16 @@ public void negativeWithFlux() throws Exception {
var e = Assertions.catchThrowable(() -> {
mono.subscribeOn(Schedulers.parallel()).blockLast(Duration.ofSeconds(1));
});
assertThat(e).isNotNull();
assertThat(e).hasCauseInstanceOf(BlockingOperationError.class);

e = e.getCause();
e.printStackTrace(System.out);

assertThat(e).hasMessageEndingWith("Blocking call! " + method);
assertThat(e).isInstanceOfSatisfying(BlockingOperationError.class, it -> {
assertThat(it.getMethod())
.isNotNull()
.returns(method, BlockingMethod::toString);
});
}

}