From 4dd37e59f508cc188a81421c6d2d22eef896c28f Mon Sep 17 00:00:00 2001 From: iverase Date: Wed, 11 Oct 2023 12:35:17 +0200 Subject: [PATCH] Move test to AbstractStreamTests where it belongs --- .../common/io/stream/AbstractStreamTests.java | 21 ++++++++++++++ .../common/io/stream/BytesStreamsTests.java | 28 ------------------- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/common/io/stream/AbstractStreamTests.java b/server/src/test/java/org/elasticsearch/common/io/stream/AbstractStreamTests.java index 1a6f52fabbd1b..aaecefa7e679a 100644 --- a/server/src/test/java/org/elasticsearch/common/io/stream/AbstractStreamTests.java +++ b/server/src/test/java/org/elasticsearch/common/io/stream/AbstractStreamTests.java @@ -737,4 +737,25 @@ private void assertGenericRoundtrip(Object original) throws IOException { assertThat(read, equalTo(original)); }); } + + public void testBytesReferenceSerialization() throws IOException { + final int length = randomIntBetween(1024, 1024 * 1024); + final byte[] bytes = new byte[length]; + random().nextBytes(bytes); + BytesReference expected; + if (randomBoolean()) { + final ByteArray byteArray = BigArrays.NON_RECYCLING_INSTANCE.newByteArray(length, randomBoolean()); + byteArray.set(0, bytes, 0, length); + expected = BytesReference.fromByteArray(byteArray, length); + } else { + expected = new BytesArray(bytes); + } + + BytesStreamOutput output = new BytesStreamOutput(); + output.writeBytesReference(expected); + final StreamInput in = getStreamInput(output.bytes()); + + final BytesReference loaded = in.readBytesReference(); + assertThat(loaded, equalTo(expected)); + } } diff --git a/server/src/test/java/org/elasticsearch/common/io/stream/BytesStreamsTests.java b/server/src/test/java/org/elasticsearch/common/io/stream/BytesStreamsTests.java index e6fb07039ed3b..92e8abbe83e16 100644 --- a/server/src/test/java/org/elasticsearch/common/io/stream/BytesStreamsTests.java +++ b/server/src/test/java/org/elasticsearch/common/io/stream/BytesStreamsTests.java @@ -15,8 +15,6 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.lucene.BytesRefs; -import org.elasticsearch.common.util.BigArrays; -import org.elasticsearch.common.util.ByteArray; import org.elasticsearch.common.util.Maps; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.core.TimeValue; @@ -561,32 +559,6 @@ public void testWriteMapAsList() throws IOException { assertThat(expected, equalTo(loaded)); } - public void testWriteBigBytesReference() throws IOException { - final int length = randomIntBetween(1024, 1024 * 1024); - final byte[] bytes = randomizedByteArrayWithSize(length); - BytesReference expected; - if (randomBoolean()) { - final ByteArray byteArray = BigArrays.NON_RECYCLING_INSTANCE.newByteArray(length, randomBoolean()); - byteArray.set(0, bytes, 0, length); - expected = BytesReference.fromByteArray(byteArray, length); - } else { - expected = new BytesArray(bytes); - } - - final BytesStreamOutput out = new BytesStreamOutput(); - out.writeBytesReference(expected); - { - final StreamInput in = out.bytes().streamInput(); // use the BytesReference version - final BytesReference loaded = in.readBytesReference(); - assertThat(loaded, equalTo(expected)); - } - { - final StreamInput in = StreamInput.wrap(BytesReference.toBytes(out.bytes())); // use the byte[] version - final BytesReference loaded = in.readBytesReference(); - assertThat(loaded, equalTo(expected)); - } - } - private abstract static class BaseNamedWriteable implements NamedWriteable { }