diff --git a/aeron-system-tests/src/test/java/io/aeron/cluster/ClusterToolTest.java b/aeron-system-tests/src/test/java/io/aeron/cluster/ClusterToolTest.java index 7c333b2bc3..5140b28aec 100644 --- a/aeron-system-tests/src/test/java/io/aeron/cluster/ClusterToolTest.java +++ b/aeron-system-tests/src/test/java/io/aeron/cluster/ClusterToolTest.java @@ -15,6 +15,7 @@ */ package io.aeron.cluster; +import io.aeron.test.CapturingPrintStream; import io.aeron.test.EventLogExtension; import io.aeron.test.InterruptAfter; import io.aeron.test.InterruptingTestCallback; @@ -38,7 +39,6 @@ import java.util.regex.Pattern; import static io.aeron.test.cluster.TestCluster.aCluster; -import static java.nio.charset.StandardCharsets.US_ASCII; import static java.nio.file.StandardOpenOption.CREATE_NEW; import static java.nio.file.StandardOpenOption.WRITE; import static org.hamcrest.MatcherAssert.assertThat; @@ -437,29 +437,4 @@ private void testSeedRecordingLogFromSnapshot(final Path emptyClusterDir, final // e.g. expected: <2021-09-27T09:49:22.756944756Z> but was: <2021-09-27T09:49:22.756944Z> assertEquals(logLastModifiedTime.toMillis(), Files.getLastModifiedTime(backupLogFile).toMillis()); } - - static class CapturingPrintStream - { - private final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - private final PrintStream printStream = new PrintStream(byteArrayOutputStream); - - PrintStream resetAndGetPrintStream() - { - byteArrayOutputStream.reset(); - return printStream; - } - - String flushAndGetContent() - { - printStream.flush(); - try - { - return byteArrayOutputStream.toString(US_ASCII.name()); - } - catch (final UnsupportedEncodingException ex) - { - throw new RuntimeException(ex); - } - } - } } diff --git a/aeron-test-support/src/main/java/io/aeron/test/CapturingPrintStream.java b/aeron-test-support/src/main/java/io/aeron/test/CapturingPrintStream.java new file mode 100644 index 0000000000..d319468514 --- /dev/null +++ b/aeron-test-support/src/main/java/io/aeron/test/CapturingPrintStream.java @@ -0,0 +1,39 @@ +/* + * Copyright 2014-2024 Real Logic Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.aeron.test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import static java.nio.charset.StandardCharsets.US_ASCII; + +public class CapturingPrintStream +{ + private final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + private final PrintStream printStream = new PrintStream(byteArrayOutputStream); + + public PrintStream resetAndGetPrintStream() + { + byteArrayOutputStream.reset(); + return printStream; + } + + public String flushAndGetContent() + { + printStream.flush(); + return byteArrayOutputStream.toString(US_ASCII); + } +}