@Test
  public void testRootScratchDir() throws Exception {
    // Stop HiveServer2
    stopMiniHS2();
    HiveConf conf = getNewHiveConf();
    String userName;
    Path scratchDirPath;
    conf.set("hive.exec.scratchdir", tmpDir + "/hs2");
    // Start an instance of HiveServer2 which uses miniMR
    startMiniHS2(conf);
    userName = System.getProperty("user.name");
    Connection conn = getConnection(miniHS2.getJdbcURL(testDbName), userName, "password");
    // FS
    FileSystem fs = miniHS2.getLocalFS();
    FsPermission expectedFSPermission = new FsPermission((short)00733);
    // Verify scratch dir paths and permission
    // HDFS scratch dir
    scratchDirPath = new Path(HiveConf.getVar(conf, HiveConf.ConfVars.SCRATCH_DIR));
    verifyScratchDir(conf, fs, scratchDirPath, expectedFSPermission, userName, false);
    conn.close();

    // Test with multi-level scratch dir path
    // Stop HiveServer2
    stopMiniHS2();
    conf.set("hive.exec.scratchdir", tmpDir + "/level1/level2/level3");
    startMiniHS2(conf);
    conn = getConnection(miniHS2.getJdbcURL(testDbName), userName, "password");
    scratchDirPath = new Path(HiveConf.getVar(conf, HiveConf.ConfVars.SCRATCH_DIR));
    verifyScratchDir(conf, fs, scratchDirPath, expectedFSPermission, userName, false);
    conn.close();

    // Restore original state
    restoreMiniHS2AndConnections();
  }
Tests the creation of the root hdfs scratch dir, which should be writable by all.

@throws Exception
itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java