public MemoryManager(float ratio, long minAllocation) {
    checkRatio(ratio);

    memoryPoolRatio = ratio;
    minMemoryAllocation = minAllocation;
    totalMemoryPool = Math.round((double)
            ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax()
        * ratio);
    LOG.debug("Allocated total memory pool is: {}", totalMemoryPool);
  }
@Test
  public void testMemoryManager() throws Exception {
    long poolSize = ParquetOutputFormat.getMemoryManager().getTotalMemoryPool();
    long rowGroupSize = poolSize / 2;
    conf.setLong(ParquetOutputFormat.BLOCK_SIZE, rowGroupSize);

    Assert.assertTrue("Pool should hold 2 full row groups", (2 * rowGroupSize) <= poolSize);
    Assert.assertTrue("Pool should not hold 3 full row groups", poolSize < (3 * rowGroupSize));

    Assert.assertEquals("Allocations should start out at 0", 0, getTotalAllocation());

    RecordWriter writer1 = createWriter(1);
    Assert.assertTrue("Allocations should never exceed pool size", getTotalAllocation() <= poolSize);
    Assert.assertEquals("First writer should be limited by row group size", rowGroupSize, getTotalAllocation());

    RecordWriter writer2 = createWriter(2);
    Assert.assertTrue("Allocations should never exceed pool size", getTotalAllocation() <= poolSize);
    Assert.assertEquals(
        "Second writer should be limited by row group size", 2 * rowGroupSize, getTotalAllocation());

    RecordWriter writer3 = createWriter(3);
    Assert.assertTrue("Allocations should never exceed pool size", getTotalAllocation() <= poolSize);

    writer1.close(null);
    Assert.assertTrue("Allocations should never exceed pool size", getTotalAllocation() <= poolSize);
    Assert.assertEquals(
        "Allocations should be increased to the row group size", 2 * rowGroupSize, getTotalAllocation());

    writer2.close(null);
    Assert.assertTrue("Allocations should never exceed pool size", getTotalAllocation() <= poolSize);
    Assert.assertEquals(
        "Allocations should be increased to the row group size", rowGroupSize, getTotalAllocation());

    writer3.close(null);
    Assert.assertEquals("Allocations should be increased to the row group size", 0, getTotalAllocation());
  }