- 
                Notifications
    
You must be signed in to change notification settings  - Fork 25
 
#345: Replace ExitGuard in integration tests #438
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
base: main
Are you sure you want to change the base?
Conversation
| 
               | 
          ||
| import com.exasol.mavenprojectversiongetter.MavenProjectVersionGetter; | ||
| 
               | 
          ||
| class JarLauncher | 
There was a problem hiding this comment.
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(); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| final Path jarPath = getExecutableJar(); | |
| final Path jarPath = getExecutableJarPath(); | 
| } | ||
| } | ||
| 
               | 
          ||
| private static Path getExecutableJar() | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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())); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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()); | 
There was a problem hiding this comment.
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; | 
There was a problem hiding this comment.
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() | 
There was a problem hiding this comment.
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); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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)); | 
There was a problem hiding this comment.
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."); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
        
          
                product/src/test/java/org/itsallcode/openfasttrace/cli/JarLauncher.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      | { | ||
| return Path.of("target") | ||
| .resolve(Objects.requireNonNull(jarNameTemplate, "jarNameTemplate") | ||
| .formatted(getCurrentProjectVersion())) | 
There was a problem hiding this comment.
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) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public void waitUntilTerminated(final Duration timeout) | |
| public void assertExpectationsAfterTerminated(final Duration timeout) | 
Closes #345.