Skip to content

Commit 4069cbe

Browse files
committed
explicit tests
1 parent 2fbb88c commit 4069cbe

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

server/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTests.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,30 @@ public static void corruptFile(Path fileToCorrupt, Logger logger) throws IOExcep
235235
}
236236
}
237237

238-
public void testLoadState() throws IOException {
238+
public void testLoadStateWithoutMissingCustoms() throws IOException {
239+
runLoadStateTest(false, false);
240+
}
241+
242+
public void testLoadStateWithoutMissingCustomsButPreserved() throws IOException {
243+
runLoadStateTest(false, true);
244+
}
245+
246+
public void testLoadStateWithMissingCustomsButPreserved() throws IOException {
247+
runLoadStateTest(true, true);
248+
}
249+
250+
public void testLoadStateWithMissingCustomsAndNotPreserved() throws IOException {
251+
runLoadStateTest(true, false);
252+
}
253+
254+
private void runLoadStateTest(boolean hasMissingCustoms, boolean preserveUnknownCustoms) throws IOException {
239255
final Path[] dirs = new Path[randomIntBetween(1, 5)];
240256
int numStates = randomIntBetween(1, 5);
241257
List<MetaData> meta = new ArrayList<>();
242258
for (int i = 0; i < numStates; i++) {
243259
meta.add(randomMeta());
244260
}
245261
Set<Path> corruptedFiles = new HashSet<>();
246-
final boolean preserveUnknownCustoms = randomBoolean();
247262
MetaDataStateFormat<MetaData> format = metaDataFormat(preserveUnknownCustoms);
248263
for (int i = 0; i < dirs.length; i++) {
249264
dirs[i] = createTempDir();
@@ -261,13 +276,12 @@ public void testLoadState() throws IOException {
261276
}
262277
List<Path> dirList = Arrays.asList(dirs);
263278
Collections.shuffle(dirList, random());
264-
final boolean hasMissingCustoms = randomBoolean();
265279
MetaData loadedMetaData = format.loadLatestState(logger, hasMissingCustoms ?
266280
NamedXContentRegistry.EMPTY : xContentRegistry(), dirList.toArray(new Path[0]));
267281
MetaData latestMetaData = meta.get(numStates-1);
268282
assertThat(loadedMetaData.clusterUUID(), not(equalTo("_na_")));
269283
assertThat(loadedMetaData.clusterUUID(), equalTo(latestMetaData.clusterUUID()));
270-
ImmutableOpenMap<String,IndexMetaData> indices = loadedMetaData.indices();
284+
ImmutableOpenMap<String, IndexMetaData> indices = loadedMetaData.indices();
271285
assertThat(indices.size(), equalTo(latestMetaData.indices().size()));
272286
for (IndexMetaData original : latestMetaData) {
273287
IndexMetaData deserialized = indices.get(original.getIndex().getName());

0 commit comments

Comments
 (0)