@Override
      public void run() {
        Deadline.registerIfNot(timeout);
        try {
          // normal
          start();
          try {
            Deadline.checkTimeout();
          } catch (MetaException e) {
            failInThread("should not timeout", e);
            return;
          }
          Deadline.stopTimer();

          // normal. Check stopTimer() works.
          start();
          try {
            Deadline.checkTimeout();
          } catch (MetaException e) {
            failInThread("should not timeout", e);
            return;
          }
          Deadline.stopTimer();

          // reset
          Deadline.resetTimeout(resetTimeout);

          // timeout
          start();
          try {
            Deadline.checkTimeout();
            failInThread("should timeout.", null);
            return;
          } catch (MetaException e) {
            if (e.getCause() instanceof DeadlineException) {
              Deadline.clear();
            } else {
              failInThread("new MetaException failed.", e);
              return;
            }
          }
          if (Deadline.getCurrentDeadline() != null) {
            failInThread("the threadlocal object should be removed after timeout.", null);
          }
        } catch (MetaException e) {
          failInThread("error happens in start, end, or reset. Check the exception.", e);
        }
      }
Test the Deadline class used for long running requests.
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestDeadline.java