Class AbstractWireTestCase<T>

java.lang.Object
org.junit.Assert
org.apache.lucene.util.LuceneTestCase
org.elasticsearch.test.ESTestCase
org.elasticsearch.test.AbstractWireTestCase<T>
Direct Known Subclasses:
AbstractNamedWriteableTestCase, AbstractWireSerializingTestCase

public abstract class AbstractWireTestCase<T>
extends ESTestCase
Standard test case for testing wire serialization. If the class being tested extends Writeable then prefer extending AbstractWireSerializingTestCase.
  • Field Details

  • Constructor Details

    • AbstractWireTestCase

      public AbstractWireTestCase()
  • Method Details

    • createTestInstance

      protected abstract T createTestInstance()
      Creates a random test instance to use in the tests. This method will be called multiple times during test execution and should return a different random instance each time it is called.
    • mutateInstance

      protected T mutateInstance​(T instance) throws java.io.IOException
      Returns an instance which is mutated slightly so it should not be equal to the given instance.
      Throws:
      java.io.IOException
    • testEqualsAndHashcode

      public final void testEqualsAndHashcode()
      Tests that the equals and hashcode methods are consistent and copied versions of the instance are equal.
    • testSerialization

      public final void testSerialization() throws java.io.IOException
      Test serialization and deserialization of the test instance.
      Throws:
      java.io.IOException
    • assertSerialization

      protected final void assertSerialization​(T testInstance) throws java.io.IOException
      Serialize the given instance and asserts that both are equal.
      Throws:
      java.io.IOException
    • assertSerialization

      protected final void assertSerialization​(T testInstance, org.elasticsearch.Version version) throws java.io.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:
      java.io.IOException
    • assertEqualInstances

      protected void assertEqualInstances​(T expectedInstance, T newInstance)
      Assert that two instances are equal. This is intentionally not final so we can override how equality is checked.
    • copyInstance

      protected final T copyInstance​(T instance) throws java.io.IOException
      Throws:
      java.io.IOException
    • copyInstance

      protected abstract T copyInstance​(T instance, org.elasticsearch.Version version) throws java.io.IOException
      Copy the instance as by reading and writing using the code specific to the provided version. 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:
      java.io.IOException
    • getNamedWriteableRegistry

      protected org.elasticsearch.common.io.stream.NamedWriteableRegistry getNamedWriteableRegistry()
      Get the NamedWriteableRegistry to use when de-serializing the object. Override this method if you need to register NamedWriteables for the test object to de-serialize. By default this will return a NamedWriteableRegistry with no registered NamedWriteables