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


##########
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:
   This is because some catch blocks wrap the inner exception, i.e., 
`ExpectedKryoTestException` (thrown by `CustomKryoTestSerializer`).
   
   For example, `HeapKeyedStateBackendBuilder#restoreState` wrap 
`ExpectedKryoTestException` in `BackendBuildingException`.
   
   Thus, we need to check the `cause` field of the thrown exception.



-- 
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