Skip to content

Commit 0bce5d2

Browse files
authored
Reenable BWC tests after backport of #53793 (#54018)
* Reenable BWC tests after backport of #53793
1 parent 83e82d3 commit 0bce5d2

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ task verifyVersions {
222222
* after the backport of the backcompat code is complete.
223223
*/
224224

225-
boolean bwc_tests_enabled = false
226-
final String bwc_tests_disabled_issue = "https://github.com/elastic/elasticsearch/pull/53793" /* place a PR link here when committing bwc changes */
225+
boolean bwc_tests_enabled = true
226+
final String bwc_tests_disabled_issue = "" /* place a PR link here when committing bwc changes */
227227
if (bwc_tests_enabled == false) {
228228
if (bwc_tests_disabled_issue.isEmpty()) {
229229
throw new GradleException("bwc_tests_disabled_issue must be set when bwc_tests_enabled == false")

server/src/main/java/org/elasticsearch/common/io/stream/DelayableWriteable.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
package org.elasticsearch.common.io.stream;
2121

22-
import org.elasticsearch.Version;
23-
import org.elasticsearch.common.bytes.BytesReference;
24-
2522
import java.io.IOException;
2623
import java.util.function.Supplier;
2724

25+
import org.elasticsearch.Version;
26+
import org.elasticsearch.common.bytes.BytesReference;
27+
2828
/**
2929
* A holder for {@link Writeable}s that can delays reading the underlying
3030
* {@linkplain Writeable} when it is read from a remote node.
@@ -60,6 +60,7 @@ private static class Referencing<T extends Writeable> extends DelayableWriteable
6060
@Override
6161
public void writeTo(StreamOutput out) throws IOException {
6262
try (BytesStreamOutput buffer = new BytesStreamOutput()) {
63+
buffer.setVersion(out.getVersion());
6364
reference.writeTo(buffer);
6465
out.writeBytesReference(buffer.bytes());
6566
}

server/src/test/java/org/elasticsearch/common/io/stream/DelayableWriteableTests.java

+34-11
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@
1919

2020
package org.elasticsearch.common.io.stream;
2121

22-
import org.elasticsearch.Version;
23-
import org.elasticsearch.test.ESTestCase;
24-
import org.elasticsearch.test.VersionUtils;
22+
import static java.util.Collections.singletonList;
23+
import static org.hamcrest.Matchers.equalTo;
2524

2625
import java.io.IOException;
2726

28-
import static java.util.Collections.singletonList;
29-
import static org.hamcrest.Matchers.equalTo;
27+
import org.elasticsearch.Version;
28+
import org.elasticsearch.test.ESTestCase;
29+
import org.elasticsearch.test.VersionUtils;
3030

3131
public class DelayableWriteableTests extends ESTestCase {
3232
// 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 {
3434
private final String s;
3535

36-
public Example(String s) {
36+
Example(String s) {
3737
this.s = s;
3838
}
3939

40-
public Example(StreamInput in) throws IOException {
40+
Example(StreamInput in) throws IOException {
4141
s = in.readString();
4242
}
4343

@@ -66,14 +66,14 @@ public int hashCode() {
6666
}
6767
}
6868

69-
public static class NamedHolder implements Writeable {
69+
private static class NamedHolder implements Writeable {
7070
private final Example e;
7171

72-
public NamedHolder(Example e) {
72+
NamedHolder(Example e) {
7373
this.e = e;
7474
}
7575

76-
public NamedHolder(StreamInput in) throws IOException {
76+
NamedHolder(StreamInput in) throws IOException {
7777
e = in.readNamedWriteable(Example.class);
7878
}
7979

@@ -97,6 +97,23 @@ public int hashCode() {
9797
}
9898
}
9999

100+
private static class SneakOtherSideVersionOnWire implements Writeable {
101+
private final Version version;
102+
103+
SneakOtherSideVersionOnWire() {
104+
version = Version.CURRENT;
105+
}
106+
107+
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+
100117
public void testRoundTripFromReferencing() throws IOException {
101118
Example e = new Example(randomAlphaOfLength(5));
102119
DelayableWriteable<Example> original = DelayableWriteable.referencing(e);
@@ -139,6 +156,12 @@ public void testRoundTripFromDelayedFromOldVersionWithNamedWriteable() throws IO
139156
roundTripTestCase(original, NamedHolder::new);
140157
}
141158

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+
142165
private <T extends Writeable> void roundTripTestCase(DelayableWriteable<T> original, Writeable.Reader<T> reader) throws IOException {
143166
DelayableWriteable<T> roundTripped = roundTrip(original, reader, Version.CURRENT);
144167
assertTrue(roundTripped.isDelayed());

0 commit comments

Comments
 (0)