private Buffer preparePayload() throws IOException {
    final Collection<UnsignedByteArray> elements = new LinkedList<>();
    for (int i = 0; i < 15; i++) {
      final byte[] payload = ("payload" + i).getBytes();
      elements.add(UnsignedByteArrays.from(payload));
    }

    final V1FullPayloadSegment v1PayloadSegment = new V1FullPayloadSegment(elements);

    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    final OutputStreamWritable outputStreamWritable = v1PayloadSegment.buildWritable();
    outputStreamWritable.writeTo(os);
    return Buffer.from(os.toByteArray());
  }
  @Test
  public void hugePayload() throws IOException {
    final byte[] payload = new byte[1024 * 1024];
    for (int i = 0; i < payload.length; i++) payload[i] = (byte) i;

    final Collection<UnsignedByteArray> elements = new LinkedList<>();
    final int docs = 4 * 1024;
    for (int i = 0; i < docs; i++) {
      elements.add(UnsignedByteArrays.from(payload));
    }

    final com.yandex.yoctodb.v1.mutable.segment.V1FullPayloadSegment v1PayloadSegment =
        new V1FullPayloadSegment(elements);

    final OutputStreamWritable outputStreamWritable = v1PayloadSegment.buildWritable();

    final File f = File.createTempFile("huge", "dat");
    f.deleteOnExit();

    try (OutputStream os = new BufferedOutputStream(new FileOutputStream(f))) {
      outputStreamWritable.writeTo(os);
    }

    final Buffer buf = Buffer.from(new RandomAccessFile(f, "r").getChannel());

    final long segmentSize = buf.getLong();
    Assert.assertEquals(segmentSize + 4, buf.remaining());

    final int code = buf.getInt();
    final Payload segment = (Payload) SegmentRegistry.read(code, buf);

    final Buffer expectedPayload = Buffer.from(payload);
    for (int i = 0; i < docs; i += docs >> 2) {
      final Buffer currentPayload = segment.getPayload(i);
      Assert.assertEquals(expectedPayload, currentPayload);
    }
  }