Source:
public void logAppendTest() { try { File tempFile = tempFile(); RandomAccessFile randomFile = new RandomAccessFile(tempFile.getParent() + File.separator + "log_current", "rw"); File logFile = new File(tempFile.getParent(), "log_current"); logFile.deleteOnExit(); randomFile.setLength(5000); MetricRegistry registry = new MetricRegistry(); Log logTest = new Log(tempFile.getParent(), 5000, new StoreMetrics(tempFile.getParent(), registry)); byte[] testbuf = new byte[2000]; new Random().nextBytes(testbuf); int written = logTest.appendFrom(ByteBuffer.wrap(testbuf)); Assert.assertEquals(written, 2000); Assert.assertEquals(logTest.getLogEndOffset(), 2000); logTest.appendFrom(Channels.newChannel(new ByteBufferInputStream(ByteBuffer.wrap(testbuf))), 2000); Assert.assertEquals(logTest.getLogEndOffset(), 4000); String str = tempFile.getParent()+"."; try { logTest.appendFrom(ByteBuffer.wrap(testbuf)); Assert.assertTrue(false); } catch (IllegalArgumentException e) { Assert.assertEquals(registry.getCounters(). get("com.github.ambry.store.Log." + str + "OverflowWriteError").getCount(), 1); } try { logTest.appendFrom(Channels.newChannel(new ByteBufferInputStream(ByteBuffer.wrap(testbuf))), 2000); Assert.assertTrue(false); } catch (IllegalArgumentException e) { Assert.assertEquals(registry.getCounters(). get("com.github.ambry.store.Log." + str + "OverflowWriteError").getCount(), 2); } logTest.close(); try { logTest.appendFrom(Channels.newChannel(new ByteBufferInputStream(ByteBuffer.wrap(testbuf))), 1000); Assert.assertTrue(false); } catch (ClosedChannelException e) { Assert.assertTrue(true); } } catch (Exception e) { e.printStackTrace(); Assert.assertEquals(true, false); } }

Target:
public void logAppendTest() { try { File tempFile = tempFile(); RandomAccessFile randomFile = new RandomAccessFile(tempFile.getParent() + File.separator + "log_current", "rw"); File logFile = new File(tempFile.getParent(), "log_current"); logFile.deleteOnExit(); randomFile.setLength(5000); MetricRegistry registry = new MetricRegistry(); Log logTest = new Log(tempFile.getParent(), 5000, new StoreMetrics(tempFile.getParent(), registry)); byte[] testbuf = new byte[2000]; new Random().nextBytes(testbuf); int written = logTest.appendFrom(ByteBuffer.wrap(testbuf)); Assert.assertEquals(written, 2000); Assert.assertEquals(logTest.getLogEndOffset(), 2000); logTest.appendFrom(Channels.newChannel(new ByteBufferInputStream(ByteBuffer.wrap(testbuf))), 2000); Assert.assertEquals(logTest.getLogEndOffset(), 4000); try { logTest.appendFrom(ByteBuffer.wrap(testbuf)); Assert.assertTrue(false); } catch (IllegalArgumentException e) { Assert.assertEquals(registry.getCounters(). get("com.github.ambry.store.Log." + tempFile.getParent() + ".OverflowWriteError").getCount(), 1); } try { logTest.appendFrom(Channels.newChannel(new ByteBufferInputStream(ByteBuffer.wrap(testbuf))), 2000); Assert.assertTrue(false); } catch (IllegalArgumentException e) { Assert.assertEquals(registry.getCounters(). get("com.github.ambry.store.Log." + tempFile.getParent() + ".OverflowWriteError").getCount(), 2); } logTest.close(); try { logTest.appendFrom(Channels.newChannel(new ByteBufferInputStream(ByteBuffer.wrap(testbuf))), 1000); Assert.assertTrue(false); } catch (ClosedChannelException e) { Assert.assertTrue(true); } } catch (Exception e) { e.printStackTrace(); Assert.assertEquals(true, false); } }