public void testFireInsertEvent() throws Throwable {
    Hive hiveDb = Hive.getWithFastCheck(hiveConf, false);
    String tableName = "test_fire_insert_event";
    hiveDb.dropTable(tableName);
    hiveDb.createTable(tableName, Lists.newArrayList("col1"), null, TextInputFormat.class,
        HiveIgnoreKeyTextOutputFormat.class);
    Table table = hiveDb.getTable(tableName);
    Path tablePath = table.getDataLocation();
    // Create some files that "inserted"
    FileSystem fileSystem = tablePath.getFileSystem(hiveConf);
    fileSystem.deleteOnExit(tablePath);
    Path insert1 = new Path(tablePath, "insert1"), insert2 = new Path(tablePath, "insert2"),
        insert3 = new Path(tablePath, "insert3");

    try (OutputStream os1 = fileSystem.create(insert1);
         OutputStream os2 = fileSystem.create(insert2);
         OutputStream os3 = fileSystem.create(insert3)) {
      os1.write(new StringBuilder("hello, ").append(System.lineSeparator())
          .append("world1").toString().getBytes());
      os2.write(new StringBuilder("hello, ").append(System.lineSeparator())
          .append("world2").toString().getBytes());
      os3.write(new StringBuilder("hello, ").append(System.lineSeparator())
          .append("world3").toString().getBytes());
    }

    // Fire the InsertData event
    hiveDb.fireInsertEvent(hiveDb.getDatabaseCurrent().getName(), tableName, null,true,
        Arrays.asList(insert1.toString(), insert2.toString(), insert3.toString()));
    // Get the last Metastore event
    InsertEvent insertEvent = DummyFireInsertListener.getLastEvent();
    // Check the event
    Assert.assertNotNull(insertEvent);
    Assert.assertNotNull(insertEvent.getTableObj());
    Assert.assertEquals(tableName, insertEvent.getTableObj().getTableName());
    Assert.assertEquals(hiveDb.getDatabaseCurrent().getName(), insertEvent.getTableObj().getDbName());
    Set<String> insertFiles = new HashSet<>(insertEvent.getFiles());
    Set<String> expectedFiles = Sets.newHashSet(insert1.toString(), insert2.toString(), insert3.toString());
    Assert.assertTrue(insertFiles.size() == 3);
    for (String insertFile : insertFiles) {
      Assert.assertTrue(expectedFiles.contains(insertFile));
    }
    Map<String, String> expectedCheckSums = new HashMap<>();
    expectedCheckSums.put("insert1", getFileCheckSum(fileSystem, insert1));
    expectedCheckSums.put("insert2", getFileCheckSum(fileSystem, insert2));
    expectedCheckSums.put("insert3", getFileCheckSum(fileSystem, insert3));
    List<String> checkSums = insertEvent.getFileChecksums();
    Assert.assertTrue(checkSums.size() == 3);
    for (int i = 0; i < 3; i++) {
      Path insertedPath = new Path(insertEvent.getFiles().get(i));
      Assert.assertEquals(expectedCheckSums.get(insertedPath.getName()), checkSums.get(i));
    }
  }
Test that tables set up with auto-purge skip trash-directory when tables/partitions are dropped.
@throws Throwable
ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHive.java