From 1a6491bc5420a14ec81363ba227146dd70259d46 Mon Sep 17 00:00:00 2001 From: Jay Modi Date: Mon, 19 Jun 2017 14:52:32 -0600 Subject: [PATCH] Test: do not copy secure settings when creating random directory service (#25297) In tests, we sometimes create a random directory service and as part of that the IndexSettings get built again. When we build them again, we need to make sure we do not set the secure settings on the new IndexMetaData object that gets created as the node settings already have the secure settings and the index settings and node settings will be combined. If both have secure settings, the settings builder will throw an AlreadySetException. --- .../test/store/MockFSDirectoryService.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/store/MockFSDirectoryService.java b/test/framework/src/main/java/org/elasticsearch/test/store/MockFSDirectoryService.java index 281dbb5115f..a37d4a28ee0 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/store/MockFSDirectoryService.java +++ b/test/framework/src/main/java/org/elasticsearch/test/store/MockFSDirectoryService.java @@ -97,7 +97,7 @@ public class MockFSDirectoryService extends FsDirectoryService { logger.debug("Using MockDirWrapper with seed [{}] throttle: [{}] crashIndex: [{}]", SeedUtils.formatSeed(seed), throttle, crashIndex); } - delegateService = randomDirectorService(indexStore, path); + delegateService = randomDirectoryService(indexStore, path); } @@ -162,9 +162,14 @@ public class MockFSDirectoryService extends FsDirectoryService { return w; } - private FsDirectoryService randomDirectorService(IndexStore indexStore, ShardPath path) { + private FsDirectoryService randomDirectoryService(IndexStore indexStore, ShardPath path) { final IndexSettings indexSettings = indexStore.getIndexSettings(); - final IndexMetaData build = IndexMetaData.builder(indexSettings.getIndexMetaData()).settings(Settings.builder().put(indexSettings.getSettings()).put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), RandomPicks.randomFrom(random, IndexModule.Type.values()).getSettingsKey())).build(); + final IndexMetaData build = IndexMetaData.builder(indexSettings.getIndexMetaData()) + .settings(Settings.builder() + .put(indexSettings.getSettings().getAsMap()) // do not copy the secure settings as they will be copied again later on! + .put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), + RandomPicks.randomFrom(random, IndexModule.Type.values()).getSettingsKey())) + .build(); final IndexSettings newIndexSettings = new IndexSettings(build, indexSettings.getNodeSettings()); return new FsDirectoryService(newIndexSettings, indexStore, path); }