Skip to content

Commit 07e7f0c

Browse files
committed
Reset once, not twice, when resetted once (#543)
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.)
1 parent 04525d9 commit 07e7f0c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public void literal(final String name, final String value) {
212212

213213
@Override
214214
protected void onResetStream() {
215-
pipe.resetStream();
215+
encoder.onResetStream();
216216
}
217217

218218
@Override

metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class MarcXmlEncoderTest {
5151
private static final String RECORD_ID = "92005291";
5252

5353
private static StringBuilder resultCollector;
54+
private static int resultCollectorsResetStreamCount;
5455
private static MarcXmlEncoder encoder;
5556

5657
@Before
@@ -62,6 +63,11 @@ public void setUp() {
6263
public void process(final String obj) {
6364
resultCollector.append(obj);
6465
}
66+
@Override
67+
public void resetStream() {
68+
++resultCollectorsResetStreamCount;
69+
}
70+
6571
});
6672
resultCollector = new StringBuilder();
6773
}
@@ -396,4 +402,19 @@ public void issue543_shouldNotWriteFooterWhenRecordIsEmpty() {
396402
assertTrue(actual.isEmpty());
397403
}
398404

405+
@Test
406+
public void issue543_shouldOnlyResetStreamOnce() {
407+
resultCollectorsResetStreamCount = 0;
408+
encoder.resetStream();
409+
assertEquals(resultCollectorsResetStreamCount, 1);
410+
}
411+
412+
@Test
413+
public void issue543_shouldOnlyResetStreamOnceUsingWrapper() {
414+
resultCollectorsResetStreamCount = 0;
415+
encoder.setEnsureCorrectMarc21Xml(true);
416+
encoder.resetStream();
417+
assertEquals(resultCollectorsResetStreamCount, 1);
418+
}
419+
399420
}

0 commit comments

Comments
 (0)