Skip to content

Commit

Permalink
#291 do not extend UnixSocketClientProviderStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
bsideup committed Feb 21, 2017
1 parent 3d871ab commit c7a4fae
Showing 1 changed file with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.testcontainers.dockerclient;

import com.github.dockerjava.core.DefaultDockerClientConfig;
import com.github.dockerjava.core.DockerClientConfig;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;

import java.io.*;
import java.net.InetSocketAddress;
Expand All @@ -11,11 +14,15 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class NamedPipeSocketClientProviderStrategy extends UnixSocketClientProviderStrategy {
public class NamedPipeSocketClientProviderStrategy extends DockerClientProviderStrategy {

private static final String NAMED_PIPE_FILE_NAME = "\\\\.\\pipe\\docker_engine";
private static final String PING_TIMEOUT_DEFAULT = "10";
private static final String PING_TIMEOUT_PROPERTY_NAME = "testcontainers.namedpipesocketprovider.timeout";

@Override
public void test() throws InvalidConfigurationException {
File file = new File("\\\\.\\pipe\\docker_engine");
File file = new File(NAMED_PIPE_FILE_NAME);

if (!file.exists()) {
throw new InvalidConfigurationException("this strategy only works with named pipe file");
Expand All @@ -38,6 +45,25 @@ public void test() throws InvalidConfigurationException {
}
}

@Override
public String getDescription() {
return "Named pipe socket \"" + NAMED_PIPE_FILE_NAME + "\" (via TCP proxy)";
}

@NotNull
protected DockerClientConfig tryConfiguration(String dockerHost) {
config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost(dockerHost)
.withDockerTlsVerify(false)
.build();
client = getClientForConfig(config);

final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT));
ping(client, timeout);

return config;
}

@Slf4j
static class NamedPipeProxy {

Expand Down

0 comments on commit c7a4fae

Please sign in to comment.