Skip to content

Commit

Permalink
Still honor WaitStrategy in Hollow modes
Browse files Browse the repository at this point in the history
  • Loading branch information
aguibert committed Feb 8, 2020
1 parent 4b1b72e commit 0a733ff
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,20 @@
import org.microshed.testing.ManuallyStartedConfiguration;
import org.microshed.testing.testcontainers.config.HollowTestcontainersConfiguration;
import org.microshed.testing.testcontainers.config.TestcontainersConfiguration;
import org.microshed.testing.testcontainers.internal.HollowContainerInspection;
import org.microshed.testing.testcontainers.internal.ImageFromDockerfile;
import org.microshed.testing.testcontainers.spi.ServerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.containers.wait.strategy.WaitStrategy;
import org.testcontainers.utility.Base58;

import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.dockerjava.api.command.InspectImageResponse;
import com.github.dockerjava.api.model.ExposedPort;

Expand Down Expand Up @@ -267,6 +270,8 @@ protected void doStart() {
Map<String, String> env = getEnvMap();
if (env.size() > 0)
getServerAdapter().setConfigProperties(env);
configure();
waitUntilContainerStarted();
lateBind_started = true;
return;
}
Expand Down Expand Up @@ -357,8 +362,13 @@ public ApplicationContainer withReadinessPath(String readinessUrl) {
public ApplicationContainer withReadinessPath(String readinessUrl, int timeoutSeconds) {
Objects.requireNonNull(readinessUrl);
readinessUrl = buildPath(readinessUrl);
waitingFor(Wait.forHttp(readinessUrl)
.withStartupTimeout(Duration.ofSeconds(timeoutSeconds)));
HttpWaitStrategy strat = Wait.forHttp(readinessUrl);
strat.withStartupTimeout(Duration.ofSeconds(timeoutSeconds));
getExposedPorts()
.stream()
.findFirst()
.ifPresent(p -> strat.forPort(p));
waitingFor(strat);
return this;
}

Expand Down Expand Up @@ -464,6 +474,22 @@ public String getBaseURL() {
return "http://" + getContainerIpAddress() + ':' + getFirstMappedPort();
}

@Override
public InspectContainerResponse getContainerInfo() {
if (isHollow)
return new HollowContainerInspection(this);
else
return super.getContainerInfo();
}

@Override
public String getDockerImageName() {
if (isHollow)
return "HollowApplicationContainer";
else
return super.getDockerImageName();
}

/**
* @return The {@link ServerAdapter} that is currently applied for this instance
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2020 IBM Corporation and others
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.microshed.testing.testcontainers.internal;

import org.microshed.testing.testcontainers.ApplicationContainer;

import com.github.dockerjava.api.command.InspectContainerResponse;

public class HollowContainerInspection extends InspectContainerResponse {

private final ApplicationContainer app;

public HollowContainerInspection(ApplicationContainer app) {
this.app = app;
}

@Override
public String getName() {
return app.getDockerImageName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class HollowTestcontainersConfigurationTest2 {
// This cointainer never actually gets started, since we are running in hollow mode
@Container
public static ApplicationContainer app = new ApplicationContainer(Paths.get("src", "test", "resources", "Dockerfile"))
.withExposedPorts(9443)
.withExposedPorts(9443) // ignored because port explicitly set via microshed_http_port
.withAppContextRoot("/myservice");

@Test
Expand Down

0 comments on commit 0a733ff

Please sign in to comment.