Search in sources :

Example 6 with DockerPort

use of com.palantir.docker.compose.connection.DockerPort in project atlasdb by palantir.

the class QosCassandraEteTestSetup method getAtlasDbConfig.

private static AtlasDbConfig getAtlasDbConfig() {
    DockerPort cassandraPort = docker.containers().container("cassandra").port(CASSANDRA_PORT_NUMBER);
    InetSocketAddress cassandraAddress = new InetSocketAddress(cassandraPort.getIp(), cassandraPort.getExternalPort());
    CassandraKeyValueServiceConfig kvsConfig = ImmutableCassandraKeyValueServiceConfig.builder().servers(ImmutableList.of(cassandraAddress)).credentials(ImmutableCassandraCredentialsConfig.builder().username("cassandra").password("cassandra").build()).ssl(false).replicationFactor(1).autoRefreshNodes(false).build();
    return ImmutableAtlasDbConfig.builder().namespace("qosete").keyValueService(kvsConfig).initializeAsync(true).build();
}
Also used : DockerPort(com.palantir.docker.compose.connection.DockerPort) InetSocketAddress(java.net.InetSocketAddress) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) ImmutableCassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.ImmutableCassandraKeyValueServiceConfig)

Example 7 with DockerPort

use of com.palantir.docker.compose.connection.DockerPort in project atlasdb by palantir.

the class NodesDownTestSetup method killCassandraContainer.

private static void killCassandraContainer(String containerName) throws IOException, InterruptedException {
    CONTAINERS.getContainer(containerName).kill();
    DockerPort containerPort = new DockerPort(containerName, CASSANDRA_THRIFT_PORT, CASSANDRA_THRIFT_PORT);
    Awaitility.waitAtMost(10, TimeUnit.SECONDS).pollInterval(2, TimeUnit.SECONDS).until(() -> !containerPort.isListeningNow());
}
Also used : DockerPort(com.palantir.docker.compose.connection.DockerPort)

Example 8 with DockerPort

use of com.palantir.docker.compose.connection.DockerPort in project nifi-minifi by apache.

the class LogUtil method verifyLogEntries.

public static void verifyLogEntries(String expectedJsonFilename, Container container) throws Exception {
    List<ExpectedLogEntry> expectedLogEntries;
    try (InputStream inputStream = LogUtil.class.getClassLoader().getResourceAsStream(expectedJsonFilename)) {
        List<Map<String, Object>> expected = new ObjectMapper().readValue(inputStream, List.class);
        expectedLogEntries = expected.stream().map(map -> new ExpectedLogEntry(Pattern.compile((String) map.get("pattern")), (int) map.getOrDefault("occurrences", 1))).collect(Collectors.toList());
    }
    DockerPort dockerPort = container.port(8000);
    logger.info("Connecting to external port {} for docker internal port of {}", new Object[] { dockerPort.getExternalPort(), dockerPort.getInternalPort() });
    URL url = new URL("http://" + dockerPort.getIp() + ":" + dockerPort.getExternalPort());
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    try (InputStream inputStream = urlConnection.getInputStream();
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
        String line;
        for (ExpectedLogEntry expectedLogEntry : expectedLogEntries) {
            boolean satisfied = false;
            int occurrences = 0;
            while ((line = bufferedReader.readLine()) != null) {
                if (expectedLogEntry.pattern.matcher(line).find()) {
                    logger.info("Found expected: " + line);
                    if (++occurrences >= expectedLogEntry.numOccurrences) {
                        logger.info("Found target " + occurrences + " times");
                        satisfied = true;
                        break;
                    }
                }
            }
            if (!satisfied) {
                fail("End of log reached without " + expectedLogEntry.numOccurrences + " match(es) of " + expectedLogEntry.pattern);
            }
        }
    } finally {
        urlConnection.disconnect();
    }
}
Also used : DockerPort(com.palantir.docker.compose.connection.DockerPort) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) BufferedReader(java.io.BufferedReader) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 9 with DockerPort

use of com.palantir.docker.compose.connection.DockerPort in project nifi-minifi by apache.

the class AbstractTestSecure method openUrlConnection.

protected HttpsURLConnection openUrlConnection(String url, SSLContext sslContext) throws IOException {
    DockerPort dockerPort = docker.containers().container("squid").port(3128);
    HttpsURLConnection httpURLConnection = (HttpsURLConnection) new URL(url).openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(dockerPort.getIp(), dockerPort.getExternalPort())));
    httpURLConnection.setSSLSocketFactory(sslContext.getSocketFactory());
    return httpURLConnection;
}
Also used : DockerPort(com.palantir.docker.compose.connection.DockerPort) Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) URL(java.net.URL)

Aggregations

DockerPort (com.palantir.docker.compose.connection.DockerPort)9 InetSocketAddress (java.net.InetSocketAddress)4 URL (java.net.URL)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CassandraKeyValueServiceConfig (com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig)1 ImmutableCassandraKeyValueServiceConfig (com.palantir.atlasdb.cassandra.ImmutableCassandraKeyValueServiceConfig)1 Container (com.palantir.docker.compose.connection.Container)1 ConnectionConfig (com.palantir.nexus.db.pool.config.ConnectionConfig)1 ImmutablePostgresConnectionConfig (com.palantir.nexus.db.pool.config.ImmutablePostgresConnectionConfig)1 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 HttpURLConnection (java.net.HttpURLConnection)1 Proxy (java.net.Proxy)1 Map (java.util.Map)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1