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

Expand Container dependsOn parameters to accept Iterable #2259

Merged
merged 5 commits into from Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -26,9 +26,6 @@
import lombok.NonNull;
import lombok.Setter;
import lombok.SneakyThrows;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that there seem to be a lot of import movements. I'm not sure why this is suddenly happening, but I'm confident that the .editorconfig rules we have set up are being respected:

[*.java]
indent_style = space
indent_size = 4
# Never use star imports
ij_java_names_count_to_use_import_on_demand = 99
ij_java_class_count_to_use_import_on_demand = 99
ij_java_layout_static_imports_separately = true

Maybe recent edits to these files have not been picking up the rules?

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
Expand All @@ -42,7 +39,6 @@
import org.slf4j.Logger;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.UnstableAPI;
import org.testcontainers.images.ImagePullPolicy;
import org.testcontainers.containers.output.OutputFrame;
import org.testcontainers.containers.startupcheck.IsRunningStartupCheckStrategy;
import org.testcontainers.containers.startupcheck.MinimumDurationRunningStartupCheckStrategy;
Expand All @@ -51,8 +47,8 @@
import org.testcontainers.containers.wait.Wait;
import org.testcontainers.containers.wait.WaitStrategy;
import org.testcontainers.containers.wait.strategy.WaitStrategyTarget;
import org.testcontainers.images.ImagePullPolicy;
import org.testcontainers.images.RemoteDockerImage;
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.lifecycle.Startable;
import org.testcontainers.lifecycle.Startables;
import org.testcontainers.lifecycle.TestDescription;
Expand All @@ -64,14 +60,9 @@
import org.testcontainers.utility.PathUtils;
import org.testcontainers.utility.ResourceReaper;
import org.testcontainers.utility.TestcontainersConfiguration;
import org.testcontainers.utility.ThrowingFunction;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;
Expand All @@ -82,7 +73,6 @@
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -266,22 +256,29 @@ public void setImage(Future<String> image) {
}

/**
* @see #dependsOn(List)
* @see #dependsOn(Iterable)
*/
public SELF dependsOn(Startable... startables) {
Collections.addAll(dependencies, startables);
return self();
}

/**
* @see #dependsOn(Iterable)
*/
public SELF dependsOn(List<? extends Startable> startables) {
return this.dependsOn((Iterable<? extends Startable>) startables);
}

/**
* Delays this container's creation and start until provided {@link Startable}s start first.
* Note that the circular dependencies are not supported.
*
* @param startables a list of {@link Startable} to depend on
* @see Startables#deepStart(Collection)
* @see Startables#deepStart(Iterable)
*/
public SELF dependsOn(List<Startable> startables) {
dependencies.addAll(startables);
public SELF dependsOn(Iterable<? extends Startable> startables) {
Copy link
Member

Choose a reason for hiding this comment

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

this will break binary compatibility

Copy link
Member Author

Choose a reason for hiding this comment

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

Pushing a commit now to reinstate dependsOn(List)

startables.forEach(dependencies::add);
return self();
}

Expand Down
11 changes: 7 additions & 4 deletions core/src/main/java/org/testcontainers/lifecycle/Startables.java
Expand Up @@ -2,12 +2,15 @@

import lombok.experimental.UtilityClass;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

@UtilityClass
public class Startables {
Expand All @@ -27,8 +30,8 @@ public Thread newThread(Runnable r) {
/**
* @see #deepStart(Stream)
*/
public CompletableFuture<Void> deepStart(Collection<? extends Startable> startables) {
return deepStart(startables.stream());
public CompletableFuture<Void> deepStart(Iterable<? extends Startable> startables) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, japicmp has flagged this!

Just as we did in GenericContainer, I'll reinstate the previous method signature for binary compatibility.

Copy link
Member Author

Choose a reason for hiding this comment

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

Reinstated.

return deepStart(StreamSupport.stream(startables.spliterator(), false));
}

/**
Expand Down