Buffer implements Closeable { public Buffer(RecordFormatter recordFormatter) { this(new Config(), recordFormatter); } Buffer(RecordFormatter recordFormatter);  Buffer(final Config config, RecordFormatter recordFormatter); void flush(Ingester ingester, boolean force); @Override void close(); float getBufferUsage(); void clearBackupFiles(); long getMaxBufferSize(); String getFileBackupPrefix(); String getFileBackupDir(); void append(String tag, long timestamp, Map<String, Object> data); void append(String tag, EventTime timestamp, Map<String, Object> data); void appendMessagePackMapValue(String tag, long timestamp, byte[] mapValue, int offset, int len); void appendMessagePackMapValue(String tag, EventTime timestamp, byte[] mapValue, int offset, int len); void appendMessagePackMapValue(String tag, long timestamp, ByteBuffer mapValue); void appendMessagePackMapValue(String tag, EventTime timestamp, ByteBuffer mapValue); long getAllocatedSize(); long getBufferedDataSize(); boolean getJvmHeapBufferMode(); String bufferFormatType(); int getChunkInitialSize(); float getChunkExpandRatio(); int getChunkRetentionSize(); int getChunkRetentionTimeMillis(); @Override String toString();  }
@Test void testBuffer() throws IOException { int recordSize = 20; int tags = 10; float allocRatio = 2f; int maxAllocSize = (recordSize * 4) * tags; bufferConfig.setChunkInitialSize(recordSize); bufferConfig.setChunkExpandRatio(allocRatio); bufferConfig.setMaxBufferSize(maxAllocSize); bufferConfig.setChunkRetentionSize(maxAllocSize / 2); Buffer buffer = new Buffer(bufferConfig, recordFormatter); assertEquals(0, buffer.getAllocatedSize()); assertEquals(0, buffer.getBufferedDataSize()); assertEquals(0f, buffer.getBufferUsage(), 0.001); Map<String, Object> data = new HashMap<>(); data.put("name", "komamitsu"); for (int i = 0; i < tags; i++) { buffer.append("foodb.bartbl" + i, 1420070400, data); } assertEquals(recordSize * tags, buffer.getAllocatedSize()); assertEquals(recordSize * tags, buffer.getBufferedDataSize()); assertEquals(((float) recordSize) * tags / maxAllocSize, buffer.getBufferUsage(), 0.001); for (int i = 0; i < tags; i++) { buffer.append("foodb.bartbl" + i, 1420070400, data); } float totalAllocatedSize = recordSize * (1 + allocRatio) * tags; assertEquals(totalAllocatedSize, buffer.getAllocatedSize(), 0.001); assertEquals(2L * recordSize * tags, buffer.getBufferedDataSize()); assertEquals(totalAllocatedSize / maxAllocSize, buffer.getBufferUsage(), 0.001); buffer.flush(ingester, true); assertEquals(totalAllocatedSize, buffer.getAllocatedSize(), 0.001); assertEquals(0, buffer.getBufferedDataSize()); assertEquals(totalAllocatedSize / maxAllocSize, buffer.getBufferUsage(), 0.001); buffer.close(); assertEquals(0, buffer.getAllocatedSize()); assertEquals(0, buffer.getBufferedDataSize()); assertEquals(0, buffer.getBufferUsage(), 0.001); }