Skip to content

Commit

Permalink
Move test to AbstractStreamTests where it belongs
Browse files Browse the repository at this point in the history
  • Loading branch information
iverase committed Oct 11, 2023
1 parent e2e32f6 commit 4dd37e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {

}
Expand Down

0 comments on commit 4dd37e5

Please sign in to comment.