@Override
    protected Result invokeInternal(Object proxy, Method method, Object[] args)
        throws Throwable {
      try {
        boolean isStarted = Deadline.startTimer(method.getName());
        Object object;
        try {
          if (testTimeoutValue > 0 &&
              (method.getName().equals("create_database") || method.getName().equals("create_database_req"))) {
            try {
              Thread.sleep(testTimeoutValue);
            } catch (InterruptedException e) {
              // do nothing.
            }
            Deadline.checkTimeout();
          }
          object = method.invoke(baseHandler, args);
        } finally {
          if (isStarted) {
            Deadline.stopTimer();
          }
        }
        return new Result(object, "error=false");
      } catch (UndeclaredThrowableException | InvocationTargetException e) {
        throw e.getCause();
      }
    }
Test handler proxy used to simulate a long-running create_database() method
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreTimeout.java