Skip to content

Commit

Permalink
Minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wendigo authored and losipiuk committed Sep 29, 2020
1 parent 8b7c21f commit 6344360
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Integer call()
return ExitCode.OK;
}

private void killContainersReaperContainer()
private static void killContainersReaperContainer()
{
try (DockerClient dockerClient = DockerClientFactory.lazyClient()) {
log.info("Killing the testcontainers reaper container (Ryuk) so that environment can stay alive");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ public Integer call()
Suite suite = suiteFactory.getSuite(suiteName);
EnvironmentConfig config = configFactory.getConfig(this.config);

out.println(format("Suite '%s' with configuration '%s' consists of following test runs: ", suiteName, this.config));
out.printf("Suite '%s' with configuration '%s' consists of following test runs: \n", suiteName, this.config);

for (SuiteTestRun testRun : suite.getTestRuns(config)) {
TestRun.TestRunOptions runOptions = createTestRunOptions(suiteName, testRun, config);
out.println(format("\n%s test run %s\n", environmentOptions.launcherBin, OptionsPrinter.format(environmentOptions, runOptions)));
out.printf("\n%s test run %s\n\n", environmentOptions.launcherBin, OptionsPrinter.format(environmentOptions, runOptions));
}

return OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public Integer call()
return getFailedCount(testRunsResults) == 0 ? ExitCode.OK : ExitCode.SOFTWARE;
}

private int printTestRunsSummary(String suiteName, List<TestRunResult> results)
private void printTestRunsSummary(String suiteName, List<TestRunResult> results)
{
long failedRuns = getFailedCount(results);

Expand All @@ -191,8 +191,6 @@ private int printTestRunsSummary(String suiteName, List<TestRunResult> results)
results.stream()
.filter(TestRunResult::hasFailed)
.forEach(Execution::printTestRunSummary);

return failedRuns == 0L ? 0 : 1;
}

private static long getFailedCount(List<TestRunResult> results)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public synchronized String getDockerFilesHostPath()

public String getDockerFilesHostPath(String file)
{
checkArgument(file != null && !file.isEmpty() && !file.startsWith("/"), "Invalid file: %s", file);
checkArgument(file != null && !file.isEmpty() && !(file.charAt(0) == '/'), "Invalid file: %s", file);
Path filePath = Paths.get(getDockerFilesHostPath()).resolve(file);
checkArgument(Files.exists(filePath), "'%s' resolves to '%s', but it does not exist", file, filePath);
return filePath.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.github.dockerjava.api.model.HostConfig;
import com.github.dockerjava.api.model.Ulimit;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Streams;
Expand Down Expand Up @@ -50,6 +49,7 @@
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkState;
Expand Down Expand Up @@ -99,7 +99,7 @@ public Environment start()

return Failsafe
.with(retryPolicy)
.get(() -> tryStart());
.get(this::tryStart);
}

public List<String> getContainerNames()
Expand Down Expand Up @@ -169,8 +169,6 @@ public void awaitContainersStopped()
}

log.warn("Some of the containers are stopped or unhealthy");

return;
}
catch (InterruptedException e) {
log.info("Interrupted");
Expand Down Expand Up @@ -374,8 +372,8 @@ public Builder containerDependsOnRest(String logicalName)
containers.entrySet()
.stream()
.filter(entry -> !entry.getKey().equals(logicalName))
.map(entry -> entry.getValue())
.forEach(dependant -> container.dependsOn(dependant));
.map(Map.Entry::getValue)
.forEach(container::dependsOn);

return this;
}
Expand Down Expand Up @@ -449,11 +447,11 @@ private Environment build(Optional<EnvironmentListener> listener)
switch (outputMode) {
case DISCARD:
log.warn("Containers logs are not printed to stdout");
setContainerOutputConsumer(this::discardContainerLogs);
setContainerOutputConsumer(Environment.Builder::discardContainerLogs);
break;

case PRINT:
setContainerOutputConsumer(this::printContainerLogs);
setContainerOutputConsumer(Environment.Builder::printContainerLogs);
break;

case PRINT_WRITE:
Expand Down Expand Up @@ -485,7 +483,7 @@ private Environment build(Optional<EnvironmentListener> listener)
return new Environment(name, startupRetries, containers, listener);
}

private Consumer<OutputFrame> writeContainerLogs(DockerContainer container, Path path)
private static Consumer<OutputFrame> writeContainerLogs(DockerContainer container, Path path)
{
Path containerLogFile = path.resolve(container.getLogicalName() + "/container.log");
log.info("Writing container %s logs to %s", container, containerLogFile);
Expand All @@ -499,7 +497,7 @@ private Consumer<OutputFrame> writeContainerLogs(DockerContainer container, Path
}
}

private Consumer<OutputFrame> printContainerLogs(DockerContainer container)
private static Consumer<OutputFrame> printContainerLogs(DockerContainer container)
{
try {
// write directly to System.out, bypassing logging & io.airlift.log.Logging#rewireStdStreams
Expand All @@ -512,13 +510,13 @@ private Consumer<OutputFrame> printContainerLogs(DockerContainer container)
}
}

private Consumer<OutputFrame> discardContainerLogs(DockerContainer container)
private static Consumer<OutputFrame> discardContainerLogs(DockerContainer container)
{
// Discard log frames
return outputFrame -> {};
}

private Consumer<OutputFrame> combineConsumers(Consumer<OutputFrame>... consumers)
private static Consumer<OutputFrame> combineConsumers(Consumer<OutputFrame>... consumers)
{
return outputFrame -> Arrays.stream(consumers).forEach(consumer -> consumer.accept(outputFrame));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static List<Class<? extends EnvironmentConfig>> findConfigsByBasePackage(
return ClassPath.from(Environments.class.getClassLoader()).getTopLevelClassesRecursive(packageName).stream()
.map(ClassPath.ClassInfo::load)
.filter(clazz -> !isAbstract(clazz.getModifiers()))
.filter(clazz -> EnvironmentConfig.class.isAssignableFrom(clazz))
.filter(EnvironmentConfig.class::isAssignableFrom)
.map(clazz -> (Class<? extends EnvironmentConfig>) clazz.asSubclass(EnvironmentConfig.class))
.collect(toImmutableList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static List<Class<? extends Suite>> findSuitesByPackageName(String packag
return ClassPath.from(Environments.class.getClassLoader()).getTopLevelClassesRecursive(packageName).stream()
.map(ClassPath.ClassInfo::load)
.filter(clazz -> !isAbstract(clazz.getModifiers()))
.filter(clazz -> Suite.class.isAssignableFrom(clazz))
.filter(Suite.class::isAssignableFrom)
.map(clazz -> (Class<? extends Suite>) clazz.asSubclass(Suite.class))
.collect(toImmutableList());
}
Expand Down

0 comments on commit 6344360

Please sign in to comment.