Class ComparatorKeyring

java.lang.Object
google.registry.util.ComparingInvocationHandler<Keyring>
google.registry.keyring.api.ComparatorKeyring
All Implemented Interfaces:
InvocationHandler

public final class ComparatorKeyring extends ComparingInvocationHandler<Keyring>
Checks that a second keyring returns the same result as the current one.

Will behave exactly like the "actualKeyring" - as in will throw / return the exact same values - no matter what the "secondKeyring" does. But will log a warning if "secondKeyring" acts differently than "actualKeyring".

If both keyrings threw exceptions, there is no check whether the exeptions are the same. The assumption is that an error happened in both, but they might report that error differently.

  • Method Details

    • create

      public static Keyring create(Keyring original, Keyring second)
      Returns an instance of Keyring that is an exact proxy of "original".

      This proxy will log any differences in return value or thrown exceptions with "second".

    • log

      protected void log(Method method, String message)
      Description copied from class: ComparingInvocationHandler
      Called when there was a difference between the implementations.
      Specified by:
      log in class ComparingInvocationHandler<Keyring>
      Parameters:
      method - the method where the difference was found
      message - human readable description of the difference found
    • compareResults

      protected boolean compareResults(Method method, @Nullable Object a, @Nullable Object b)
      Implements equals for the PGP classes.
      Overrides:
      compareResults in class ComparingInvocationHandler<Keyring>
      Parameters:
      method - the method whose return value is given
      a - the object returned by a call to method for the "actual" implementation
      b - the object returned by a call to method for the "second" implementation
    • stringifyResult

      protected String stringifyResult(Method method, @Nullable Object a)
      Implements toString for the PGP classes.
      Overrides:
      stringifyResult in class ComparingInvocationHandler<Keyring>
      Parameters:
      method - the method whose return value is given
      a - the object returned by a call to method
    • stringifyThrown

      protected String stringifyThrown(Method method, Throwable throwable)
      Description copied from class: ComparingInvocationHandler
      Implements toString for thrown exceptions.

      By default exceptions are logged using their .toString. If more data is needed (part of stack trace for example), override this method with the desired implementation.

      Overrides:
      stringifyThrown in class ComparingInvocationHandler<Keyring>
      Parameters:
      method - the method whose return value is given
      throwable - the exception thrown by a call to method