33import com .github .dockerjava .api .DockerClient ;
44import com .github .dockerjava .api .command .CreateContainerCmd ;
55import com .github .dockerjava .api .command .InspectContainerResponse ;
6- import com .github .dockerjava .api .model .Bind ;
7- import com .github .dockerjava .api .model .ContainerNetwork ;
8- import com .github .dockerjava .api .model .ExposedPort ;
9- import com .github .dockerjava .api .model .HostConfig ;
10- import com .github .dockerjava .api .model .Info ;
11- import com .github .dockerjava .api .model .Link ;
12- import com .github .dockerjava .api .model .PortBinding ;
13- import com .github .dockerjava .api .model .Volume ;
14- import com .github .dockerjava .api .model .VolumesFrom ;
6+ import com .github .dockerjava .api .model .*;
157import com .google .common .base .Strings ;
16- import lombok .AccessLevel ;
17- import lombok .Data ;
18- import lombok .EqualsAndHashCode ;
19- import lombok .NonNull ;
20- import lombok .Setter ;
21- import lombok .SneakyThrows ;
8+ import lombok .*;
229import org .apache .commons .compress .archivers .tar .TarArchiveInputStream ;
2310import org .apache .commons .compress .archivers .tar .TarArchiveOutputStream ;
2411import org .apache .commons .compress .utils .IOUtils ;
3219import org .rnorth .ducttape .unreliables .Unreliables ;
3320import org .rnorth .visibleassertions .VisibleAssertions ;
3421import org .slf4j .Logger ;
35- import org .slf4j .profiler .Profiler ;
3622import org .testcontainers .DockerClientFactory ;
3723import org .testcontainers .containers .output .FrameConsumerResultCallback ;
3824import org .testcontainers .containers .output .OutputFrame ;
5137import org .testcontainers .lifecycle .TestLifecycleAware ;
5238import org .testcontainers .utility .*;
5339
54- import java .io .ByteArrayInputStream ;
55- import java .io .ByteArrayOutputStream ;
56- import java .io .File ;
57- import java .io .FileOutputStream ;
58- import java .io .IOException ;
59- import java .io .InputStream ;
40+ import java .io .*;
6041import java .nio .charset .Charset ;
6142import java .nio .file .Path ;
6243import java .time .Duration ;
63- import java .util .ArrayList ;
64- import java .util .Arrays ;
65- import java .util .Collections ;
66- import java .util .HashMap ;
67- import java .util .HashSet ;
68- import java .util .LinkedHashSet ;
69- import java .util .List ;
70- import java .util .Map ;
71- import java .util .Optional ;
72- import java .util .Set ;
44+ import java .util .*;
7345import java .util .concurrent .Future ;
7446import java .util .concurrent .TimeUnit ;
7547import java .util .concurrent .atomic .AtomicInteger ;
@@ -229,11 +201,7 @@ public void start() {
229201 }
230202
231203 protected void doStart () {
232- Profiler profiler = new Profiler ("Container startup" );
233- profiler .setLogger (logger ());
234-
235204 try {
236- profiler .start ("Prepare container configuration and host configuration" );
237205 configure ();
238206
239207 logger ().debug ("Starting container: {}" , getDockerImageName ());
@@ -242,24 +210,21 @@ protected void doStart() {
242210 AtomicInteger attempt = new AtomicInteger (0 );
243211 Unreliables .retryUntilSuccess (startupAttempts , () -> {
244212 logger ().debug ("Trying to start container: {} (attempt {}/{})" , image .get (), attempt .incrementAndGet (), startupAttempts );
245- tryStart (profiler . startNested ( "Container startup attempt" ) );
213+ tryStart ();
246214 return true ;
247215 });
248216
249217 } catch (Exception e ) {
250218 throw new ContainerLaunchException ("Container startup failed" , e );
251- } finally {
252- profiler .stop ().log ();
253219 }
254220 }
255221
256- private void tryStart (Profiler profiler ) {
222+ private void tryStart () {
257223 try {
258224 String dockerImageName = image .get ();
259225 logger ().debug ("Starting container: {}" , dockerImageName );
260226
261227 logger ().info ("Creating container for image: {}" , dockerImageName );
262- profiler .start ("Create container" );
263228 CreateContainerCmd createCommand = dockerClient .createContainerCmd (dockerImageName );
264229 applyConfiguration (createCommand );
265230
@@ -272,7 +237,6 @@ private void tryStart(Profiler profiler) {
272237 containerIsCreated (containerId );
273238
274239 logger ().info ("Starting container with ID: {}" , containerId );
275- profiler .start ("Start container" );
276240 dockerClient .startContainerCmd (containerId ).exec ();
277241
278242 // For all registered output consumers, start following as close to container startup as possible
@@ -281,22 +245,18 @@ private void tryStart(Profiler profiler) {
281245 logger ().info ("Container {} is starting: {}" , dockerImageName , containerId );
282246
283247 // Tell subclasses that we're starting
284- profiler .start ("Inspecting container" );
285248 containerInfo = dockerClient .inspectContainerCmd (containerId ).exec ();
286249 containerName = containerInfo .getName ();
287- profiler .start ("Call containerIsStarting on subclasses" );
288250 containerIsStarting (containerInfo );
289251
290252 // Wait until the container is running (may not be fully started)
291- profiler .start ("Wait until container has started properly, or there's evidence it failed to start." );
292253
293254 if (!this .startupCheckStrategy .waitUntilStartupSuccessful (dockerClient , containerId )) {
294255 // Bail out, don't wait for the port to start listening.
295256 // (Exception thrown here will be caught below and wrapped)
296257 throw new IllegalStateException ("Container did not start correctly." );
297258 }
298259
299- profiler .start ("Wait until container started properly" );
300260 waitUntilContainerStarted ();
301261
302262 logger ().info ("Container {} started" , dockerImageName );
@@ -321,8 +281,6 @@ private void tryStart(Profiler profiler) {
321281 }
322282
323283 throw new ContainerLaunchException ("Could not create/start container" , e );
324- } finally {
325- profiler .stop ();
326284 }
327285 }
328286
@@ -455,7 +413,7 @@ public Set<Integer> getLivenessCheckPortNumbers() {
455413 private void applyConfiguration (CreateContainerCmd createCommand ) {
456414 HostConfig hostConfig = buildHostConfig ();
457415 createCommand .withHostConfig (hostConfig );
458-
416+
459417 // Set up exposed ports (where there are no host port bindings defined)
460418 ExposedPort [] portArray = exposedPorts .stream ()
461419 .map (ExposedPort ::new )
@@ -1166,7 +1124,7 @@ public SELF withStartupAttempts(int attempts) {
11661124 }
11671125
11681126 /**
1169- * Allow low level modifications of {@link CreateContainerCmd} after it was pre-configured in {@link #tryStart(Profiler )}.
1127+ * Allow low level modifications of {@link CreateContainerCmd} after it was pre-configured in {@link #tryStart()}.
11701128 * Invocation happens eagerly on a moment when container is created.
11711129 * Warning: this does expose the underlying docker-java API so might change outside of our control.
11721130 *
0 commit comments