azagrebin commented on a change in pull request #11624: [FLINK-16949] Enhance 
AbstractStreamOperatorTestHarness to use customized TtlTimeProvider
URL: https://github.com/apache/flink/pull/11624#discussion_r402878447
 
 

 ##########
 File path: 
flink-streaming-java/src/test/java/org/apache/flink/streaming/util/AbstractStreamOperatorTestHarnessTest.java
 ##########
 @@ -52,4 +55,24 @@ public void testInitializeAfterOpenning() throws Throwable {
                result.open();
                result.initializeState(new OperatorSubtaskState());
        }
+
+       @Test
+       public void testSetTtlTimeProvider() throws Exception {
+               AbstractStreamOperatorTestHarness<Integer> result;
+               AbstractStreamOperator operator = new 
AbstractStreamOperator<Integer>() {};
+               result =
+                       new AbstractStreamOperatorTestHarness<>(
+                               operator,
+                               1,
+                               1,
+                               0);
+               result.config.setStateKeySerializer(IntSerializer.INSTANCE);
+
+               long expectedTimeStamp = 42;
+               result.setTtlTimeProvider(() -> expectedTimeStamp);
+               result.initializeState(new OperatorSubtaskState());
+               result.open();
+               Assert.assertEquals(expectedTimeStamp,
+                       ((AbstractKeyedStateBackend<?>) 
operator.getKeyedStateBackend()).getTtlTimeProvider().currentTimestamp());
 
 Review comment:
   I would avoid exposing `getTtlTimeProvider` in `AbstractKeyedStateBackend`, 
although we annotate with `VisibleForTesting`, it still becomes visible for 
users.
   The working of custom `TtlTimeProvider` can be tested e.g. by creating TTL 
states and checking that they expire according the custom timestamp. Also this 
will be tested by other tests which rely on this injection of custom 
`TtlTimeProvider`.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to