Skip to content

Commit ec76043

Browse files
committed
fix tests
1 parent c7011a6 commit ec76043

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

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

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.elasticsearch.common.xcontent.ToXContent;
4040
import org.elasticsearch.common.xcontent.ToXContentFragment;
4141
import org.elasticsearch.common.xcontent.XContentBuilder;
42-
import org.elasticsearch.common.xcontent.XContentFactory;
4342
import org.elasticsearch.common.xcontent.XContentParser;
4443
import org.elasticsearch.index.Index;
4544
import org.elasticsearch.test.ESTestCase;
@@ -237,7 +236,6 @@ public static void corruptFile(Path file, Logger logger) throws IOException {
237236
public void testLoadState() throws IOException {
238237
final Path[] dirs = new Path[randomIntBetween(1, 5)];
239238
int numStates = randomIntBetween(1, 5);
240-
int numLegacy = randomIntBetween(0, numStates);
241239
List<MetaData> meta = new ArrayList<>();
242240
for (int i = 0; i < numStates; i++) {
243241
meta.add(randomMeta());
@@ -247,20 +245,7 @@ public void testLoadState() throws IOException {
247245
for (int i = 0; i < dirs.length; i++) {
248246
dirs[i] = createTempDir();
249247
Files.createDirectories(dirs[i].resolve(MetaDataStateFormat.STATE_DIR_NAME));
250-
for (int j = 0; j < numLegacy; j++) {
251-
if (randomBoolean() && (j < numStates - 1 || dirs.length > 0 && i != 0)) {
252-
Path file = dirs[i].resolve(MetaDataStateFormat.STATE_DIR_NAME).resolve("global-"+j);
253-
Files.createFile(file); // randomly create 0-byte files -- there is extra logic to skip them
254-
} else {
255-
try (XContentBuilder xcontentBuilder = XContentFactory.contentBuilder(MetaDataStateFormat.FORMAT,
256-
Files.newOutputStream(dirs[i].resolve(MetaDataStateFormat.STATE_DIR_NAME).resolve("global-" + j)))) {
257-
xcontentBuilder.startObject();
258-
MetaData.Builder.toXContent(meta.get(j), xcontentBuilder, ToXContent.EMPTY_PARAMS);
259-
xcontentBuilder.endObject();
260-
}
261-
}
262-
}
263-
for (int j = numLegacy; j < numStates; j++) {
248+
for (int j = 0; j < numStates; j++) {
264249
format.write(meta.get(j), dirs[i]);
265250
if (randomBoolean() && (j < numStates - 1 || dirs.length > 0 && i != 0)) { // corrupt a file that we do not necessarily need here....
266251
Path file = dirs[i].resolve(MetaDataStateFormat.STATE_DIR_NAME).resolve("global-" + j + ".st");
@@ -290,20 +275,18 @@ public void testLoadState() throws IOException {
290275
assertThat(loadedMetaData.indexGraveyard(), equalTo(latestMetaData.indexGraveyard()));
291276

292277
// now corrupt all the latest ones and make sure we fail to load the state
293-
if (numStates > numLegacy) {
294-
for (int i = 0; i < dirs.length; i++) {
295-
Path file = dirs[i].resolve(MetaDataStateFormat.STATE_DIR_NAME).resolve("global-" + (numStates-1) + ".st");
296-
if (corruptedFiles.contains(file)) {
297-
continue;
298-
}
299-
MetaDataStateFormatTests.corruptFile(file, logger);
300-
}
301-
try {
302-
format.loadLatestState(logger, xContentRegistry(), dirList.toArray(new Path[0]));
303-
fail("latest version can not be read");
304-
} catch (ElasticsearchException ex) {
305-
assertThat(ExceptionsHelper.unwrap(ex, CorruptStateException.class), notNullValue());
278+
for (int i = 0; i < dirs.length; i++) {
279+
Path file = dirs[i].resolve(MetaDataStateFormat.STATE_DIR_NAME).resolve("global-" + (numStates-1) + ".st");
280+
if (corruptedFiles.contains(file)) {
281+
continue;
306282
}
283+
MetaDataStateFormatTests.corruptFile(file, logger);
284+
}
285+
try {
286+
format.loadLatestState(logger, xContentRegistry(), dirList.toArray(new Path[0]));
287+
fail("latest version can not be read");
288+
} catch (ElasticsearchException ex) {
289+
assertThat(ExceptionsHelper.unwrap(ex, CorruptStateException.class), notNullValue());
307290
}
308291
}
309292

0 commit comments

Comments
 (0)