From b20fa77d1ce3b501dc5e69515551acc09fbed8f3 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Wed, 20 Jun 2018 12:58:05 +0200 Subject: [PATCH 1/8] fix repository update with the same settings but different type --- .../repositories/RepositoriesService.java | 2 +- .../RepositoriesServiceTests.java | 100 ++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java diff --git a/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java b/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java index 636e108468e82..e2d2a6a0416fe 100644 --- a/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java +++ b/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java @@ -349,7 +349,7 @@ private boolean registerRepository(RepositoryMetaData repositoryMetaData) throws Repository previous = repositories.get(repositoryMetaData.name()); if (previous != null) { RepositoryMetaData previousMetadata = previous.getMetadata(); - if (!previousMetadata.type().equals(repositoryMetaData.type()) && previousMetadata.settings().equals(repositoryMetaData.settings())) { + if (previousMetadata.type().equals(repositoryMetaData.type()) && previousMetadata.settings().equals(repositoryMetaData.settings())) { // Previous version is the same as this one - ignore it return false; } diff --git a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java new file mode 100644 index 0000000000000..69df01a4576c6 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java @@ -0,0 +1,100 @@ +package org.elasticsearch.repositories;/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse; +import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse; +import org.elasticsearch.client.Client; +import org.elasticsearch.cluster.metadata.RepositoryMetaData; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.env.Environment; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.plugins.RepositoryPlugin; +import org.elasticsearch.repositories.fs.FsRepository; +import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.InternalTestCluster; + +import java.nio.file.Path; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; + +public class RepositoriesServiceTests extends ESIntegTestCase { + + private final static String FAKE_FS_TYPE = "fakeFS"; + + @Override + protected Collection> nodePlugins() { + return Collections.singletonList(TestFSRepositoryPlugin.class); + } + + public static class TestFSRepositoryPlugin extends Plugin implements RepositoryPlugin { + + @Override + public Map getRepositories(final Environment env, final NamedXContentRegistry registry) { + return Collections.singletonMap(FAKE_FS_TYPE, + (metadata) -> new FsRepository(metadata, env, registry)); + } + } + + public void testUpdateRepositoryWithDiffType() { + String repositoryName = "test-repo"; + + Client client = client(); + Settings settings = ((InternalTestCluster) cluster()).getDefaultSettings(); + Path location = randomRepoPath(settings); + + Settings.Builder repoSettings = Settings.builder().put(settings).put("location", location); + + PutRepositoryResponse putRepositoryResponse1 = + client.admin().cluster().preparePutRepository(repositoryName) + .setType(FsRepository.TYPE) + .setSettings(repoSettings) + .get(); + assertThat(putRepositoryResponse1.isAcknowledged(), equalTo(true)); + + GetRepositoriesResponse getRepositoriesResponse1 = + client.admin().cluster().prepareGetRepositories(repositoryName).get(); + + assertThat(getRepositoriesResponse1.repositories(), hasSize(1)); + RepositoryMetaData repositoryMetaData1 = getRepositoriesResponse1.repositories().get(0); + + assertThat(repositoryMetaData1.type(), equalTo(FsRepository.TYPE)); + + // update repository with different + + PutRepositoryResponse putRepositoryResponse2 = + client.admin().cluster().preparePutRepository(repositoryName) + .setType(FAKE_FS_TYPE) + .setSettings(repoSettings) + .get(); + assertThat(putRepositoryResponse2.isAcknowledged(), equalTo(true)); + + GetRepositoriesResponse getRepositoriesResponse2 = + client.admin().cluster().prepareGetRepositories(repositoryName).get(); + + assertThat(getRepositoriesResponse2.repositories(), hasSize(1)); + RepositoryMetaData repositoryMetaData2 = getRepositoriesResponse2.repositories().get(0); + + assertThat(repositoryMetaData2.type(), equalTo(FAKE_FS_TYPE)); + } +} From fc5e94dc4627539958daf3c5cad2d883ea6a89fa Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Wed, 20 Jun 2018 13:07:44 +0200 Subject: [PATCH 2/8] fix comment --- .../repositories/RepositoriesServiceTests.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java index 69df01a4576c6..59b0056ba33bb 100644 --- a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java +++ b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java @@ -1,4 +1,4 @@ -package org.elasticsearch.repositories;/* +/* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright @@ -17,6 +17,8 @@ * under the License. */ +package org.elasticsearch.repositories; + import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse; import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse; import org.elasticsearch.client.Client; @@ -80,7 +82,7 @@ public void testUpdateRepositoryWithDiffType() { assertThat(repositoryMetaData1.type(), equalTo(FsRepository.TYPE)); - // update repository with different + // update repository with different type PutRepositoryResponse putRepositoryResponse2 = client.admin().cluster().preparePutRepository(repositoryName) From 3f606bdbb943ee3f45c3b9c91714743ab3b4de8f Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Wed, 20 Jun 2018 13:31:48 +0200 Subject: [PATCH 3/8] use equals instead of check each property of repo metadata; improve test case --- .../repositories/RepositoriesService.java | 2 +- .../RepositoriesServiceTests.java | 35 ++++++++----------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java b/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java index e2d2a6a0416fe..d5b2a6413e9a9 100644 --- a/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java +++ b/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java @@ -349,7 +349,7 @@ private boolean registerRepository(RepositoryMetaData repositoryMetaData) throws Repository previous = repositories.get(repositoryMetaData.name()); if (previous != null) { RepositoryMetaData previousMetadata = previous.getMetadata(); - if (previousMetadata.type().equals(repositoryMetaData.type()) && previousMetadata.settings().equals(repositoryMetaData.settings())) { + if (previousMetadata.equals(repositoryMetaData)) { // Previous version is the same as this one - ignore it return false; } diff --git a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java index 59b0056ba33bb..3ab56b01b2c48 100644 --- a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java +++ b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java @@ -24,46 +24,35 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.RepositoryMetaData; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.env.Environment; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.plugins.RepositoryPlugin; import org.elasticsearch.repositories.fs.FsRepository; +import org.elasticsearch.snapshots.mockstore.MockRepository; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalTestCluster; import java.nio.file.Path; import java.util.Collection; import java.util.Collections; -import java.util.Map; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.instanceOf; public class RepositoriesServiceTests extends ESIntegTestCase { - private final static String FAKE_FS_TYPE = "fakeFS"; - @Override protected Collection> nodePlugins() { - return Collections.singletonList(TestFSRepositoryPlugin.class); - } - - public static class TestFSRepositoryPlugin extends Plugin implements RepositoryPlugin { - - @Override - public Map getRepositories(final Environment env, final NamedXContentRegistry registry) { - return Collections.singletonMap(FAKE_FS_TYPE, - (metadata) -> new FsRepository(metadata, env, registry)); - } + return Collections.singletonList(MockRepository.Plugin.class); } public void testUpdateRepositoryWithDiffType() { String repositoryName = "test-repo"; Client client = client(); - Settings settings = ((InternalTestCluster) cluster()).getDefaultSettings(); - Path location = randomRepoPath(settings); + InternalTestCluster cluster = (InternalTestCluster) cluster(); + RepositoriesService repositoriesService = cluster.getInstance(RepositoriesService.class); + Settings settings = cluster.getDefaultSettings(); + Path location = randomRepoPath(); Settings.Builder repoSettings = Settings.builder().put(settings).put("location", location); @@ -82,11 +71,14 @@ public void testUpdateRepositoryWithDiffType() { assertThat(repositoryMetaData1.type(), equalTo(FsRepository.TYPE)); + Repository repository1 = repositoriesService.repository(repositoryName); + assertThat(repository1, instanceOf(FsRepository.class)); + // update repository with different type PutRepositoryResponse putRepositoryResponse2 = client.admin().cluster().preparePutRepository(repositoryName) - .setType(FAKE_FS_TYPE) + .setType("mock") .setSettings(repoSettings) .get(); assertThat(putRepositoryResponse2.isAcknowledged(), equalTo(true)); @@ -97,6 +89,9 @@ public void testUpdateRepositoryWithDiffType() { assertThat(getRepositoriesResponse2.repositories(), hasSize(1)); RepositoryMetaData repositoryMetaData2 = getRepositoriesResponse2.repositories().get(0); - assertThat(repositoryMetaData2.type(), equalTo(FAKE_FS_TYPE)); + assertThat(repositoryMetaData2.type(), equalTo("mock")); + + Repository repository2 = repositoriesService.repository(repositoryName); + assertThat(repository2, instanceOf(MockRepository.class)); } } From c3dd0f6c5468aa9b61164bf2442bb78c92138d57 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Wed, 20 Jun 2018 13:59:11 +0200 Subject: [PATCH 4/8] integration test has to be IT; added check for the instance; add some randomization --- ...rviceTests.java => RepositoriesServiceIT.java} | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) rename server/src/test/java/org/elasticsearch/repositories/{RepositoriesServiceTests.java => RepositoriesServiceIT.java} (86%) diff --git a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java similarity index 86% rename from server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java rename to server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java index 3ab56b01b2c48..d8934ce1c927b 100644 --- a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java +++ b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java @@ -37,8 +37,10 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.sameInstance; -public class RepositoriesServiceTests extends ESIntegTestCase { +public class RepositoriesServiceIT extends ESIntegTestCase { @Override protected Collection> nodePlugins() { @@ -74,11 +76,13 @@ public void testUpdateRepositoryWithDiffType() { Repository repository1 = repositoriesService.repository(repositoryName); assertThat(repository1, instanceOf(FsRepository.class)); - // update repository with different type + // update repository + + boolean diffType = randomBoolean(); PutRepositoryResponse putRepositoryResponse2 = client.admin().cluster().preparePutRepository(repositoryName) - .setType("mock") + .setType(diffType ? "mock" : FsRepository.TYPE) .setSettings(repoSettings) .get(); assertThat(putRepositoryResponse2.isAcknowledged(), equalTo(true)); @@ -89,9 +93,10 @@ public void testUpdateRepositoryWithDiffType() { assertThat(getRepositoriesResponse2.repositories(), hasSize(1)); RepositoryMetaData repositoryMetaData2 = getRepositoriesResponse2.repositories().get(0); - assertThat(repositoryMetaData2.type(), equalTo("mock")); + assertThat(repositoryMetaData2.type(), equalTo(diffType ? "mock" : FsRepository.TYPE)); Repository repository2 = repositoriesService.repository(repositoryName); - assertThat(repository2, instanceOf(MockRepository.class)); + assertThat(repository2, instanceOf(diffType ? MockRepository.class : FsRepository.class)); + assertThat(repository2, diffType ? not(sameInstance(repository1)) : sameInstance(repository1)); } } From a857d2b9aa4464d3c99f1de30f40525bba018140 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Wed, 20 Jun 2018 16:52:23 +0200 Subject: [PATCH 5/8] minor test case enhancements --- .../repositories/RepositoriesServiceIT.java | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java index d8934ce1c927b..12ede12b925c0 100644 --- a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java +++ b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java @@ -20,7 +20,6 @@ package org.elasticsearch.repositories; import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse; -import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.RepositoryMetaData; import org.elasticsearch.common.settings.Settings; @@ -34,6 +33,7 @@ import java.util.Collection; import java.util.Collections; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.instanceOf; @@ -47,7 +47,7 @@ protected Collection> nodePlugins() { return Collections.singletonList(MockRepository.Plugin.class); } - public void testUpdateRepositoryWithDiffType() { + public void testUpdateRepository() { String repositoryName = "test-repo"; Client client = client(); @@ -58,45 +58,41 @@ public void testUpdateRepositoryWithDiffType() { Settings.Builder repoSettings = Settings.builder().put(settings).put("location", location); - PutRepositoryResponse putRepositoryResponse1 = - client.admin().cluster().preparePutRepository(repositoryName) + assertAcked(client.admin().cluster().preparePutRepository(repositoryName) .setType(FsRepository.TYPE) .setSettings(repoSettings) - .get(); - assertThat(putRepositoryResponse1.isAcknowledged(), equalTo(true)); + .get()); - GetRepositoriesResponse getRepositoriesResponse1 = + GetRepositoriesResponse originalRetRepositoriesResponse = client.admin().cluster().prepareGetRepositories(repositoryName).get(); - assertThat(getRepositoriesResponse1.repositories(), hasSize(1)); - RepositoryMetaData repositoryMetaData1 = getRepositoriesResponse1.repositories().get(0); + assertThat(originalRetRepositoriesResponse.repositories(), hasSize(1)); + RepositoryMetaData originalRepositoryMetaData = originalRetRepositoriesResponse.repositories().get(0); - assertThat(repositoryMetaData1.type(), equalTo(FsRepository.TYPE)); + assertThat(originalRepositoryMetaData.type(), equalTo(FsRepository.TYPE)); - Repository repository1 = repositoriesService.repository(repositoryName); - assertThat(repository1, instanceOf(FsRepository.class)); + Repository originalRepository = repositoriesService.repository(repositoryName); + assertThat(originalRepository, instanceOf(FsRepository.class)); // update repository - boolean diffType = randomBoolean(); + boolean updated = randomBoolean(); + String updatedRepositoryType = updated ? "mock" : FsRepository.TYPE; - PutRepositoryResponse putRepositoryResponse2 = - client.admin().cluster().preparePutRepository(repositoryName) - .setType(diffType ? "mock" : FsRepository.TYPE) + assertAcked(client.admin().cluster().preparePutRepository(repositoryName) + .setType(updatedRepositoryType) .setSettings(repoSettings) - .get(); - assertThat(putRepositoryResponse2.isAcknowledged(), equalTo(true)); + .get()); - GetRepositoriesResponse getRepositoriesResponse2 = + GetRepositoriesResponse updatedGetRepositoriesResponse = client.admin().cluster().prepareGetRepositories(repositoryName).get(); - assertThat(getRepositoriesResponse2.repositories(), hasSize(1)); - RepositoryMetaData repositoryMetaData2 = getRepositoriesResponse2.repositories().get(0); + assertThat(updatedGetRepositoriesResponse.repositories(), hasSize(1)); + RepositoryMetaData updatedRepositoryMetaData = updatedGetRepositoriesResponse.repositories().get(0); - assertThat(repositoryMetaData2.type(), equalTo(diffType ? "mock" : FsRepository.TYPE)); + assertThat(updatedRepositoryMetaData.type(), equalTo(updatedRepositoryType)); - Repository repository2 = repositoriesService.repository(repositoryName); - assertThat(repository2, instanceOf(diffType ? MockRepository.class : FsRepository.class)); - assertThat(repository2, diffType ? not(sameInstance(repository1)) : sameInstance(repository1)); + Repository updatedRepository = repositoriesService.repository(repositoryName); + assertThat(updatedRepository, updated ? not(sameInstance(originalRepository)) : sameInstance(originalRepository)); } } From 8f7eb41d46f8f8928598a4f4fc222c8acb5aa7d6 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Thu, 21 Jun 2018 11:25:48 +0200 Subject: [PATCH 6/8] make variables final; explicit start a single master node --- .../repositories/RepositoriesServiceIT.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java index 12ede12b925c0..f052b4d82bebf 100644 --- a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java +++ b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java @@ -29,7 +29,6 @@ import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalTestCluster; -import java.nio.file.Path; import java.util.Collection; import java.util.Collections; @@ -40,6 +39,7 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.sameInstance; +@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 0, numClientNodes = 0, supportsDedicatedMasters = false) public class RepositoriesServiceIT extends ESIntegTestCase { @Override @@ -48,51 +48,52 @@ protected Collection> nodePlugins() { } public void testUpdateRepository() { - String repositoryName = "test-repo"; + final InternalTestCluster cluster = internalCluster(); + cluster.startMasterOnlyNode(); - Client client = client(); - InternalTestCluster cluster = (InternalTestCluster) cluster(); - RepositoriesService repositoriesService = cluster.getInstance(RepositoriesService.class); - Settings settings = cluster.getDefaultSettings(); - Path location = randomRepoPath(); + final String repositoryName = "test-repo"; - Settings.Builder repoSettings = Settings.builder().put(settings).put("location", location); + final Client client = client(); + final RepositoriesService repositoriesService = cluster.getInstance(RepositoriesService.class); + final Settings settings = cluster.getDefaultSettings(); + + final Settings.Builder repoSettings = Settings.builder().put(settings).put("location", randomRepoPath()); assertAcked(client.admin().cluster().preparePutRepository(repositoryName) .setType(FsRepository.TYPE) .setSettings(repoSettings) .get()); - GetRepositoriesResponse originalRetRepositoriesResponse = + final GetRepositoriesResponse originalGetRepositoriesResponse = client.admin().cluster().prepareGetRepositories(repositoryName).get(); - assertThat(originalRetRepositoriesResponse.repositories(), hasSize(1)); - RepositoryMetaData originalRepositoryMetaData = originalRetRepositoriesResponse.repositories().get(0); + assertThat(originalGetRepositoriesResponse.repositories(), hasSize(1)); + RepositoryMetaData originalRepositoryMetaData = originalGetRepositoriesResponse.repositories().get(0); assertThat(originalRepositoryMetaData.type(), equalTo(FsRepository.TYPE)); - Repository originalRepository = repositoriesService.repository(repositoryName); + final Repository originalRepository = repositoriesService.repository(repositoryName); assertThat(originalRepository, instanceOf(FsRepository.class)); // update repository - boolean updated = randomBoolean(); - String updatedRepositoryType = updated ? "mock" : FsRepository.TYPE; + final boolean updated = randomBoolean(); + final String updatedRepositoryType = updated ? "mock" : FsRepository.TYPE; assertAcked(client.admin().cluster().preparePutRepository(repositoryName) .setType(updatedRepositoryType) .setSettings(repoSettings) .get()); - GetRepositoriesResponse updatedGetRepositoriesResponse = + final GetRepositoriesResponse updatedGetRepositoriesResponse = client.admin().cluster().prepareGetRepositories(repositoryName).get(); assertThat(updatedGetRepositoriesResponse.repositories(), hasSize(1)); - RepositoryMetaData updatedRepositoryMetaData = updatedGetRepositoriesResponse.repositories().get(0); + final RepositoryMetaData updatedRepositoryMetaData = updatedGetRepositoriesResponse.repositories().get(0); assertThat(updatedRepositoryMetaData.type(), equalTo(updatedRepositoryType)); - Repository updatedRepository = repositoriesService.repository(repositoryName); + final Repository updatedRepository = repositoriesService.repository(repositoryName); assertThat(updatedRepository, updated ? not(sameInstance(originalRepository)) : sameInstance(originalRepository)); } } From f7d1a30f65e61c90b456e40134300e14acd81b8d Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Fri, 22 Jun 2018 12:08:08 +0200 Subject: [PATCH 7/8] do not stuck with a single master case --- .../elasticsearch/repositories/RepositoriesServiceIT.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java index f052b4d82bebf..49164d0658681 100644 --- a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java +++ b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java @@ -39,7 +39,6 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.sameInstance; -@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 0, numClientNodes = 0, supportsDedicatedMasters = false) public class RepositoriesServiceIT extends ESIntegTestCase { @Override @@ -47,14 +46,15 @@ protected Collection> nodePlugins() { return Collections.singletonList(MockRepository.Plugin.class); } - public void testUpdateRepository() { + public void testUpdateRepository() throws Exception { + waitNoPendingTasksOnAll(); final InternalTestCluster cluster = internalCluster(); - cluster.startMasterOnlyNode(); final String repositoryName = "test-repo"; final Client client = client(); - final RepositoriesService repositoriesService = cluster.getInstance(RepositoriesService.class); + final RepositoriesService repositoriesService = + cluster.getDataOrMasterNodeInstances(RepositoriesService.class).iterator().next(); final Settings settings = cluster.getDefaultSettings(); final Settings.Builder repoSettings = Settings.builder().put(settings).put("location", randomRepoPath()); From 4fd7576bbf4af643c594f47d4a3bb85e589bd1d8 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Fri, 22 Jun 2018 15:25:35 +0200 Subject: [PATCH 8/8] final polish --- .../elasticsearch/repositories/RepositoriesServiceIT.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java index 49164d0658681..05c9746aa49ac 100644 --- a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java +++ b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceIT.java @@ -46,8 +46,7 @@ protected Collection> nodePlugins() { return Collections.singletonList(MockRepository.Plugin.class); } - public void testUpdateRepository() throws Exception { - waitNoPendingTasksOnAll(); + public void testUpdateRepository() { final InternalTestCluster cluster = internalCluster(); final String repositoryName = "test-repo"; @@ -57,7 +56,7 @@ public void testUpdateRepository() throws Exception { cluster.getDataOrMasterNodeInstances(RepositoriesService.class).iterator().next(); final Settings settings = cluster.getDefaultSettings(); - final Settings.Builder repoSettings = Settings.builder().put(settings).put("location", randomRepoPath()); + final Settings.Builder repoSettings = Settings.builder().put("location", randomRepoPath()); assertAcked(client.admin().cluster().preparePutRepository(repositoryName) .setType(FsRepository.TYPE) @@ -75,8 +74,6 @@ public void testUpdateRepository() throws Exception { final Repository originalRepository = repositoriesService.repository(repositoryName); assertThat(originalRepository, instanceOf(FsRepository.class)); - // update repository - final boolean updated = randomBoolean(); final String updatedRepositoryType = updated ? "mock" : FsRepository.TYPE;