Skip to content

Commit

Permalink
Reset once, not twice, when resetted once (#543)
Browse files Browse the repository at this point in the history
By not calling the pipe (aka wrapper) but the receiver directly
the stream is only once resetted when called once.

(In conjunction with ObjectFileWriter and StreamBatchResetter this bug
had resulted in as many empty files as non-empty ones.)
  • Loading branch information
dr0i committed Sep 30, 2024
1 parent 04525d9 commit 07e7f0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void literal(final String name, final String value) {

@Override
protected void onResetStream() {
pipe.resetStream();
encoder.onResetStream();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class MarcXmlEncoderTest {
private static final String RECORD_ID = "92005291";

private static StringBuilder resultCollector;
private static int resultCollectorsResetStreamCount;
private static MarcXmlEncoder encoder;

@Before
Expand All @@ -62,6 +63,11 @@ public void setUp() {
public void process(final String obj) {
resultCollector.append(obj);
}
@Override
public void resetStream() {
++resultCollectorsResetStreamCount;
}

});
resultCollector = new StringBuilder();
}
Expand Down Expand Up @@ -396,4 +402,19 @@ public void issue543_shouldNotWriteFooterWhenRecordIsEmpty() {
assertTrue(actual.isEmpty());
}

@Test
public void issue543_shouldOnlyResetStreamOnce() {
resultCollectorsResetStreamCount = 0;
encoder.resetStream();
assertEquals(resultCollectorsResetStreamCount, 1);
}

@Test
public void issue543_shouldOnlyResetStreamOnceUsingWrapper() {
resultCollectorsResetStreamCount = 0;
encoder.setEnsureCorrectMarc21Xml(true);
encoder.resetStream();
assertEquals(resultCollectorsResetStreamCount, 1);
}

}

0 comments on commit 07e7f0c

Please sign in to comment.