### Question:
BufferMgr { public DataBuffer createBuffer() throws IOException { synchronized (snapshotLock) { synchronized (this) { if (corruptedState) { throw new IOException("Corrupted BufferMgr state"); } int id = indexProvider.allocateIndex(); DataBuffer buf = null; BufferNode node = getCachedBufferNode(id); if (node != null) { buf = node.buffer; node.locked = true; removeFromCache(node); } buf = buf != null ? buf : getCacheBuffer(); buf.setId(id); buf.setDirty(true); buf.setEmpty(false); ++lockCount; return buf; } } } BufferMgr();  BufferMgr(int requestedBufferSize, long approxCacheSize, int maxUndos);  BufferMgr(BufferFile sourceFile);  BufferMgr(BufferFile sourceFile, long approxCacheSize, int maxUndos); private  BufferMgr(BufferFile sourceFile, int requestedbufferSize, long approxCacheSize,
			int maxUndos); void enablePreCache(); void setCorruptedState(); boolean isCorrupted(); synchronized int getLockCount(); int getBufferSize(); BufferFile getSourceFile(); void dispose(); void dispose(boolean keepRecoveryData); void setMaxUndos(int maxUndos); void clearCheckpoints(); int getMaxUndos(); synchronized DataBuffer getBuffer(int id); DataBuffer createBuffer(); void releaseBuffer(DataBuffer buf); void deleteBuffer(int id); boolean atCheckpoint(); boolean checkpoint(); synchronized boolean isChanged(); boolean hasUndoCheckpoints(); boolean hasRedoCheckpoints(); int getAvailableUndoCount(); int getAvailableRedoCount(); boolean undo(boolean redoable); boolean redo(); boolean canSave(); synchronized boolean modifiedSinceSnapshot(); boolean takeRecoverySnapshot(DBChangeSet changeSet, TaskMonitor monitor); LocalBufferFile getRecoveryChangeSetFile(); void clearRecoveryFiles(); boolean recover(TaskMonitor monitor); static boolean canRecover(BufferFileManager bfMgr); void save(String comment, DBChangeSet changeSet, TaskMonitor monitor); void saveAs(BufferFile outFile, boolean associateWithNewFile, TaskMonitor monitor); long getCacheHits(); long getCacheMisses(); int getLowBufferCount(); void resetCacheStatistics(); String getStatusInfo(); int getAllocatedBufferCount(); int getFreeBufferCount(); static void cleanupOldCacheFiles(); static final String ALWAYS_PRECACHE_PROPERTY; static final int DEFAULT_BUFFER_SIZE; static final int DEFAULT_CHECKPOINT_COUNT; static final int DEFAULT_CACHE_SIZE; }### Answer:
@Test public void testCreateBuffer() throws IOException { initNewFile(); assertTrue(!mgr.isChanged()); DataBuffer buf = mgr.createBuffer(); assertEquals(1, mgr.getLockCount()); int id = buf.getId(); buf.put(0, fillPattern1); mgr.releaseBuffer(buf); assertTrue(mgr.isChanged()); buf = mgr.getBuffer(id); assertEquals(1, mgr.getLockCount()); byte[] data = buf.get(0, buf.length()); Msg.error(this, ">>>>>>>>>>>>>>>> Expected Exception"); try { mgr.getBuffer(id); Assert.fail(); } catch (IOException e) { } Msg.error(this, "<<<<<<<<<<<<<<<< End Expected Exception"); mgr.releaseBuffer(buf); assertEquals(0, mgr.getLockCount()); assertTrue(Arrays.equals(fillPattern1, data)); try { mgr.releaseBuffer(buf); Assert.fail(); } catch (Exception e) { } assertEquals(0, mgr.getLockCount()); try { buf = mgr.getBuffer(++id); Assert.fail(); } catch (IOException e) { } assertEquals(0, mgr.getLockCount()); }