private static InetSocketAddress connect(DockerComposeRule docker, int dbPort) { try { if (docker == null) { throw new IllegalStateException("Docker compose rule cannot be run, is null."); } else { docker.before(); return InetSocketAddress.createUnresolved( docker.containers().ip(), docker.hostNetworkedPort(dbPort).getExternalPort()); } } catch (IOException | InterruptedException | IllegalStateException e) { throw new RuntimeException("Could not run docker compose rule.", e); } }
public Builder waitingForHostNetworkedPort(int port, HealthCheck<DockerPort> healthCheck, ReadableDuration timeout) { ClusterHealthCheck clusterHealthCheck = transformingHealthCheck(cluster -> new DockerPort(cluster.ip(), port, port), healthCheck); return addClusterWait(new ClusterWait(clusterHealthCheck, timeout)); }
public Builder waitingForHostNetworkedPort(int port, HealthCheck<DockerPort> healthCheck, ReadableDuration timeout) { ClusterHealthCheck clusterHealthCheck = transformingHealthCheck(cluster -> new DockerPort(cluster.ip(), port, port), healthCheck); return addClusterWait(new ClusterWait(clusterHealthCheck, timeout)); }
public Builder waitingForHostNetworkedPort(int port, HealthCheck<DockerPort> healthCheck, ReadableDuration timeout) { ClusterHealthCheck clusterHealthCheck = transformingHealthCheck(cluster -> new DockerPort(cluster.ip(), port, port), healthCheck); return addClusterWait(new ClusterWait(clusterHealthCheck, timeout)); }
private Object dockerPort(Class<?> parameterContext, Cluster cluster, Port port) { Container container = cluster.container(port.container()); Preconditions.checkNotNull(container, "Could not find container '%s'", port.container()); DockerPort dockerPort = container.port(port.internalPort()); Preconditions.checkNotNull(container, "Could not find internalPort '%s' for container '%s'", port.internalPort(), port.container()); if (InetSocketAddress.class.isAssignableFrom(parameterContext)) { try { final InetAddress address = InetAddress.getByName(cluster.ip()); return new InetSocketAddress(address, dockerPort.getExternalPort()); } catch (UnknownHostException e) { throw new ParameterResolutionException("Could not resolve ip", e); } } else if (Integer.class.equals(parameterContext)) { return dockerPort.getExternalPort(); } else if (int.class.equals(parameterContext)) { return dockerPort.getExternalPort(); } else { return null; } }