pnowojski commented on a change in pull request #8858: [hotfix][tests] Change
some StreamTask tests to create a test task in the task's thread
URL: https://github.com/apache/flink/pull/8858#discussion_r297102381
##########
File path:
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java
##########
@@ -805,29 +723,102 @@ public void
testSetsUserCodeClassLoaderForTimerThreadFactory() throws Throwable
new MockEnvironmentBuilder()
.setUserCodeClassLoader(new
TestUserCodeClassLoader())
.build()) {
- TimeServiceTask timerServiceTask = new
TimeServiceTask(mockEnvironment);
+ RunningTask<TimeServiceTask> task = runTask(() -> new
TimeServiceTask(mockEnvironment));
+ task.waitForTaskCompletion(false);
- CompletableFuture<Void> invokeFuture =
CompletableFuture.runAsync(
- () -> {
- try {
- timerServiceTask.invoke();
- } catch (Exception e) {
- throw new
CompletionException(e);
- }
- },
- TestingUtils.defaultExecutor());
-
- invokeFuture.get();
-
- assertThat(timerServiceTask.getClassLoaders(),
hasSize(greaterThanOrEqualTo(1)));
- assertThat(timerServiceTask.getClassLoaders(),
everyItem(instanceOf(TestUserCodeClassLoader.class)));
+ assertThat(task.streamTask.getClassLoaders(),
hasSize(greaterThanOrEqualTo(1)));
+ assertThat(task.streamTask.getClassLoaders(),
everyItem(instanceOf(TestUserCodeClassLoader.class)));
}
}
//
------------------------------------------------------------------------
// Test Utilities
//
------------------------------------------------------------------------
+ private static StreamOperator<?>
streamOperatorWithSnapshot(OperatorSnapshotFutures operatorSnapshotResult)
throws Exception {
+ StreamOperator<?> operator = mock(StreamOperator.class);
+ when(operator.getOperatorID()).thenReturn(new OperatorID());
Review comment:
Can you replace the `mock(StreamOperator.class)` here and
`streamOperatorWithSnapshotException` with some proper mock?
There are already quite a lot of mock implementations like two different
`MockStreamOperator` and `NoOpStreamOperator`, sot might be worthwhile thinking
about how to extract them to some common `MockStreamOperatorBuilder`, that
would provide an optional overrides for example for `operatorSnapshotResult`.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services