|
@@ -256,12 +256,32 @@ public abstract class AbstractStreamTests extends ESTestCase {
|
|
|
StreamOutput::writeCollection,
|
|
|
in -> in.readList(FooBar::new)
|
|
|
);
|
|
|
+
|
|
|
+ runWriteReadCollectionTest(
|
|
|
+ () -> new FooBar(randomInt(), randomInt()),
|
|
|
+ StreamOutput::writeOptionalCollection,
|
|
|
+ in -> in.readOptionalList(FooBar::new)
|
|
|
+ );
|
|
|
+
|
|
|
+ runWriteReadOptionalCollectionWithNullInput(out -> out.writeOptionalCollection(null), in -> in.readOptionalList(FooBar::new));
|
|
|
}
|
|
|
|
|
|
public void testStringCollection() throws IOException {
|
|
|
runWriteReadCollectionTest(() -> randomUnicodeOfLength(16), StreamOutput::writeStringCollection, StreamInput::readStringList);
|
|
|
}
|
|
|
|
|
|
+ public void testOptionalStringCollection() throws IOException {
|
|
|
+ runWriteReadCollectionTest(
|
|
|
+ () -> randomUnicodeOfLength(16),
|
|
|
+ StreamOutput::writeOptionalStringCollection,
|
|
|
+ StreamInput::readOptionalStringList
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testOptionalStringCollectionWithNullInput() throws IOException {
|
|
|
+ runWriteReadOptionalCollectionWithNullInput(out -> out.writeOptionalStringCollection(null), StreamInput::readOptionalStringList);
|
|
|
+ }
|
|
|
+
|
|
|
private <T> void runWriteReadCollectionTest(
|
|
|
final Supplier<T> supplier,
|
|
|
final CheckedBiConsumer<StreamOutput, Collection<T>, IOException> writer,
|
|
@@ -280,6 +300,18 @@ public abstract class AbstractStreamTests extends ESTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private <T> void runWriteReadOptionalCollectionWithNullInput(
|
|
|
+ final CheckedConsumer<StreamOutput, IOException> nullWriter,
|
|
|
+ final CheckedFunction<StreamInput, Collection<T>, IOException> reader
|
|
|
+ ) throws IOException {
|
|
|
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
|
|
|
+ nullWriter.accept(out);
|
|
|
+ try (StreamInput in = getStreamInput(out.bytes())) {
|
|
|
+ assertNull(reader.apply(in));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void testSetOfLongs() throws IOException {
|
|
|
final int size = randomIntBetween(0, 6);
|
|
|
final Set<Long> sourceSet = Sets.newHashSetWithExpectedSize(size);
|