Skip to content

Commit

Permalink
explicit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ywelsch committed Dec 6, 2019
1 parent 2fbb88c commit 4069cbe
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,30 @@ public static void corruptFile(Path fileToCorrupt, Logger logger) throws IOExcep
}
}

public void testLoadState() throws IOException {
public void testLoadStateWithoutMissingCustoms() throws IOException {
runLoadStateTest(false, false);
}

public void testLoadStateWithoutMissingCustomsButPreserved() throws IOException {
runLoadStateTest(false, true);
}

public void testLoadStateWithMissingCustomsButPreserved() throws IOException {
runLoadStateTest(true, true);
}

public void testLoadStateWithMissingCustomsAndNotPreserved() throws IOException {
runLoadStateTest(true, false);
}

private void runLoadStateTest(boolean hasMissingCustoms, boolean preserveUnknownCustoms) throws IOException {
final Path[] dirs = new Path[randomIntBetween(1, 5)];
int numStates = randomIntBetween(1, 5);
List<MetaData> meta = new ArrayList<>();
for (int i = 0; i < numStates; i++) {
meta.add(randomMeta());
}
Set<Path> corruptedFiles = new HashSet<>();
final boolean preserveUnknownCustoms = randomBoolean();
MetaDataStateFormat<MetaData> format = metaDataFormat(preserveUnknownCustoms);
for (int i = 0; i < dirs.length; i++) {
dirs[i] = createTempDir();
Expand All @@ -261,13 +276,12 @@ public void testLoadState() throws IOException {
}
List<Path> dirList = Arrays.asList(dirs);
Collections.shuffle(dirList, random());
final boolean hasMissingCustoms = randomBoolean();
MetaData loadedMetaData = format.loadLatestState(logger, hasMissingCustoms ?
NamedXContentRegistry.EMPTY : xContentRegistry(), dirList.toArray(new Path[0]));
MetaData latestMetaData = meta.get(numStates-1);
assertThat(loadedMetaData.clusterUUID(), not(equalTo("_na_")));
assertThat(loadedMetaData.clusterUUID(), equalTo(latestMetaData.clusterUUID()));
ImmutableOpenMap<String,IndexMetaData> indices = loadedMetaData.indices();
ImmutableOpenMap<String, IndexMetaData> indices = loadedMetaData.indices();
assertThat(indices.size(), equalTo(latestMetaData.indices().size()));
for (IndexMetaData original : latestMetaData) {
IndexMetaData deserialized = indices.get(original.getIndex().getName());
Expand Down

0 comments on commit 4069cbe

Please sign in to comment.