Simplify creation of Elasticsearch containers in tests
Remove the ElasticNodeInfo class which is just a wrapper around the container's HTTP hostname and port. Instead we can just use the container and get the hostname and port directly. This reduces the amount of boilerplate code in the tests where the containers are created. Change-Id: I969fb3708ce1616182fa98c1c5bfccca658e1250
This commit is contained in:
@@ -25,18 +25,10 @@ import java.util.UUID;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
public final class ElasticTestUtils {
|
||||
public static class ElasticNodeInfo {
|
||||
public final String hostname;
|
||||
public final int port;
|
||||
|
||||
public ElasticNodeInfo(String hostname, int port) {
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
}
|
||||
}
|
||||
|
||||
public static void configure(
|
||||
Config config, String hostname, int port, String prefix, ElasticVersion version) {
|
||||
Config config, ElasticContainer container, String prefix, ElasticVersion version) {
|
||||
String hostname = container.getHttpHost().getHostName();
|
||||
int port = container.getHttpHost().getPort();
|
||||
config.setEnum("index", null, "type", IndexType.ELASTICSEARCH);
|
||||
config.setString("elasticsearch", null, "server", "http://" + hostname + ":" + port);
|
||||
config.setString("elasticsearch", null, "prefix", prefix);
|
||||
@@ -47,8 +39,8 @@ public final class ElasticTestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void configure(Config config, String hostname, int port, String prefix) {
|
||||
configure(config, hostname, port, prefix, null);
|
||||
public static void configure(Config config, ElasticContainer container, String prefix) {
|
||||
configure(config, container, prefix, null);
|
||||
}
|
||||
|
||||
public static void createAllIndexes(Injector injector) throws IOException {
|
||||
@@ -61,12 +53,9 @@ public final class ElasticTestUtils {
|
||||
|
||||
public static Config getConfig(ElasticVersion version) {
|
||||
ElasticContainer container = ElasticContainer.createAndStart(version);
|
||||
ElasticNodeInfo elasticNodeInfo =
|
||||
new ElasticNodeInfo(
|
||||
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
|
||||
String indicesPrefix = UUID.randomUUID().toString();
|
||||
Config cfg = new Config();
|
||||
configure(cfg, elasticNodeInfo.hostname, elasticNodeInfo.port, indicesPrefix, version);
|
||||
configure(cfg, container, indicesPrefix, version);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
|
||||
import com.google.gerrit.server.query.account.AbstractQueryAccountsTest;
|
||||
import com.google.gerrit.testing.ConfigSuite;
|
||||
import com.google.gerrit.testing.InMemoryModule;
|
||||
@@ -31,20 +30,14 @@ public class ElasticV5QueryAccountsTest extends AbstractQueryAccountsTest {
|
||||
return IndexConfig.createForElasticsearch();
|
||||
}
|
||||
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
if (nodeInfo != null) {
|
||||
// do not start Elasticsearch twice
|
||||
return;
|
||||
if (container == null) {
|
||||
// Only start Elasticsearch once
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
|
||||
nodeInfo =
|
||||
new ElasticNodeInfo(
|
||||
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -65,8 +58,7 @@ public class ElasticV5QueryAccountsTest extends AbstractQueryAccountsTest {
|
||||
Config elasticsearchConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(elasticsearchConfig);
|
||||
String indicesPrefix = getSanitizedMethodName();
|
||||
ElasticTestUtils.configure(
|
||||
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
|
||||
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix, ElasticVersion.V5_6);
|
||||
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
|
||||
import com.google.gerrit.server.query.change.AbstractQueryChangesTest;
|
||||
import com.google.gerrit.testing.ConfigSuite;
|
||||
import com.google.gerrit.testing.InMemoryModule;
|
||||
@@ -31,20 +30,14 @@ public class ElasticV5QueryChangesTest extends AbstractQueryChangesTest {
|
||||
return IndexConfig.createForElasticsearch();
|
||||
}
|
||||
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
if (nodeInfo != null) {
|
||||
// do not start Elasticsearch twice
|
||||
return;
|
||||
if (container == null) {
|
||||
// Only start Elasticsearch once
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
|
||||
nodeInfo =
|
||||
new ElasticNodeInfo(
|
||||
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -65,8 +58,7 @@ public class ElasticV5QueryChangesTest extends AbstractQueryChangesTest {
|
||||
Config elasticsearchConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(elasticsearchConfig);
|
||||
String indicesPrefix = getSanitizedMethodName();
|
||||
ElasticTestUtils.configure(
|
||||
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
|
||||
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix, ElasticVersion.V5_6);
|
||||
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
|
||||
import com.google.gerrit.server.query.group.AbstractQueryGroupsTest;
|
||||
import com.google.gerrit.testing.ConfigSuite;
|
||||
import com.google.gerrit.testing.InMemoryModule;
|
||||
@@ -31,20 +30,14 @@ public class ElasticV5QueryGroupsTest extends AbstractQueryGroupsTest {
|
||||
return IndexConfig.createForElasticsearch();
|
||||
}
|
||||
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
if (nodeInfo != null) {
|
||||
// do not start Elasticsearch twice
|
||||
return;
|
||||
if (container == null) {
|
||||
// Only start Elasticsearch once
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
|
||||
nodeInfo =
|
||||
new ElasticNodeInfo(
|
||||
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -65,8 +58,7 @@ public class ElasticV5QueryGroupsTest extends AbstractQueryGroupsTest {
|
||||
Config elasticsearchConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(elasticsearchConfig);
|
||||
String indicesPrefix = getSanitizedMethodName();
|
||||
ElasticTestUtils.configure(
|
||||
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
|
||||
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix, ElasticVersion.V5_6);
|
||||
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
|
||||
import com.google.gerrit.server.query.project.AbstractQueryProjectsTest;
|
||||
import com.google.gerrit.testing.ConfigSuite;
|
||||
import com.google.gerrit.testing.InMemoryModule;
|
||||
@@ -31,20 +30,14 @@ public class ElasticV5QueryProjectsTest extends AbstractQueryProjectsTest {
|
||||
return IndexConfig.createForElasticsearch();
|
||||
}
|
||||
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
if (nodeInfo != null) {
|
||||
// do not start Elasticsearch twice
|
||||
return;
|
||||
if (container == null) {
|
||||
// Only start Elasticsearch once
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
|
||||
nodeInfo =
|
||||
new ElasticNodeInfo(
|
||||
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -65,8 +58,7 @@ public class ElasticV5QueryProjectsTest extends AbstractQueryProjectsTest {
|
||||
Config elasticsearchConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(elasticsearchConfig);
|
||||
String indicesPrefix = getSanitizedMethodName();
|
||||
ElasticTestUtils.configure(
|
||||
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
|
||||
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix, ElasticVersion.V5_6);
|
||||
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
|
||||
import com.google.gerrit.server.query.account.AbstractQueryAccountsTest;
|
||||
import com.google.gerrit.testing.ConfigSuite;
|
||||
import com.google.gerrit.testing.InMemoryModule;
|
||||
@@ -31,20 +30,14 @@ public class ElasticV6QueryAccountsTest extends AbstractQueryAccountsTest {
|
||||
return IndexConfig.createForElasticsearch();
|
||||
}
|
||||
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
if (nodeInfo != null) {
|
||||
// do not start Elasticsearch twice
|
||||
return;
|
||||
if (container == null) {
|
||||
// Only start Elasticsearch once
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V6_8);
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V6_8);
|
||||
nodeInfo =
|
||||
new ElasticNodeInfo(
|
||||
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -65,8 +58,7 @@ public class ElasticV6QueryAccountsTest extends AbstractQueryAccountsTest {
|
||||
Config elasticsearchConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(elasticsearchConfig);
|
||||
String indicesPrefix = getSanitizedMethodName();
|
||||
ElasticTestUtils.configure(
|
||||
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
|
||||
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix);
|
||||
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
|
||||
import com.google.gerrit.server.query.change.AbstractQueryChangesTest;
|
||||
import com.google.gerrit.testing.ConfigSuite;
|
||||
import com.google.gerrit.testing.InMemoryModule;
|
||||
@@ -36,23 +35,17 @@ public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest {
|
||||
return IndexConfig.createForElasticsearch();
|
||||
}
|
||||
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer container;
|
||||
private static CloseableHttpAsyncClient client;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
if (nodeInfo != null) {
|
||||
// do not start Elasticsearch twice
|
||||
return;
|
||||
if (container == null) {
|
||||
// Only start Elasticsearch once
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V6_8);
|
||||
client = HttpAsyncClients.createDefault();
|
||||
client.start();
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V6_8);
|
||||
nodeInfo =
|
||||
new ElasticNodeInfo(
|
||||
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
|
||||
client = HttpAsyncClients.createDefault();
|
||||
client.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -67,7 +60,8 @@ public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest {
|
||||
client.execute(
|
||||
new HttpPost(
|
||||
String.format(
|
||||
"http://localhost:%d/%s*/_close", nodeInfo.port, getSanitizedMethodName())),
|
||||
"http://localhost:%d/%s*/_close",
|
||||
container.getHttpHost().getPort(), getSanitizedMethodName())),
|
||||
HttpClientContext.create(),
|
||||
null);
|
||||
}
|
||||
@@ -83,8 +77,7 @@ public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest {
|
||||
Config elasticsearchConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(elasticsearchConfig);
|
||||
String indicesPrefix = getSanitizedMethodName();
|
||||
ElasticTestUtils.configure(
|
||||
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
|
||||
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix);
|
||||
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
|
||||
import com.google.gerrit.server.query.group.AbstractQueryGroupsTest;
|
||||
import com.google.gerrit.testing.ConfigSuite;
|
||||
import com.google.gerrit.testing.InMemoryModule;
|
||||
@@ -31,20 +30,14 @@ public class ElasticV6QueryGroupsTest extends AbstractQueryGroupsTest {
|
||||
return IndexConfig.createForElasticsearch();
|
||||
}
|
||||
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
if (nodeInfo != null) {
|
||||
// do not start Elasticsearch twice
|
||||
return;
|
||||
if (container == null) {
|
||||
// Only start Elasticsearch once
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V6_8);
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V6_8);
|
||||
nodeInfo =
|
||||
new ElasticNodeInfo(
|
||||
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -65,8 +58,7 @@ public class ElasticV6QueryGroupsTest extends AbstractQueryGroupsTest {
|
||||
Config elasticsearchConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(elasticsearchConfig);
|
||||
String indicesPrefix = getSanitizedMethodName();
|
||||
ElasticTestUtils.configure(
|
||||
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
|
||||
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix);
|
||||
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
|
||||
import com.google.gerrit.server.query.project.AbstractQueryProjectsTest;
|
||||
import com.google.gerrit.testing.ConfigSuite;
|
||||
import com.google.gerrit.testing.InMemoryModule;
|
||||
@@ -31,20 +30,14 @@ public class ElasticV6QueryProjectsTest extends AbstractQueryProjectsTest {
|
||||
return IndexConfig.createForElasticsearch();
|
||||
}
|
||||
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
if (nodeInfo != null) {
|
||||
// do not start Elasticsearch twice
|
||||
return;
|
||||
if (container == null) {
|
||||
// Only start Elasticsearch once
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V6_8);
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V6_8);
|
||||
nodeInfo =
|
||||
new ElasticNodeInfo(
|
||||
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -65,8 +58,7 @@ public class ElasticV6QueryProjectsTest extends AbstractQueryProjectsTest {
|
||||
Config elasticsearchConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(elasticsearchConfig);
|
||||
String indicesPrefix = getSanitizedMethodName();
|
||||
ElasticTestUtils.configure(
|
||||
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
|
||||
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix);
|
||||
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
|
||||
import com.google.gerrit.server.query.account.AbstractQueryAccountsTest;
|
||||
import com.google.gerrit.testing.ConfigSuite;
|
||||
import com.google.gerrit.testing.InMemoryModule;
|
||||
@@ -31,20 +30,14 @@ public class ElasticV7QueryAccountsTest extends AbstractQueryAccountsTest {
|
||||
return IndexConfig.createForElasticsearch();
|
||||
}
|
||||
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
if (nodeInfo != null) {
|
||||
// do not start Elasticsearch twice
|
||||
return;
|
||||
if (container == null) {
|
||||
// Only start Elasticsearch once
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V7_6);
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V7_6);
|
||||
nodeInfo =
|
||||
new ElasticNodeInfo(
|
||||
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -65,8 +58,7 @@ public class ElasticV7QueryAccountsTest extends AbstractQueryAccountsTest {
|
||||
Config elasticsearchConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(elasticsearchConfig);
|
||||
String indicesPrefix = getSanitizedMethodName();
|
||||
ElasticTestUtils.configure(
|
||||
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
|
||||
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix);
|
||||
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
|
||||
import com.google.gerrit.server.query.change.AbstractQueryChangesTest;
|
||||
import com.google.gerrit.testing.ConfigSuite;
|
||||
import com.google.gerrit.testing.InMemoryModule;
|
||||
@@ -36,23 +35,17 @@ public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
|
||||
return IndexConfig.createForElasticsearch();
|
||||
}
|
||||
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer container;
|
||||
private static CloseableHttpAsyncClient client;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
if (nodeInfo != null) {
|
||||
// do not start Elasticsearch twice
|
||||
return;
|
||||
if (container == null) {
|
||||
// Only start Elasticsearch once
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V7_6);
|
||||
client = HttpAsyncClients.createDefault();
|
||||
client.start();
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V7_6);
|
||||
nodeInfo =
|
||||
new ElasticNodeInfo(
|
||||
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
|
||||
client = HttpAsyncClients.createDefault();
|
||||
client.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -67,7 +60,8 @@ public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
|
||||
client.execute(
|
||||
new HttpPost(
|
||||
String.format(
|
||||
"http://localhost:%d/%s*/_close", nodeInfo.port, getSanitizedMethodName())),
|
||||
"http://localhost:%d/%s*/_close",
|
||||
container.getHttpHost().getPort(), getSanitizedMethodName())),
|
||||
HttpClientContext.create(),
|
||||
null);
|
||||
}
|
||||
@@ -83,8 +77,7 @@ public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
|
||||
Config elasticsearchConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(elasticsearchConfig);
|
||||
String indicesPrefix = getSanitizedMethodName();
|
||||
ElasticTestUtils.configure(
|
||||
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
|
||||
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix);
|
||||
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
|
||||
import com.google.gerrit.server.query.group.AbstractQueryGroupsTest;
|
||||
import com.google.gerrit.testing.ConfigSuite;
|
||||
import com.google.gerrit.testing.InMemoryModule;
|
||||
@@ -31,20 +30,14 @@ public class ElasticV7QueryGroupsTest extends AbstractQueryGroupsTest {
|
||||
return IndexConfig.createForElasticsearch();
|
||||
}
|
||||
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
if (nodeInfo != null) {
|
||||
// do not start Elasticsearch twice
|
||||
return;
|
||||
if (container == null) {
|
||||
// Only start Elasticsearch once
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V7_6);
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V7_6);
|
||||
nodeInfo =
|
||||
new ElasticNodeInfo(
|
||||
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -65,8 +58,7 @@ public class ElasticV7QueryGroupsTest extends AbstractQueryGroupsTest {
|
||||
Config elasticsearchConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(elasticsearchConfig);
|
||||
String indicesPrefix = getSanitizedMethodName();
|
||||
ElasticTestUtils.configure(
|
||||
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
|
||||
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix);
|
||||
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
|
||||
import com.google.gerrit.server.query.project.AbstractQueryProjectsTest;
|
||||
import com.google.gerrit.testing.ConfigSuite;
|
||||
import com.google.gerrit.testing.InMemoryModule;
|
||||
@@ -31,20 +30,14 @@ public class ElasticV7QueryProjectsTest extends AbstractQueryProjectsTest {
|
||||
return IndexConfig.createForElasticsearch();
|
||||
}
|
||||
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
if (nodeInfo != null) {
|
||||
// do not start Elasticsearch twice
|
||||
return;
|
||||
if (container == null) {
|
||||
// Only start Elasticsearch once
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V7_6);
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V7_6);
|
||||
nodeInfo =
|
||||
new ElasticNodeInfo(
|
||||
container.getHttpHost().getHostName(), container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -65,8 +58,7 @@ public class ElasticV7QueryProjectsTest extends AbstractQueryProjectsTest {
|
||||
Config elasticsearchConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(elasticsearchConfig);
|
||||
String indicesPrefix = getSanitizedMethodName();
|
||||
ElasticTestUtils.configure(
|
||||
elasticsearchConfig, nodeInfo.hostname, nodeInfo.port, indicesPrefix);
|
||||
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix);
|
||||
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user