From 07e7f0c56cf5e193852e309f6631e430f13165f8 Mon Sep 17 00:00:00 2001 From: Pascal Christoph Date: Fri, 27 Sep 2024 15:03:19 +0200 Subject: [PATCH] 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.) --- .../biblio/marc21/MarcXmlEncoder.java | 2 +- .../biblio/marc21/MarcXmlEncoderTest.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java index e754bb70..3113a324 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java @@ -212,7 +212,7 @@ public void literal(final String name, final String value) { @Override protected void onResetStream() { - pipe.resetStream(); + encoder.onResetStream(); } @Override diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java index 5b979e5a..2e1c8df2 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java @@ -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 @@ -62,6 +63,11 @@ public void setUp() { public void process(final String obj) { resultCollector.append(obj); } + @Override + public void resetStream() { + ++resultCollectorsResetStreamCount; + } + }); resultCollector = new StringBuilder(); } @@ -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); + } + }