This is an automated email from the ASF dual-hosted git repository.
chesnay pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/master by this push:
new f9f4284 [hotfix][test-utils-junit] Improve exception assertions
f9f4284 is described below
commit f9f4284f298236d57dfd6784a2a90bdd8103c72b
Author: Francesco Guardiani <[email protected]>
AuthorDate: Fri Apr 1 14:50:46 2022 +0200
[hotfix][test-utils-junit] Improve exception assertions
---
.../kafka/table/KafkaDynamicTableFactoryTest.java | 45 +++++++++++-----------
.../flink/runtime/rpc/akka/AkkaRpcActorTest.java | 4 +-
.../flink/core/testutils/FlinkAssertions.java | 27 +++----------
3 files changed, 30 insertions(+), 46 deletions(-)
diff --git
a/flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/streaming/connectors/kafka/table/KafkaDynamicTableFactoryTest.java
b/flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/streaming/connectors/kafka/table/KafkaDynamicTableFactoryTest.java
index 1c81457..2c2e2fe 100644
---
a/flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/streaming/connectors/kafka/table/KafkaDynamicTableFactoryTest.java
+++
b/flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/streaming/connectors/kafka/table/KafkaDynamicTableFactoryTest.java
@@ -93,7 +93,7 @@ import java.util.Set;
import java.util.function.Consumer;
import java.util.regex.Pattern;
-import static org.apache.flink.core.testutils.FlinkAssertions.containsCause;
+import static org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches;
import static
org.apache.flink.streaming.connectors.kafka.table.KafkaConnectorOptionsUtil.AVRO_CONFLUENT;
import static
org.apache.flink.streaming.connectors.kafka.table.KafkaConnectorOptionsUtil.DEBEZIUM_AVRO_CONFLUENT;
import static
org.apache.flink.streaming.connectors.kafka.table.KafkaConnectorOptionsUtil.PROPERTIES_PREFIX;
@@ -744,9 +744,9 @@ public class KafkaDynamicTableFactoryTest {
})
.isInstanceOf(ValidationException.class)
.satisfies(
- containsCause(
- new ValidationException(
- "Option 'topic' and 'topic-pattern'
shouldn't be set together.")));
+ anyCauseMatches(
+ ValidationException.class,
+ "Option 'topic' and 'topic-pattern' shouldn't
be set together."));
}
@Test
@@ -763,10 +763,10 @@ public class KafkaDynamicTableFactoryTest {
})
.isInstanceOf(ValidationException.class)
.satisfies(
- containsCause(
- new ValidationException(
- "'scan.startup.timestamp-millis' "
- + "is required in 'timestamp'
startup mode but missing.")));
+ anyCauseMatches(
+ ValidationException.class,
+ "'scan.startup.timestamp-millis' "
+ + "is required in 'timestamp' startup
mode but missing."));
}
@Test
@@ -784,10 +784,10 @@ public class KafkaDynamicTableFactoryTest {
})
.isInstanceOf(ValidationException.class)
.satisfies(
- containsCause(
- new ValidationException(
- "'scan.startup.specific-offsets' "
- + "is required in
'specific-offsets' startup mode but missing.")));
+ anyCauseMatches(
+ ValidationException.class,
+ "'scan.startup.specific-offsets' "
+ + "is required in 'specific-offsets'
startup mode but missing."));
}
@Test
@@ -803,10 +803,9 @@ public class KafkaDynamicTableFactoryTest {
})
.isInstanceOf(ValidationException.class)
.satisfies(
- containsCause(
- new ValidationException(
- "Could not find and instantiate
partitioner "
- + "class 'abc'")));
+ anyCauseMatches(
+ ValidationException.class,
+ "Could not find and instantiate partitioner "
+ "class 'abc'"));
}
@Test
@@ -823,10 +822,10 @@ public class KafkaDynamicTableFactoryTest {
})
.isInstanceOf(ValidationException.class)
.satisfies(
- containsCause(
- new ValidationException(
- "Currently 'round-robin' partitioner
only works "
- + "when option 'key.fields' is
not specified.")));
+ anyCauseMatches(
+ ValidationException.class,
+ "Currently 'round-robin' partitioner only
works "
+ + "when option 'key.fields' is not
specified."));
}
@Test
@@ -850,9 +849,9 @@ public class KafkaDynamicTableFactoryTest {
})
.isInstanceOf(ValidationException.class)
.satisfies(
- containsCause(
- new ValidationException(
- "sink.transactional-id-prefix must be
specified when using DeliveryGuarantee.EXACTLY_ONCE.")));
+ anyCauseMatches(
+ ValidationException.class,
+ "sink.transactional-id-prefix must be
specified when using DeliveryGuarantee.EXACTLY_ONCE."));
}
@Test
diff --git
a/flink-rpc/flink-rpc-akka/src/test/java/org/apache/flink/runtime/rpc/akka/AkkaRpcActorTest.java
b/flink-rpc/flink-rpc-akka/src/test/java/org/apache/flink/runtime/rpc/akka/AkkaRpcActorTest.java
index 4a75f1e..80c6204 100644
---
a/flink-rpc/flink-rpc-akka/src/test/java/org/apache/flink/runtime/rpc/akka/AkkaRpcActorTest.java
+++
b/flink-rpc/flink-rpc-akka/src/test/java/org/apache/flink/runtime/rpc/akka/AkkaRpcActorTest.java
@@ -430,7 +430,9 @@ class AkkaRpcActorTest {
onStartEndpoint.awaitUntilOnStartCalled();
assertThatThrownBy(() -> onStartEndpoint.getTerminationFuture().get())
- .satisfies(FlinkAssertions.containsCause(testException));
+ .satisfies(
+ FlinkAssertions.anyCauseMatches(
+ testException.getClass(),
testException.getMessage()));
}
/**
diff --git
a/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/FlinkAssertions.java
b/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/FlinkAssertions.java
index dae17f1..c2f51b0 100644
---
a/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/FlinkAssertions.java
+++
b/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/FlinkAssertions.java
@@ -57,6 +57,9 @@ public final class FlinkAssertions {
Class<? extends Throwable> clazz, String containsMessage) {
return t ->
assertThatChainOfCauses(t)
+ .as(
+ "Any cause is instance of class '%s' and
contains message '%s'",
+ clazz, containsMessage)
.anySatisfy(
cause ->
assertThat(cause)
@@ -65,28 +68,6 @@ public final class FlinkAssertions {
}
/**
- * Shorthand to assert the chain of causes includes a specific {@link
Throwable}. Same as:
- *
- * <pre>{@code
- * assertThatChainOfCauses(t)
- * .anySatisfy(
- * cause ->
- * assertThat(cause)
- * .isInstanceOf(throwable.getClass())
- * .hasMessage(throwable.getMessage()));
- * }</pre>
- */
- public static ThrowingConsumer<? super Throwable> containsCause(Throwable
throwable) {
- return t ->
- assertThatChainOfCauses(t)
- .anySatisfy(
- cause ->
- assertThat(cause)
-
.isInstanceOf(throwable.getClass())
-
.hasMessage(throwable.getMessage()));
- }
-
- /**
* Shorthand to assert the chain of causes includes a {@link Throwable}
matching a specific
* {@link Class}. Same as:
*
@@ -102,6 +83,7 @@ public final class FlinkAssertions {
Class<? extends Throwable> clazz) {
return t ->
assertThatChainOfCauses(t)
+ .as("Any cause is instance of class '%s'", clazz)
.anySatisfy(cause ->
assertThat(cause).isInstanceOf(clazz));
}
@@ -120,6 +102,7 @@ public final class FlinkAssertions {
public static ThrowingConsumer<? super Throwable> anyCauseMatches(String
containsMessage) {
return t ->
assertThatChainOfCauses(t)
+ .as("Any cause contains message '%s'", containsMessage)
.anySatisfy(t1 ->
assertThat(t1).hasMessageContaining(containsMessage));
}