@Override
  public void onEvent(PreEventContext context) throws MetaException, NoSuchObjectException,
      InvalidOperationException {

    callCount++;
    if (throwException) {
      throwException = false;
      throw new JDOException();
    }

    throwException = true;
  }
AlternateFailurePreListener.

An implementation of MetaStorePreEventListener which fails every other time it's invoked,
starting with the first time.

It also records and makes available the number of times it's been invoked.
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/AlternateFailurePreListener.java