27
27
import java .io .IOException ;
28
28
import java .util .Collections ;
29
29
30
+ /**
31
+ * Standard test case for testing wire serialization. If the class being tested
32
+ * extends {@link Writeable} then prefer extending {@link AbstractWireSerializingTestCase}.
33
+ */
30
34
public abstract class AbstractWireTestCase <T > extends ESTestCase {
31
35
32
36
protected static final int NUMBER_OF_TEST_RUNS = 20 ;
@@ -38,11 +42,6 @@ public abstract class AbstractWireTestCase<T> extends ESTestCase {
38
42
*/
39
43
protected abstract T createTestInstance ();
40
44
41
- /**
42
- * Returns a {@link Writeable.Reader} that can be used to de-serialize the instance
43
- */
44
- protected abstract Writeable .Reader <T > instanceReader ();
45
-
46
45
/**
47
46
* Returns an instance which is mutated slightly so it should not be equal
48
47
* to the given instance.
@@ -73,18 +72,26 @@ public final void testSerialization() throws IOException {
73
72
}
74
73
75
74
/**
76
- * Serialize the given instance and asserts that both are equal
75
+ * Serialize the given instance and asserts that both are equal.
77
76
*/
78
- protected final T assertSerialization (T testInstance ) throws IOException {
79
- return assertSerialization (testInstance , Version .CURRENT );
77
+ protected final void assertSerialization (T testInstance ) throws IOException {
78
+ assertSerialization (testInstance , Version .CURRENT );
80
79
}
81
80
82
- protected final T assertSerialization (T testInstance , Version version ) throws IOException {
81
+ /**
82
+ * Assert that instances copied at a particular version are equal. The version is useful
83
+ * for sanity checking the backwards compatibility of the wire. It isn't a substitute for
84
+ * real backwards compatibility tests but it is *so* much faster.
85
+ */
86
+ protected final void assertSerialization (T testInstance , Version version ) throws IOException {
83
87
T deserializedInstance = copyInstance (testInstance , version );
84
88
assertEqualInstances (testInstance , deserializedInstance );
85
- return deserializedInstance ;
86
89
}
87
90
91
+ /**
92
+ * Assert that two instances are equal. This is intentionally not final so we can override
93
+ * how equality is checked.
94
+ */
88
95
protected void assertEqualInstances (T expectedInstance , T newInstance ) {
89
96
assertNotSame (newInstance , expectedInstance );
90
97
assertEquals (expectedInstance , newInstance );
@@ -95,6 +102,11 @@ protected final T copyInstance(T instance) throws IOException {
95
102
return copyInstance (instance , Version .CURRENT );
96
103
}
97
104
105
+ /**
106
+ * Copy the instance as by reading and writing using the code specific to the provided version.
107
+ * The version is useful for sanity checking the backwards compatibility of the wire. It isn't
108
+ * a substitute for real backwards compatibility tests but it is *so* much faster.
109
+ */
98
110
protected abstract T copyInstance (T instance , Version version ) throws IOException ;
99
111
100
112
/**
0 commit comments