Elasticsearch: Unharcode localhost for container's

No longer hardcode the docker container hostname for the Elasticsearch
tests. Use the hostname that was dynamically resolved from the running
ElasticContainer (the 'testcontainer') instead.

This is so that tests running upon non-localhost named containers may
pass like in the localhost case.

Change-Id: I9dbd8b76bd7b22004d1d2327bb4c8395907ff223
This commit is contained in:
Marco Miller
2020-04-01 14:18:29 -04:00
parent 7d59b457f8
commit 22aa30d2c3
13 changed files with 68 additions and 32 deletions

View File

@@ -26,16 +26,19 @@ import org.eclipse.jgit.lib.Config;
public final class ElasticTestUtils {
public static class ElasticNodeInfo {
public final String hostname;
public final int port;
public ElasticNodeInfo(int port) {
public ElasticNodeInfo(String hostname, int port) {
this.hostname = hostname;
this.port = port;
}
}
public static void configure(Config config, int port, String prefix, ElasticVersion version) {
public static void configure(
Config config, String hostname, int port, String prefix, ElasticVersion version) {
config.setEnum("index", null, "type", IndexType.ELASTICSEARCH);
config.setString("elasticsearch", null, "server", "http://localhost:" + port);
config.setString("elasticsearch", null, "server", "http://" + hostname + ":" + port);
config.setString("elasticsearch", null, "prefix", prefix);
config.setInt("index", null, "maxLimit", 10000);
String password = version == ElasticVersion.V5_6 ? "changeme" : null;
@@ -44,8 +47,8 @@ public final class ElasticTestUtils {
}
}
public static void configure(Config config, int port, String prefix) {
configure(config, port, prefix, null);
public static void configure(Config config, String hostname, int port, String prefix) {
configure(config, hostname, port, prefix, null);
}
public static void createAllIndexes(Injector injector) throws IOException {
@@ -57,12 +60,13 @@ public final class ElasticTestUtils {
}
public static Config getConfig(ElasticVersion version) {
ElasticNodeInfo elasticNodeInfo;
ElasticContainer container = ElasticContainer.createAndStart(version);
elasticNodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
ElasticNodeInfo elasticNodeInfo =
new ElasticNodeInfo(
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
String indicesPrefix = UUID.randomUUID().toString();
Config cfg = new Config();
configure(cfg, elasticNodeInfo.port, indicesPrefix, version);
configure(cfg, elasticNodeInfo.hostname, elasticNodeInfo.port, indicesPrefix, version);
return cfg;
}

View File

@@ -42,7 +42,9 @@ public class ElasticV5QueryAccountsTest extends AbstractQueryAccountsTest {
}
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
nodeInfo =
new ElasticNodeInfo(
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
}
@AfterClass
@@ -64,7 +66,7 @@ public class ElasticV5QueryAccountsTest extends AbstractQueryAccountsTest {
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName();
ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
}
}

View File

@@ -42,7 +42,9 @@ public class ElasticV5QueryChangesTest extends AbstractQueryChangesTest {
}
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
nodeInfo =
new ElasticNodeInfo(
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
}
@AfterClass
@@ -64,7 +66,7 @@ public class ElasticV5QueryChangesTest extends AbstractQueryChangesTest {
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName();
ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
}
}

View File

@@ -42,7 +42,9 @@ public class ElasticV5QueryGroupsTest extends AbstractQueryGroupsTest {
}
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
nodeInfo =
new ElasticNodeInfo(
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
}
@AfterClass
@@ -64,7 +66,7 @@ public class ElasticV5QueryGroupsTest extends AbstractQueryGroupsTest {
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName();
ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
}
}

View File

@@ -42,7 +42,9 @@ public class ElasticV5QueryProjectsTest extends AbstractQueryProjectsTest {
}
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
nodeInfo =
new ElasticNodeInfo(
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
}
@AfterClass
@@ -64,7 +66,7 @@ public class ElasticV5QueryProjectsTest extends AbstractQueryProjectsTest {
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName();
ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
}
}

View File

@@ -42,7 +42,9 @@ public class ElasticV6QueryAccountsTest extends AbstractQueryAccountsTest {
}
container = ElasticContainer.createAndStart(ElasticVersion.V6_8);
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
nodeInfo =
new ElasticNodeInfo(
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
}
@AfterClass
@@ -63,7 +65,8 @@ public class ElasticV6QueryAccountsTest extends AbstractQueryAccountsTest {
Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
}
}

View File

@@ -48,7 +48,9 @@ public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest {
}
container = ElasticContainer.createAndStart(ElasticVersion.V6_8);
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
nodeInfo =
new ElasticNodeInfo(
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
client = HttpAsyncClients.createDefault();
client.start();
}
@@ -81,7 +83,8 @@ public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest {
Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
}
}

View File

@@ -42,7 +42,9 @@ public class ElasticV6QueryGroupsTest extends AbstractQueryGroupsTest {
}
container = ElasticContainer.createAndStart(ElasticVersion.V6_8);
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
nodeInfo =
new ElasticNodeInfo(
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
}
@AfterClass
@@ -63,7 +65,8 @@ public class ElasticV6QueryGroupsTest extends AbstractQueryGroupsTest {
Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
}
}

View File

@@ -42,7 +42,9 @@ public class ElasticV6QueryProjectsTest extends AbstractQueryProjectsTest {
}
container = ElasticContainer.createAndStart(ElasticVersion.V6_8);
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
nodeInfo =
new ElasticNodeInfo(
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
}
@AfterClass
@@ -63,7 +65,8 @@ public class ElasticV6QueryProjectsTest extends AbstractQueryProjectsTest {
Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
}
}

View File

@@ -42,7 +42,9 @@ public class ElasticV7QueryAccountsTest extends AbstractQueryAccountsTest {
}
container = ElasticContainer.createAndStart(ElasticVersion.V7_6);
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
nodeInfo =
new ElasticNodeInfo(
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
}
@AfterClass
@@ -63,7 +65,8 @@ public class ElasticV7QueryAccountsTest extends AbstractQueryAccountsTest {
Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
}
}

View File

@@ -48,7 +48,9 @@ public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
}
container = ElasticContainer.createAndStart(ElasticVersion.V7_6);
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
nodeInfo =
new ElasticNodeInfo(
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
client = HttpAsyncClients.createDefault();
client.start();
}
@@ -81,7 +83,8 @@ public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
}
}

View File

@@ -42,7 +42,9 @@ public class ElasticV7QueryGroupsTest extends AbstractQueryGroupsTest {
}
container = ElasticContainer.createAndStart(ElasticVersion.V7_6);
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
nodeInfo =
new ElasticNodeInfo(
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
}
@AfterClass
@@ -63,7 +65,8 @@ public class ElasticV7QueryGroupsTest extends AbstractQueryGroupsTest {
Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
}
}

View File

@@ -42,7 +42,9 @@ public class ElasticV7QueryProjectsTest extends AbstractQueryProjectsTest {
}
container = ElasticContainer.createAndStart(ElasticVersion.V7_6);
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
nodeInfo =
new ElasticNodeInfo(
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
}
@AfterClass
@@ -63,7 +65,8 @@ public class ElasticV7QueryProjectsTest extends AbstractQueryProjectsTest {
Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
}
}