Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed trimming of the recorded test output #2040

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions core/src/testFixtures/java/org/lflang/tests/LFTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,16 @@ private Thread recordStream(StringBuffer builder, InputStream inputStream) {
int len;
char[] buf = new char[1024];
while ((len = reader.read(buf)) > 0) {
if (Runtime.getRuntime().freeMemory() < Runtime.getRuntime().totalMemory() / 2) {
builder.append(buf, 0, len);
// If the buffer gets too large, then we delete the first half of the buffer
// and trim it down in size. It is important to decide what "too large" means.
// Here we take 1/4 of the total memory available to the Java runtime as a rule of
// thumb.
if (builder.length() > Runtime.getRuntime().totalMemory() / 4) {
builder.delete(0, builder.length() / 2);
builder.insert(0, "[earlier messages were removed to free up memory]%n");
builder.insert(0, "[earlier messages were removed to free up memory]\n");
builder.trimToSize();
}
builder.append(buf, 0, len);
}
} catch (IOException e) {
throw new RuntimeIOException(e);
Expand Down