snuyanzin commented on code in PR #21410:
URL: https://github.com/apache/flink/pull/21410#discussion_r1044823025


##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/StateBackendTestBase.java:
##########
@@ -959,24 +947,44 @@ public void 
testKryoRegisteringRestoreResilienceWithDefaultSerializer() throws E
 
             // on the second restore, since the custom serializer will be used 
for
             // deserialization, we expect the deliberate failure to be thrown
-            expectedException.expect(
-                    anyOf(
-                            isA(ExpectedKryoTestException.class),
-                            Matchers.<Throwable>hasProperty(
-                                    "cause", 
isA(ExpectedKryoTestException.class))));
-
-            // state backends that eagerly deserializes (such as the memory 
state backend) will fail
-            // here
-            backend = restoreKeyedBackend(IntSerializer.INSTANCE, snapshot2, 
env);
-
-            state =
-                    backend.getPartitionedState(
-                            VoidNamespace.INSTANCE, 
VoidNamespaceSerializer.INSTANCE, kvId);
-
-            backend.setCurrentKey(1);
-            // state backends that lazily deserializes (such as RocksDB) will 
fail here
-            state.value();
-
+            assertThatThrownBy(
+                            () -> {
+                                // state backends that eagerly deserializes 
(such as the memory
+                                // state backend) will fail
+                                // here
+                                CheckpointableKeyedStateBackend<Integer> 
restoreBackend = null;
+                                try {
+                                    restoreBackend =
+                                            restoreKeyedBackend(
+                                                    IntSerializer.INSTANCE, 
snapshot2, env);
+
+                                    ValueState<TestPojo> restoreState =
+                                            restoreBackend.getPartitionedState(
+                                                    VoidNamespace.INSTANCE,
+                                                    
VoidNamespaceSerializer.INSTANCE,
+                                                    new 
ValueStateDescriptor<>("id", pojoType));
+
+                                    restoreBackend.setCurrentKey(1);
+                                    // state backends that lazily deserializes 
(such as RocksDB)
+                                    // will fail here
+                                    restoreState.value();
+
+                                    restoreBackend.dispose();
+                                } finally {
+                                    if (restoreBackend != null) {
+                                        IOUtils.closeQuietly(restoreBackend);
+                                        restoreBackend.dispose();
+                                    }
+                                }
+                            })
+                    .satisfiesAnyOf(
+                            actual ->
+                                    assertThat(actual)
+                                            
.isInstanceOf(ExpectedKryoTestException.class),
+                            actual ->
+                                    assertThat(actual)
+                                            .hasFieldOrProperty("cause")

Review Comment:
   there is `.hasCauseInstanceOf` method in assertJ e.g.
   ```java
   assertThatThrownBy(() -> ...)
   .hasCauseInstanceOf(ExpectedCauseException.class);
   ```
   will not it help here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to