### Question:
MmapMemoryManager extends RealtimeIndexOffHeapMemoryManager { @VisibleForTesting public static long getDefaultFileLength() { return DEFAULT_FILE_LENGTH; } MmapMemoryManager(String dirPathName, String segmentName, ServerMetrics serverMetrics); @VisibleForTesting  MmapMemoryManager(String dirPathName, String segmentName); @VisibleForTesting static long getDefaultFileLength();  }### Answer:
@Test public void testLargeBlocks() throws Exception { final String segmentName = "someSegment"; PinotDataBufferMemoryManager memoryManager = new MmapMemoryManager(_tmpDir, segmentName); final long s1 = 2 * MmapMemoryManager.getDefaultFileLength(); final long s2 = 1000; final String col1 = "col1"; final String col2 = "col2"; final byte value = 34; PinotDataBuffer buf1 = memoryManager.allocate(s1, col1); ByteBuffer b1 = buf1.toDirectByteBuffer(0, (int) s1); b1.putLong(0, s1); Assert.assertEquals(b1.getLong(0), s1); b1.put((int) s1 - 1, value); Assert.assertEquals(b1.get((int) s1 - 1), value); PinotDataBuffer buf2 = memoryManager.allocate(s2, col2); ByteBuffer b2 = buf2.toDirectByteBuffer(0, (int) s2); b2.putLong(0, s2); Assert.assertEquals(b2.getLong(0), s2); File dir = new File(_tmpDir); File[] files = dir.listFiles(); Assert.assertEquals(files.length, 2); Arrays.sort(files, new Comparator<File>() { @Override public int compare(File o1, File o2) { return o1.getName().compareTo(o2.getName()); } }); String fileName = files[0].getName(); Assert.assertTrue(fileName.contains(segmentName)); fileName = files[1].getName(); Assert.assertTrue(fileName.contains(segmentName)); buf1.close(); buf2.close(); memoryManager.close(); List<String> allocationContexts = PinotDataBuffer.getBufferInfo(); Assert.assertEquals(allocationContexts.size(), 0); Assert.assertEquals(new File(_tmpDir).listFiles().length, 0); }
@Test public void testCornerConditions() throws Exception { final String segmentName = "someSegment"; PinotDataBufferMemoryManager memoryManager = new MmapMemoryManager(_tmpDir, segmentName); final long s1 = MmapMemoryManager.getDefaultFileLength() - 1; final long s2 = 1; final long s3 = 100 * 1024 * 1024; final String colName = "col"; final byte v1 = 56; final byte v2 = 11; final byte v3 = 32; PinotDataBuffer b1 = memoryManager.allocate(s1, colName); ByteBuffer bb1 = b1.toDirectByteBuffer(0, (int) s1); bb1.put((int) s1 - 1, v1); PinotDataBuffer b2 = memoryManager.allocate(s2, colName); ByteBuffer bb2 = b2.toDirectByteBuffer(0, (int) s2); bb2.put((int) s2 - 1, v2); File dir = new File(_tmpDir); Assert.assertEquals(dir.listFiles().length, 1); PinotDataBuffer b3 = memoryManager.allocate(s3, colName); ByteBuffer bb3 = b3.toDirectByteBuffer(0, (int) s3); bb3.put(0, v3); Assert.assertEquals(dir.listFiles().length, 2); Assert.assertEquals(bb1.get((int) s1 - 1), v1); Assert.assertEquals(bb2.get((int) s2 - 1), v2); Assert.assertEquals(bb3.get(0), v3); memoryManager.close(); List<String> allocationContexts = PinotDataBuffer.getBufferInfo(); Assert.assertEquals(allocationContexts.size(), 0); }