/** Specify the {@link WaitStrategy} to use to determine if the container is ready. * * @see org.testcontainers.containers.wait.strategy.Wait#defaultWaitStrategy() * @param serviceName the name of the service to wait for * @param waitStrategy the WaitStrategy to use * @return this */ public SELF waitingFor(String serviceName, @NonNull WaitStrategy waitStrategy) { String serviceInstanceName = getServiceInstanceName(serviceName); addWaitStrategy(serviceInstanceName, waitStrategy); return self(); }
public SELF withExposedService(String serviceName, int servicePort, @NonNull WaitStrategy waitStrategy) { String serviceInstanceName = getServiceInstanceName(serviceName); /* * For every service/port pair that needs to be exposed, we register a target on an 'ambassador container'. * * The ambassador container's role is to link (within the Docker network) to one of the * compose services, and proxy TCP network I/O out to a port that the ambassador container * exposes. * * This avoids the need for the docker compose file to explicitly expose ports on all the * services. * * {@link GenericContainer} should ensure that the ambassador container is on the same network * as the rest of the compose environment. */ // Ambassador container will be started together after docker compose has started int ambassadorPort = nextAmbassadorPort.getAndIncrement(); ambassadorPortMappings.computeIfAbsent(serviceInstanceName, __ -> new ConcurrentHashMap<>()).put(servicePort, ambassadorPort); ambassadorContainer.withTarget(ambassadorPort, serviceInstanceName, servicePort); ambassadorContainer.addLink(new FutureContainer(this.project + "_" + serviceInstanceName), serviceInstanceName); addWaitStrategy(serviceInstanceName, waitStrategy); return self(); }