Don't keep 100MB static buffer in test.

This may remove available memory from other tests running in the same
process. Instead, create the huge buffer when needed so it can be GCed
immediately.

PiperOrigin-RevId: 330960844
This commit is contained in:
tonihei 2020-09-10 18:10:28 +01:00 committed by Oliver Woodman
parent 267cc53770
commit 157dffdca9

View File

@ -39,8 +39,6 @@ public final class BatchBufferTest {
private static final byte[] TEST_ACCESS_UNIT =
TestUtil.buildTestData(BUFFER_SIZE_MUCH_SMALLER_THAN_BATCH_SIZE_BYTES);
private static final byte[] TEST_HUGE_ACCESS_UNIT =
TestUtil.buildTestData(BUFFER_SIZE_LARGER_THAN_BATCH_SIZE_BYTES);
private final BatchBuffer batchBuffer = new BatchBuffer();
@ -163,15 +161,16 @@ public final class BatchBufferTest {
batchBuffer.getNextAccessUnitBuffer().ensureSpaceForWrite(TEST_ACCESS_UNIT.length);
batchBuffer.getNextAccessUnitBuffer().data.put(TEST_ACCESS_UNIT);
batchBuffer.commitNextAccessUnit();
batchBuffer.getNextAccessUnitBuffer().ensureSpaceForWrite(TEST_HUGE_ACCESS_UNIT.length);
batchBuffer.getNextAccessUnitBuffer().data.put(TEST_HUGE_ACCESS_UNIT);
byte[] hugeAccessUnit = TestUtil.buildTestData(BUFFER_SIZE_LARGER_THAN_BATCH_SIZE_BYTES);
batchBuffer.getNextAccessUnitBuffer().ensureSpaceForWrite(hugeAccessUnit.length);
batchBuffer.getNextAccessUnitBuffer().data.put(hugeAccessUnit);
batchBuffer.commitNextAccessUnit();
batchBuffer.batchWasConsumed();
batchBuffer.flip();
assertThat(batchBuffer.getAccessUnitCount()).isEqualTo(1);
assertThat(batchBuffer.data).isEqualTo(ByteBuffer.wrap(TEST_HUGE_ACCESS_UNIT));
assertThat(batchBuffer.data).isEqualTo(ByteBuffer.wrap(hugeAccessUnit));
}
@Test