Skip to content

Commit

Permalink
Tests: Add logic to handle static index upgrade case where index is
Browse files Browse the repository at this point in the history
already on latest version.

See #9207
  • Loading branch information
rjernst committed Jan 9, 2015
1 parent d226a97 commit 4cda543
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.bwcompat;

import org.elasticsearch.Version;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
Expand Down Expand Up @@ -94,9 +95,16 @@ void assertOldIndexWorks(String index) throws Exception {
assertBasicSearchWorks();
assertRealtimeGetWorks();
assertNewReplicasWork();
assertUpgradeWorks();
assertUpgradeWorks(isLatestLuceneVersion(index));
unloadIndex();
}

boolean isLatestLuceneVersion(String index) {
String versionStr = index.substring(index.indexOf('-') + 1, index.lastIndexOf('.'));
Version version = Version.fromString(versionStr);
return version.luceneVersion.major == Version.CURRENT.luceneVersion.major &&
version.luceneVersion.minor == Version.CURRENT.luceneVersion.minor;
}

void assertBasicSearchWorks() {
SearchRequestBuilder searchReq = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery());
Expand Down Expand Up @@ -147,10 +155,12 @@ void assertNewReplicasWork() {
.execute().actionGet());
}

void assertUpgradeWorks() throws Exception {
void assertUpgradeWorks(boolean alreadyLatest) throws Exception {
HttpRequestBuilder httpClient = httpClient();

UpgradeTest.assertNotUpgraded(httpClient, "test");
if (alreadyLatest == false) {
UpgradeTest.assertNotUpgraded(httpClient, "test");
}
UpgradeTest.runUpgrade(httpClient, "test", "wait_for_completion", "true");
UpgradeTest.assertUpgraded(httpClient, "test");
}
Expand Down
Expand Up @@ -204,7 +204,9 @@ public static void assertUpgraded(HttpRequestBuilder httpClient, String index) t
for (ShardSegments segs : shard.getShards()) {
for (Segment seg : segs.getSegments()) {
assertEquals("Index " + indexSegments.getIndex() + " has unupgraded segment " + seg.toString(),
Version.CURRENT.luceneVersion, seg.version);
Version.CURRENT.luceneVersion.major, seg.version.major);
assertEquals("Index " + indexSegments.getIndex() + " has unupgraded segment " + seg.toString(),
Version.CURRENT.luceneVersion.minor, seg.version.minor);
}
}
}
Expand Down

0 comments on commit 4cda543

Please sign in to comment.