Class AbstractBWCSerializationTestCase<T extends Writeable & ToXContent>


public abstract class AbstractBWCSerializationTestCase<T extends Writeable & ToXContent> extends AbstractXContentSerializingTestCase<T>
  • Constructor Details

    • AbstractBWCSerializationTestCase

      public AbstractBWCSerializationTestCase()
  • Method Details

    • mutateInstanceForVersion

      protected abstract T mutateInstanceForVersion(T instance, TransportVersion version)
      Returns the expected instance if serialized from the given version.
    • bwcVersions

      protected Collection<TransportVersion> bwcVersions()
      The bwc versions to test serialization against
    • testBwcSerialization

      public final void testBwcSerialization() throws IOException
      Test serialization and deserialization of the test instance across versions
      Throws:
      IOException
    • assertBwcSerialization

      protected final void assertBwcSerialization(T testInstance, TransportVersion version) throws IOException
      Assert that instances copied at a particular version are equal. The version is useful for sanity checking the backwards compatibility of the wire. It isn't a substitute for real backwards compatibility tests but it is *so* much faster.
      Throws:
      IOException
    • assertOnBWCObject

      protected void assertOnBWCObject(T bwcSerializedObject, T testInstance, TransportVersion version)
      Parameters:
      bwcSerializedObject - The object deserialized from the previous version
      testInstance - The original test instance
      version - The version which serialized
    • testSerializationIsNotBackwardsCompatible

      protected void testSerializationIsNotBackwardsCompatible(TransportVersion featureVersion, Function<T,Boolean> expectFailureFunction, String errorMessage) throws IOException
      Helper method to test cases where serialization to older versions is expected to fail. An example of such a case would be an existing object adding a new Enum value which is not known to older versions and which has no equivalent default value that could be sent instead. Any attempt to serialize the object will result in an exception on the older node when attempting to deserialize, so to make the cause of the failure more obvious, an exception is thrown on the node doing the serialization.
      Parameters:
      featureVersion - the TransportVersion in which the change was introduced
      expectFailureFunction - a function which should return true if serializing the instance should be expected to fail
      errorMessage - the expected error message when serialization fails
      Throws:
      IOException