@Test
  public void testNoTxnComponentsForScheduledQueries() throws Exception {
    String tableName = "scheduledquerytable";
    int[][] tableData = {{1, 2},{3, 4}};
    runStatementOnDriver("create table " + tableName + " (a int, b int) stored as orc tblproperties ('transactional'='true')");

    int noOfTimesScheduledQueryExecuted = 4;

    // Logic for executing scheduled queries multiple times.
    for (int index = 0;index < noOfTimesScheduledQueryExecuted;index++) {
      ExecutorService executor =
              Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true)
                      .setNameFormat("Scheduled queries for transactional tables").build());

      // Mock service which initialises the query for execution.
      MockScheduledQueryService qService = new
              MockScheduledQueryService("insert into " + tableName + " (a,b) " + makeValuesClause(tableData));
      ScheduledQueryExecutionContext ctx = new ScheduledQueryExecutionContext(executor, hiveConf, qService);

      // Start the scheduled query execution.
      try (ScheduledQueryExecutionService sQ = ScheduledQueryExecutionService.startScheduledQueryExecutorService(ctx)) {
        // Wait for the scheduled query to finish. Hopefully 30 seconds should be more than enough.
        SessionState.getConsole().logInfo("Waiting for query execution to finish ...");
        synchronized (qService.notifier) {
          qService.notifier.wait(30000);
        }
        SessionState.getConsole().logInfo("Done waiting for query execution!");
      }

      assertThat(qService.lastProgressInfo.isSetExecutorQueryId(), is(true));
      assertThat(qService.lastProgressInfo.getExecutorQueryId(),
              Matchers.containsString(ctx.executorHostName + "/"));
    }

    // Check whether the table has delta files corresponding to the number of scheduled executions.
    FileSystem fs = FileSystem.get(hiveConf);
    FileStatus[] fileStatuses = fs.globStatus(new Path(getWarehouseDir() + "/" + tableName + "/*"));
    Assert.assertEquals(fileStatuses.length, noOfTimesScheduledQueryExecuted);
    for(FileStatus fileStatus : fileStatuses) {
      Assert.assertTrue(fileStatus.getPath().getName().startsWith(AcidUtils.DELTA_PREFIX));
    }

    // Check whether the COMPLETED_TXN_COMPONENTS table has records with
    // '__global_locks' database and associate writeId corresponding to the
    // number of scheduled executions.
    Assert.assertEquals(TestTxnDbUtil.countQueryAgent(hiveConf,
            "select count(*) from completed_txn_components" +
            " where ctc_database='__global_locks'"),
            0);

    // Compact the table which has inserts from the scheduled query.
    runStatementOnDriver("alter table " + tableName + " compact 'major'");
    runWorker(hiveConf);
    runCleaner(hiveConf);

    // Run AcidHouseKeeperService to cleanup the COMPLETED_TXN_COMPONENTS.
    MetastoreTaskThread houseKeeper = new AcidHouseKeeperService();
    MetastoreTaskThread compactionHouseKeeper = new CompactionHouseKeeperService();
    houseKeeper.setConf(hiveConf);
    compactionHouseKeeper.setConf(hiveConf);
    houseKeeper.run();
    compactionHouseKeeper.run();

    // Check whether the table is compacted.
    fileStatuses = fs.globStatus(new Path(getWarehouseDir() + "/" + tableName + "/*"));
    Assert.assertEquals(fileStatuses.length, 1);
    for(FileStatus fileStatus : fileStatuses) {
      Assert.assertTrue(fileStatus.getPath().getName().startsWith(AcidUtils.BASE_PREFIX));
    }

    // Check whether the data in the table is correct.
    int[][] actualData = {{1,2}, {1,2}, {1,2}, {1,2}, {3,4}, {3,4}, {3,4}, {3,4}};
    List<String> resData = runStatementOnDriver("select a,b from " + tableName + " order by a");
    Assert.assertEquals(resData, stringifyValues(actualData));
  }
This tests that delete_delta_x_y dirs will be not produced during minor compaction if no input delete events.
See HIVE-20941.
@throws Exception
ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands2.java