Skip to content

Commit

Permalink
[Java] Move CapturingPrintStream to test-support.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeb01 committed Sep 19, 2024
1 parent 883336c commit 25c6b60
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 25c6b60

Please sign in to comment.