Skip to content

Conversation

@kaklakariada
Copy link
Contributor

@kaklakariada kaklakariada commented Jan 19, 2025

Closes #345.

@kaklakariada kaklakariada changed the title #345: Add Jar Launcher #345: Replace ExitGuard in integration tests Jan 19, 2025

import com.exasol.mavenprojectversiongetter.MavenProjectVersionGetter;

class JarLauncher
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this class deserves a bit of documentation in the header. :-)


public static JarLauncher start(final Path workingDir, final List<String> args)
{
final Path jarPath = getExecutableJar();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final Path jarPath = getExecutableJar();
final Path jarPath = getExecutableJarPath();

}
}

private static Path getExecutableJar()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static Path getExecutableJar()
private static Path getExecutableJarPath()

"Executable JAR not found at %s. Run 'mvn -T1C package -DskipTests' to build it.");
}
final List<String> command = new ArrayList<>();
command.addAll(asList(getJavaExecutable().toString(), "-jar", getExecutableJar().toString()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
command.addAll(asList(getJavaExecutable().toString(), "-jar", getExecutableJar().toString()));
command.addAll(List.of(getJavaExecutable().toString(), "-jar", getExecutableJar().toString()));

{
return runnable -> {
final Thread thread = new Thread(runnable);
thread.setName(ProcessOutputConsumer.class.getSimpleName());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense to name the thread after the process being consumed? Or at least to get that processes identification into the name? Thread names are mainly a debugging means as far as I remember.

{
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)))
{
String line = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strings are immutable. Does reusing it have any runtime benefit in this case? I would assume not, since the memory will be freshly allocated with each new assignment.

return builder.toString();
}

void streamFinished()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming an attribute and a method the same is a recipe for confusion.
Please rename the method. Use an imperative. :-)


private static class ProcessStreamConsumer
{
private final CountDownLatch streamFinished = new CountDownLatch(1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private final CountDownLatch streamFinished = new CountDownLatch(1);
private final CountDownLatch streamFinishedLatch = new CountDownLatch(1);


void accept(final String line)
{
LOG.fine("%s > %s".formatted(name, line));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consuming without logging might be a good option, since we are in tests here and don't want to flood the test log.

if (!Files.exists(jarPath))
{
throw new IllegalStateException(
"Executable JAR not found at %s. Run 'mvn -T1C package -DskipTests' to build it.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

{
return Path.of("target")
.resolve(Objects.requireNonNull(jarNameTemplate, "jarNameTemplate")
.formatted(getCurrentProjectVersion()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a tiny bit hard to read if you don't remember the %s in the template. But I can live with it.

.orElseThrow(() -> new IllegalStateException("Java executable not found"));
}

public void waitUntilTerminated(final Duration timeout)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void waitUntilTerminated(final Duration timeout)
public void assertExpectationsAfterTerminated(final Duration timeout)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace tests using security manager

3 participants