@Test
  public void testCompactionSchedule() throws Exception {
    IoTDBDescriptor.getInstance().getConfig().setFileLimitPerCrossTask(1);
    IoTDBDescriptor.getInstance().getConfig().setInnerCompactionCandidateFileNum(2);
    createFiles(10, 10, 5, 1000, 0, 0, 100, 100, false, true);
    createFiles(1, 5, 10, 1000, 4000, 4000, 0, 100, false, false);
    createFiles(1, 5, 10, 1000, 5000, 5000, 0, 100, false, false);

    tsFileManager.addAll(seqResources, true);
    tsFileManager.addAll(unseqResources, false);

    // first cross compaction task
    ICrossSpaceSelector crossSpaceCompactionSelector =
        IoTDBDescriptor.getInstance()
            .getConfig()
            .getCrossCompactionSelector()
            .createInstance(
                COMPACTION_TEST_SG, "0", 0, tsFileManager, new CompactionScheduleContext());
    CrossCompactionTaskResource sourceFiles =
        crossSpaceCompactionSelector
            .selectCrossSpaceTask(
                tsFileManager.getOrCreateSequenceListByTimePartition(0),
                tsFileManager.getOrCreateUnsequenceListByTimePartition(0))
            .get(0);
    Assert.assertEquals(2, sourceFiles.getSeqFiles().size());
    Assert.assertEquals(1, sourceFiles.getUnseqFiles().size());
    List<TsFileResource> targetResources =
        CompactionFileGeneratorUtils.getCrossCompactionTargetTsFileResources(
            sourceFiles.getSeqFiles());
    performer.setSourceFiles(sourceFiles.getSeqFiles(), sourceFiles.getUnseqFiles());
    performer.setTargetFiles(targetResources);
    performer.setSummary(new FastCompactionTaskSummary());
    performer.perform();

    CompactionUtils.moveTargetFile(
        targetResources, CompactionTaskType.CROSS, COMPACTION_TEST_SG + "-" + "0");
    CompactionUtils.combineModsInCrossCompaction(
        sourceFiles.getSeqFiles(), sourceFiles.getUnseqFiles(), targetResources);
    tsFileManager.replace(
        sourceFiles.getSeqFiles(), sourceFiles.getUnseqFiles(), targetResources, 0);

    // Suppose the read lock of the source file is occupied by other threads, causing the first task
    // to get stuck.
    // Target file of the first task should not be selected to participate in other cross compaction
    // tasks.
    Assert.assertEquals(
        0,
        crossSpaceCompactionSelector
            .selectCrossSpaceTask(
                tsFileManager.getOrCreateSequenceListByTimePartition(0),
                tsFileManager.getOrCreateUnsequenceListByTimePartition(0))
            .size());

    // Target file of the first task should not be selected to participate in other inner compaction
    // tasks.
    ICompactionSelector innerSelector =
        IoTDBDescriptor.getInstance()
            .getConfig()
            .getInnerSequenceCompactionSelector()
            .createInstance(
                COMPACTION_TEST_SG, "0", 0, tsFileManager, new CompactionScheduleContext());
    Assert.assertEquals(0, innerSelector.selectInnerSpaceTask(targetResources).size());

    // first compaction task finishes successfully
    targetResources.forEach(x -> x.setStatusForTest(TsFileResourceStatus.NORMAL));

    // target file of first compaction task can be selected to participate in another cross
    // compaction task
    List<CrossCompactionTaskResource> pairs =
        crossSpaceCompactionSelector.selectCrossSpaceTask(
            tsFileManager.getOrCreateSequenceListByTimePartition(0),
            tsFileManager.getOrCreateUnsequenceListByTimePartition(0));
    Assert.assertEquals(1, pairs.size());
    Assert.assertEquals(2, pairs.get(0).getSeqFiles().size());
    Assert.assertEquals(1, pairs.get(0).getUnseqFiles().size());
    Assert.assertEquals(
        tsFileManager.getTsFileList(true).get(4), pairs.get(0).getSeqFiles().get(0));
    Assert.assertEquals(
        tsFileManager.getTsFileList(true).get(5), pairs.get(0).getSeqFiles().get(1));
    Assert.assertEquals(
        tsFileManager.getTsFileList(false).get(0), pairs.get(0).getUnseqFiles().get(0));

    // target file of first compaction task can be selected to participate in another inner
    // compaction task
    List<InnerSpaceCompactionTask> innerPairs = innerSelector.selectInnerSpaceTask(targetResources);
    Assert.assertEquals(1, innerPairs.size());
  }
Target files of first cross compaction task should not be selected to participate in other
tasks util the first task is finished.<br>
Seq Files index : 1 ~ 10<br>
Unseq Files index : 1 ~ 2<br>
Unseq file 1 overlaps with seq file 4,5 and unseq file 2 overlaps with seq file 5,6
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/cross/CrossSpaceCompactionWithFastPerformerValidationTest.java