isunjin commented on a change in pull request #6684: [FLINK-10205] Batch Job: InputSplit Fault tolerant for DataSource… URL: https://github.com/apache/flink/pull/6684#discussion_r221389763
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/JobMasterTest.java ########## @@ -704,6 +716,66 @@ public void testResourceManagerConnectionAfterRegainingLeadership() throws Excep } } + private JobGraph createDataSourceJobGraph() { + final TextInputFormat inputFormat = new TextInputFormat(new Path(".")); + final InputFormatVertex producer = new InputFormatVertex("Producer"); + new TaskConfig(producer.getConfiguration()).setStubWrapper(new UserCodeObjectWrapper<InputFormat<?, ?>>(inputFormat)); + producer.setInvokableClass(DataSourceTask.class); + + final JobVertex consumer = new JobVertex("Consumer"); + consumer.setInvokableClass(NoOpInvokable.class); + consumer.connectNewDataSetAsInput(producer, DistributionPattern.POINTWISE, ResultPartitionType.BLOCKING); + + final JobGraph jobGraph = new JobGraph(producer, consumer); + jobGraph.setAllowQueuedScheduling(true); + + return jobGraph; + } + + /** + * Tests the {@link JobMaster#requestNextInputSplit(JobVertexID, ExecutionAttemptID)} + * validate that it will get same result for a different retry + */ + @Test + public void testRequestNextInputSplitWithDataSourceFailover() throws Exception { + + final JobGraph dataSourceJobGraph = createDataSourceJobGraph(); + testJobMasterAPIWithMockExecution(dataSourceJobGraph, (tdd, jobMaster) ->{ + try{ + final JobMasterGateway gateway = jobMaster.getSelfGateway(JobMasterGateway.class); + + final TaskInformation taskInformation = tdd.getSerializedTaskInformation() + .deserializeValue(getClass().getClassLoader()); + JobVertexID vertexID = taskInformation.getJobVertexId(); + + //get the previous split + SerializedInputSplit split1 = gateway.requestNextInputSplit(vertexID, tdd.getExecutionAttemptId()).get(); + + //start a new version of this execution + ExecutionGraph executionGraph = jobMaster.getExecutionGraph(); + Execution execution = executionGraph.getRegisteredExecutions().get(tdd.getExecutionAttemptId()); + ExecutionVertex executionVertex = execution.getVertex(); + + long version = execution.getGlobalModVersion(); + gateway.updateTaskExecutionState(new TaskExecutionState(dataSourceJobGraph.getJobID(), tdd.getExecutionAttemptId(), ExecutionState.FINISHED)).get(); + Execution newExecution = executionVertex.resetForNewExecution(System.currentTimeMillis(), version); + + //get the new split + SerializedInputSplit split2 = gateway.requestNextInputSplit(vertexID, newExecution.getAttemptId()).get(); + + Assert.assertArrayEquals(split1.getInputSplitData(), split2.getInputSplitData()); + + //get the new split3 Review comment: add more assert ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on 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