From 57f4f32d4d2c53767cdc21e1211254c5433bb191 Mon Sep 17 00:00:00 2001 From: Marco Miller Date: Wed, 1 Apr 2020 11:28:35 -0400 Subject: [PATCH 1/6] Documentation: Fix contributions link in CLA page Community: Issue 12313 Change-Id: I67256ab3ec912750662c8209524ace5ec43a4836 --- Documentation/dev-cla.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/dev-cla.txt b/Documentation/dev-cla.txt index 267351f279..5bc34a7737 100644 --- a/Documentation/dev-cla.txt +++ b/Documentation/dev-cla.txt @@ -1,6 +1,6 @@ = Gerrit Code Review - Contributor License Agreement -In order to link::dev-community.html#how-to-contribute[contribute] to +In order to link:dev-community.html#how-to-contribute[contribute] to Gerrit a Contributor License Agreement must be completed before contributions are accepted. To view and accept the agreements do the following: From 0b0a0892d5f286be7870ab8b716f446ad11ca15d Mon Sep 17 00:00:00 2001 From: Marco Miller Date: Wed, 1 Apr 2020 12:03:57 -0400 Subject: [PATCH 2/6] Documentation: Group contribution links in How-to Remove the duplicated contribution links, so that this page solely points to its related How-to section for all such processes. Community: Issue 12313 Change-Id: I8f004718d111f61901b5659565fc70bbd8f8f8c6 --- Documentation/dev-community.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Documentation/dev-community.txt b/Documentation/dev-community.txt index a49706452b..c787561b93 100644 --- a/Documentation/dev-community.txt +++ b/Documentation/dev-community.txt @@ -17,10 +17,7 @@ link:dev-cla.html[contributor's agreement] on file with the project. * link:dev-design.html[System Design] * Processes ** link:dev-processes.html#project-governance[Project Governance / Engineering Steering Committee] -** link:dev-contributing.html#contribution-processes[Contribution Processes] -*** link:dev-contributing.html#lightweight-contribution-process[Lightweight Contribution Process] -*** link:dev-contributing.html#design-driven-contribution-process[Design-Driven Contribution Process] -*** link:dev-contributing.html#mentorship[Mentorship] +** link:#how-to-contribute[Contribution Processes] ** link:dev-design-docs.html#review[Design doc reviews] ** link:dev-processes.html#dev-in-stable-branches[Development in stable branches] ** link:dev-processes.html#backporting[Backporting to stable branches] From 22aa30d2c30ebc253bab36a7e5120c4ed823beed Mon Sep 17 00:00:00 2001 From: Marco Miller Date: Wed, 1 Apr 2020 14:18:29 -0400 Subject: [PATCH 3/6] 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 --- .../elasticsearch/ElasticTestUtils.java | 20 +++++++++++-------- .../ElasticV5QueryAccountsTest.java | 6 ++++-- .../ElasticV5QueryChangesTest.java | 6 ++++-- .../ElasticV5QueryGroupsTest.java | 6 ++++-- .../ElasticV5QueryProjectsTest.java | 6 ++++-- .../ElasticV6QueryAccountsTest.java | 7 +++++-- .../ElasticV6QueryChangesTest.java | 7 +++++-- .../ElasticV6QueryGroupsTest.java | 7 +++++-- .../ElasticV6QueryProjectsTest.java | 7 +++++-- .../ElasticV7QueryAccountsTest.java | 7 +++++-- .../ElasticV7QueryChangesTest.java | 7 +++++-- .../ElasticV7QueryGroupsTest.java | 7 +++++-- .../ElasticV7QueryProjectsTest.java | 7 +++++-- 13 files changed, 68 insertions(+), 32 deletions(-) diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticTestUtils.java b/javatests/com/google/gerrit/elasticsearch/ElasticTestUtils.java index 020a15834c..236ab66da4 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticTestUtils.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticTestUtils.java @@ -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; } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryAccountsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryAccountsTest.java index c8ce54a792..fb41de4270 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryAccountsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryAccountsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryChangesTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryChangesTest.java index cfdfa983d0..2dd2363c53 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryChangesTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryChangesTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryGroupsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryGroupsTest.java index 832a7bd7fc..5cef866b38 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryGroupsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryGroupsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryProjectsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryProjectsTest.java index 29d3fa416a..186802a9f2 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryProjectsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryProjectsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryAccountsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryAccountsTest.java index 191b83ceb7..3f44e1e436 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryAccountsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryAccountsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java index 94c5a04901..f6139dd4af 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryGroupsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryGroupsTest.java index 8bc57675e0..094afb28a7 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryGroupsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryGroupsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryProjectsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryProjectsTest.java index de8e922b57..faec8cf99b 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryProjectsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryProjectsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryAccountsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryAccountsTest.java index 826473f2c0..d6bdeb9baf 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryAccountsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryAccountsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryChangesTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryChangesTest.java index 43a2dfc46e..82b20ccbb3 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryChangesTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryChangesTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryGroupsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryGroupsTest.java index 0954e603c2..854a0a4840 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryGroupsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryGroupsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryProjectsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryProjectsTest.java index e6d78770dd..3bbcfe6527 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryProjectsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryProjectsTest.java @@ -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)); } } From 89a9a041ac1e926e7dd2008cc6444a9ceed5f914 Mon Sep 17 00:00:00 2001 From: Nguyen Tuan Khang Phan Date: Tue, 31 Mar 2020 17:37:22 -0400 Subject: [PATCH 4/6] Add debug logs for automatic account creation case Replace commented line with an explicit log trace. Change-Id: I49f373ac884501a17dbc0bc271d20ca7f27628e8 --- java/com/google/gerrit/server/account/AccountManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/java/com/google/gerrit/server/account/AccountManager.java b/java/com/google/gerrit/server/account/AccountManager.java index 75c55cd889..713c1c4b8a 100644 --- a/java/com/google/gerrit/server/account/AccountManager.java +++ b/java/com/google/gerrit/server/account/AccountManager.java @@ -136,7 +136,9 @@ public class AccountManager { try { Optional optionalExtId = externalIds.get(who.getExternalIdKey()); if (!optionalExtId.isPresent()) { - // New account, automatically create and return. + logger.atFine().log( + "External ID for account %s not found. A new account will be automatically created.", + who.getUserName()); return create(who); } From 4036283acf085dca9a7b4c3d62c81f822462968a Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 2 Apr 2020 09:36:27 +0900 Subject: [PATCH 5/6] 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 --- .../elasticsearch/ElasticTestUtils.java | 23 +++++-------------- .../ElasticV5QueryAccountsTest.java | 16 ++++--------- .../ElasticV5QueryChangesTest.java | 16 ++++--------- .../ElasticV5QueryGroupsTest.java | 16 ++++--------- .../ElasticV5QueryProjectsTest.java | 16 ++++--------- .../ElasticV6QueryAccountsTest.java | 16 ++++--------- .../ElasticV6QueryChangesTest.java | 23 +++++++------------ .../ElasticV6QueryGroupsTest.java | 16 ++++--------- .../ElasticV6QueryProjectsTest.java | 16 ++++--------- .../ElasticV7QueryAccountsTest.java | 16 ++++--------- .../ElasticV7QueryChangesTest.java | 23 +++++++------------ .../ElasticV7QueryGroupsTest.java | 16 ++++--------- .../ElasticV7QueryProjectsTest.java | 16 ++++--------- 13 files changed, 62 insertions(+), 167 deletions(-) diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticTestUtils.java b/javatests/com/google/gerrit/elasticsearch/ElasticTestUtils.java index 236ab66da4..2d99cbf4af 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticTestUtils.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticTestUtils.java @@ -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; } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryAccountsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryAccountsTest.java index fb41de4270..cb192cdc65 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryAccountsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryAccountsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryChangesTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryChangesTest.java index 2dd2363c53..c4d0c18840 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryChangesTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryChangesTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryGroupsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryGroupsTest.java index 5cef866b38..f1fb60c758 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryGroupsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryGroupsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryProjectsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryProjectsTest.java index 186802a9f2..4dd0e9895a 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryProjectsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV5QueryProjectsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryAccountsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryAccountsTest.java index 3f44e1e436..bb79655219 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryAccountsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryAccountsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java index f6139dd4af..cd46bf1065 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryGroupsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryGroupsTest.java index 094afb28a7..a966dfaded 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryGroupsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryGroupsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryProjectsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryProjectsTest.java index faec8cf99b..40bee586cf 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryProjectsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryProjectsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryAccountsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryAccountsTest.java index d6bdeb9baf..4a5345aa29 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryAccountsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryAccountsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryChangesTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryChangesTest.java index 82b20ccbb3..c8514e827d 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryChangesTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryChangesTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryGroupsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryGroupsTest.java index 854a0a4840..6b979b331a 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryGroupsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryGroupsTest.java @@ -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)); } } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryProjectsTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryProjectsTest.java index 3bbcfe6527..4106d8b756 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryProjectsTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryProjectsTest.java @@ -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)); } } From 6e8615737f79ace4acecda1211ce12831bcf2206 Mon Sep 17 00:00:00 2001 From: Luca Milanesio Date: Thu, 2 Apr 2020 11:15:18 +0100 Subject: [PATCH 6/6] Do not assume ES is running on localhost in tests Remove references to http://localhost when closing the ES indexes during tests. Change-Id: I7c11cb8078bfcf5a8b7a337d764dcb90f7efbf42 --- .../gerrit/elasticsearch/ElasticV6QueryChangesTest.java | 6 ++++-- .../gerrit/elasticsearch/ElasticV7QueryChangesTest.java | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java index cd46bf1065..f1dcbaf63c 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java @@ -60,8 +60,10 @@ public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest { client.execute( new HttpPost( String.format( - "http://localhost:%d/%s*/_close", - container.getHttpHost().getPort(), getSanitizedMethodName())), + "http://%s:%d/%s*/_close", + container.getHttpHost().getHostName(), + container.getHttpHost().getPort(), + getSanitizedMethodName())), HttpClientContext.create(), null); } diff --git a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryChangesTest.java b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryChangesTest.java index c8514e827d..704f2f1284 100644 --- a/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryChangesTest.java +++ b/javatests/com/google/gerrit/elasticsearch/ElasticV7QueryChangesTest.java @@ -60,8 +60,10 @@ public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest { client.execute( new HttpPost( String.format( - "http://localhost:%d/%s*/_close", - container.getHttpHost().getPort(), getSanitizedMethodName())), + "http://%s:%d/%s*/_close", + container.getHttpHost().getHostName(), + container.getHttpHost().getPort(), + getSanitizedMethodName())), HttpClientContext.create(), null); }