public static void setNewDerbyDbLocation(HiveConf conf, String newloc) {
    String newDbLoc = System.getProperty("test.tmp.dir") + newloc + "metastore_db";

    conf.setVar(ConfVars.METASTORE_CONNECT_URL_KEY, "jdbc:derby:;databaseName=" + newDbLoc
        + ";create=true");
  }
Use this if you want a fresh metastore for your test, without any existing entries.
It updates the configuration to point to new derby dir location
@param conf HiveConf to be updated
@param newloc new location within test temp dir for the metastore db
itests/hive-unit/src/test/java/org/apache/hadoop/hive/UtilsForTest.java