Source:
<code>public void basicWriteAndReadTest() throws IOException { String segmentName = "log_current"; LogSegment segment = getSegment(segmentName, STANDARD_SEGMENT_SIZE); try { assertEquals("Name of segment is inconsistent with what was provided", segmentName, segment.getName()); int writeSize = 100; byte[] buf = TestUtils.getRandomBytes(3 * writeSize); int written = segment.appendFrom(ByteBuffer.wrap(buf, 0, writeSize)); assertEquals("Size written did not match size of buffer provided", writeSize, written); assertEquals("End offset is not equal to the cumulative bytes written", writeSize, segment.getEndOffset()); segment.appendFrom(Channels.newChannel(new ByteBufferInputStream(ByteBuffer.wrap(buf, writeSize, writeSize))), writeSize); assertEquals("End offset is not equal to the cumulative bytes written", 2 * writeSize, segment.getEndOffset()); segment.writeFrom(Channels.newChannel(new ByteBufferInputStream(ByteBuffer.wrap(buf, 2 * writeSize, writeSize))), segment.getEndOffset(), writeSize); assertEquals("End offset is not equal to the cumulative bytes written", 3 * writeSize, segment.getEndOffset()); <START> readAndEnsureMatch(segment, 0, buf); <END> assertEquals("End offset is not equal to the cumulative bytes written", 3 * writeSize, segment.getEndOffset()); assertEquals("Size in bytes is not equal to size of the file", STANDARD_SEGMENT_SIZE, segment.sizeInBytes()); segment.flush(); segment.close(); segment = new LogSegment(segmentName, new File(tempDirName, segmentName), STANDARD_SEGMENT_SIZE, metrics); segment.state = LogSegment.State.ACTIVE; segment.setEndOffset(buf.length); readAndEnsureMatch(segment, 0, buf); } finally { closeSegmentAndDeleteFile(segment); } }</code><technical_language>call readAndEnsureMatch() thrice confirm 3 calls appendFrom(buffer), appendFrom(channel) writeFrom(channel) behaving expected</technical_language>

Target:
public void basicWriteAndReadTest() throws IOException { String segmentName = "log_current"; LogSegment segment = getSegment(segmentName, STANDARD_SEGMENT_SIZE); try { assertEquals("Start offset is not as expected", 0, segment.getStartOffset()); assertEquals("Name of segment is inconsistent with what was provided", segmentName, segment.getName()); assertEquals("Capacity of segment is inconsistent with what was provided", STANDARD_SEGMENT_SIZE, segment.getCapacityInBytes()); int writeSize = 100; byte[] buf = TestUtils.getRandomBytes(3 * writeSize); int written = segment.appendFrom(ByteBuffer.wrap(buf, 0, writeSize)); assertEquals("Size written did not match size of buffer provided", writeSize, written); assertEquals("End offset is not equal to the cumulative bytes written", writeSize, segment.getEndOffset()); readAndEnsureMatch(segment, 0, Arrays.copyOfRange(buf, 0, writeSize)); segment.appendFrom(Channels.newChannel(new ByteBufferInputStream(ByteBuffer.wrap(buf, writeSize, writeSize))), writeSize); assertEquals("End offset is not equal to the cumulative bytes written", 2 * writeSize, segment.getEndOffset()); readAndEnsureMatch(segment, writeSize, Arrays.copyOfRange(buf, writeSize, 2 * writeSize)); segment.writeFrom(Channels.newChannel(new ByteBufferInputStream(ByteBuffer.wrap(buf, 2 * writeSize, writeSize))), segment.getEndOffset(), writeSize); assertEquals("End offset is not equal to the cumulative bytes written", 3 * writeSize, segment.getEndOffset()); readAndEnsureMatch(segment, 2 * writeSize, Arrays.copyOfRange(buf, 2 * writeSize, buf.length)); readAndEnsureMatch(segment, 0, buf); assertEquals("End offset is not equal to the cumulative bytes written", 3 * writeSize, segment.getEndOffset()); assertEquals("Size in bytes is not equal to size of the file", STANDARD_SEGMENT_SIZE, segment.sizeInBytes()); segment.flush(); segment.close(); segment = new LogSegment(segmentName, new File(tempDir, segmentName), STANDARD_SEGMENT_SIZE, metrics); segment.setEndOffset(buf.length); readAndEnsureMatch(segment, 0, buf); } finally { closeSegmentAndDeleteFile(segment); } }