Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix collecting lines by appending a line feed #299

Merged
merged 3 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
import org.metafacture.framework.helpers.DefaultObjectPipe;

/**
* Joins strings and emits them as records when a line matches the pattern.
* Collects strings and emits them as records when a line matches the pattern.
* Appends to every incoming line a line feed so that the original structure is
* preserved.
*
* @author Pascal Christoph (dr0i).
*
*/
@Description("Joins strings and emits them as records when a line matches the pattern.")
@Description("Collects strings and emits them as records when a line matches the pattern.")
@In(String.class)
@Out(String.class)
@FluxCommand("lines-to-records")
Expand All @@ -50,7 +52,7 @@ public void process(final String line) {
getReceiver().process(record.toString());
record = new StringBuilder(SB_CAPACITY);
} else
record.append(line);
record.append(line + "\n");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@
*/
public final class LineRecorderTest {

private static final String RECORD1_PART1 = "a1\n";
private static final String RECORD1_PART2 = "a2\n";
private static final String RECORD1_PART1 = "a1";
private static final String RECORD1_PART2 = "a2";
private static final String RECORD1_ENDMARKER = "\n";

private static final String RECORD2_PART1 = "b1\n";
private static final String RECORD2_PART2 = "b2\n";
private static final String RECORD2_PART1 = "b1";
private static final String RECORD2_PART2 = "b2";
private static final String RECORD2_ENDMARKER = "\n";

private static final String RECORD3_PART1 = "c1\n";
private static final String RECORD3_PART2 = "c2\n";
private static final String RECORD3_PART1 = "c1";
private static final String RECORD3_PART2 = "c2";
private static final String RECORD3_ENDMARKER = "EOR";

private static final String LINE_SEPARATOR = "\n";

private LineRecorder lineRecorder;

@Mock
Expand All @@ -63,13 +65,21 @@ public void shouldEmitRecords() {
lineRecorder.process(RECORD1_ENDMARKER);

final InOrder ordered = inOrder(receiver);
ordered.verify(receiver).process(RECORD1_PART1 + RECORD1_PART2);
ordered.verify(receiver).process(
RECORD1_PART1 +
LINE_SEPARATOR +
RECORD1_PART2 +
LINE_SEPARATOR);

lineRecorder.process(RECORD2_PART1);
lineRecorder.process(RECORD2_PART2);
lineRecorder.process(RECORD2_ENDMARKER);

ordered.verify(receiver).process(RECORD2_PART1 + RECORD2_PART2);
ordered.verify(receiver).process(
RECORD2_PART1 +
LINE_SEPARATOR +
RECORD2_PART2 +
LINE_SEPARATOR);
ordered.verifyNoMoreInteractions();
}

Expand All @@ -81,7 +91,11 @@ public void shouldEmitRecordWithNonDefaultRecordMarker() {
lineRecorder.process(RECORD3_ENDMARKER);

final InOrder ordered = inOrder(receiver);
ordered.verify(receiver).process(RECORD3_PART1 + RECORD3_PART2);
ordered.verify(receiver).process(
RECORD3_PART1 +
LINE_SEPARATOR +
RECORD3_PART2 +
LINE_SEPARATOR);
ordered.verifyNoMoreInteractions();
}

Expand Down