@Test
  public void testPermFunc() throws Exception {
    // This test assumes the hive-contrib JAR has been built as part of the Hive build.
    // Also dependent on the UDFExampleAdd class within that JAR.
    Path jarFilePath = getHiveContribJarPath();
    Statement stmt = conTestDb.createStatement();
    ResultSet res;
    // Add the jar file
    stmt.execute("ADD JAR " + jarFilePath.toString());

    // Register function
    String queryStr =
        "CREATE FUNCTION example_add AS '" + testUdfClassName + "' USING JAR '" + jarFilePath + "'";
    stmt.execute(queryStr);

    // Call describe
    res = stmt.executeQuery("DESCRIBE FUNCTION " + testDbName + ".example_add");
    checkForNotExist(res);

    // Use UDF in query
    res = stmt.executeQuery("SELECT example_add(1, 2) FROM " + tableName + " LIMIT 1");
    assertTrue("query has results", res.next());
    assertEquals(3, res.getInt(1));
    assertFalse("no more results", res.next());

    //try creating same function again which should fail with AlreadyExistsException
    String createSameFunctionAgain =
            "CREATE FUNCTION example_add AS '" + testUdfClassName + "' USING JAR '" + jarFilePath + "'";
    try {
      stmt.execute(createSameFunctionAgain);
    }catch (Exception e){
      assertTrue("recreating same function failed with AlreadyExistsException ", e.getMessage().contains("AlreadyExistsException"));
    }

    // Call describe to see if function still available in registry
    res = stmt.executeQuery("DESCRIBE FUNCTION " + testDbName + ".example_add");
    checkForNotExist(res);

    // A new connection should be able to call describe/use function without issue
    Connection conn2 = getConnection(testDbName);
    Statement stmt2 = conn2.createStatement();
    stmt2.execute("USE " + testDbName);
    res = stmt2.executeQuery("DESCRIBE FUNCTION " + testDbName + ".example_add");
    checkForNotExist(res);

    res =
        stmt2.executeQuery("SELECT " + testDbName + ".example_add(1, 1) FROM " + tableName
            + " LIMIT 1");
    assertTrue("query has results", res.next());
    assertEquals(2, res.getInt(1));
    assertFalse("no more results", res.next());
    conn2.close();
    stmt.execute("DROP FUNCTION IF EXISTS " + testDbName + ".example_add");
    stmt.close();
  }
Tests ADD JAR uses Hives ReflectionUtil.CONSTRUCTOR_CACHE

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