Skip to content

Commit

Permalink
[Java] Remove test method from RecordingWriter and use the real imple…
Browse files Browse the repository at this point in the history
…mentation for testing.
  • Loading branch information
mjpt777 committed Mar 29, 2018
1 parent 7592943 commit 3fa6148
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 55 deletions.
59 changes: 5 additions & 54 deletions aeron-archive/src/main/java/io/aeron/archive/RecordingWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

import io.aeron.Counter;
import io.aeron.logbuffer.BlockHandler;
import io.aeron.logbuffer.FrameDescriptor;
import io.aeron.logbuffer.Header;
import org.agrona.BitUtil;
import org.agrona.CloseHelper;
import org.agrona.DirectBuffer;
import org.agrona.LangUtil;
Expand All @@ -39,12 +36,12 @@
* Responsible for writing out a recording into the file system. A recording has descriptor file and a set of data files
* written into the archive folder.
* <p>
* Design note: While this class is notionally closely related to the {@link RecordingSession} it is separated from it
* for the following reasons:
* <b>Design note:</b> While this class is notionally closely related to the {@link RecordingSession} it is separated
* from it for the following reasons:
* <ul>
* <li> Easier testing and in particular simplified re-use in testing. </li>
* <li> Isolation of an external relationship, namely the FS</li>
* <li> While a {@link RecordingWriter} is part of a {@link RecordingSession}, a session may transition without actually
* <li>Easier testing and in particular simplified re-use in testing.</li>
* <li>Isolation of an external relationship, namely the file system.</li>
* <li>While a {@link RecordingWriter} is part of a {@link RecordingSession}, a session may transition without actually
* creating a {@link RecordingWriter}.</li>
* </ul>
*/
Expand Down Expand Up @@ -160,52 +157,6 @@ boolean isClosed()
return isClosed;
}

/**
* Convenience method for testing purposes only.
*/
void writeFragment(final DirectBuffer buffer, final Header header)
{
final int termOffset = header.termOffset();
final int frameLength = header.frameLength();
final int alignedLength = BitUtil.align(frameLength, FrameDescriptor.FRAME_ALIGNMENT);

try
{
if (NULL_POSITION == segmentPosition)
{
onFirstWrite(termOffset);
}

if (segmentFileLength == segmentPosition)
{
onFileRollOver();
}

final ByteBuffer src = buffer.byteBuffer().duplicate();
src.position(termOffset).limit(termOffset + frameLength);

final int written = recordingFileChannel.write(src, segmentPosition);
recordingFileChannel.position(segmentPosition + alignedLength);

if (written != frameLength)
{
throw new IllegalStateException();
}

if (forceWrites)
{
recordingFileChannel.force(forceMetadata);
}

afterWrite(alignedLength);
}
catch (final Exception ex)
{
close();
LangUtil.rethrowUnchecked(ex);
}
}

private void newRecordingSegmentFile()
{
final File file = new File(archiveDir, segmentFileName(recordingId, segmentIndex));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ private void recordFragment(

header.offset(offset);

recordingWriter.writeFragment(buffer, header);
recordingWriter.onBlock(buffer, offset, FRAME_LENGTH, SESSION_ID, INITIAL_TERM_ID);
}

private void mockPublication(final ExclusivePublication replay, final UnsafeBuffer termBuffer)
Expand Down

0 comments on commit 3fa6148

Please sign in to comment.