|
30 | 30 |
|
31 | 31 | public class DelayableWriteableTests extends ESTestCase {
|
32 | 32 | // NOTE: we don't use AbstractWireSerializingTestCase because we don't implement equals and hashCode.
|
33 |
| - public static class Example implements NamedWriteable { |
| 33 | + private static class Example implements NamedWriteable { |
34 | 34 | private final String s;
|
35 | 35 |
|
36 | 36 | public Example(String s) {
|
@@ -66,7 +66,7 @@ public int hashCode() {
|
66 | 66 | }
|
67 | 67 | }
|
68 | 68 |
|
69 |
| - public static class NamedHolder implements Writeable { |
| 69 | + private static class NamedHolder implements Writeable { |
70 | 70 | private final Example e;
|
71 | 71 |
|
72 | 72 | public NamedHolder(Example e) {
|
@@ -97,6 +97,23 @@ public int hashCode() {
|
97 | 97 | }
|
98 | 98 | }
|
99 | 99 |
|
| 100 | + private static class SneakOtherSideVersionOnWire implements Writeable { |
| 101 | + private final Version version; |
| 102 | + |
| 103 | + public SneakOtherSideVersionOnWire() { |
| 104 | + version = Version.CURRENT; |
| 105 | + } |
| 106 | + |
| 107 | + public SneakOtherSideVersionOnWire(StreamInput in) throws IOException { |
| 108 | + version = Version.readVersion(in); |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + public void writeTo(StreamOutput out) throws IOException { |
| 113 | + Version.writeVersion(out.getVersion(), out); |
| 114 | + } |
| 115 | + } |
| 116 | + |
100 | 117 | public void testRoundTripFromReferencing() throws IOException {
|
101 | 118 | Example e = new Example(randomAlphaOfLength(5));
|
102 | 119 | DelayableWriteable<Example> original = DelayableWriteable.referencing(e);
|
@@ -139,6 +156,12 @@ public void testRoundTripFromDelayedFromOldVersionWithNamedWriteable() throws IO
|
139 | 156 | roundTripTestCase(original, NamedHolder::new);
|
140 | 157 | }
|
141 | 158 |
|
| 159 | + public void testSerializesWithRemoteVersion() throws IOException { |
| 160 | + Version remoteVersion = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT); |
| 161 | + DelayableWriteable<SneakOtherSideVersionOnWire> original = DelayableWriteable.referencing(new SneakOtherSideVersionOnWire()); |
| 162 | + assertThat(roundTrip(original, SneakOtherSideVersionOnWire::new, remoteVersion).get().version, equalTo(remoteVersion)); |
| 163 | + } |
| 164 | + |
142 | 165 | private <T extends Writeable> void roundTripTestCase(DelayableWriteable<T> original, Writeable.Reader<T> reader) throws IOException {
|
143 | 166 | DelayableWriteable<T> roundTripped = roundTrip(original, reader, Version.CURRENT);
|
144 | 167 | assertTrue(roundTripped.isDelayed());
|
|
0 commit comments