From 4cda543637b1a5dab51864129be241b9eadfef72 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Fri, 9 Jan 2015 12:07:06 -0800 Subject: [PATCH] Tests: Add logic to handle static index upgrade case where index is already on latest version. See #9207 --- .../OldIndexBackwardsCompatibilityTests.java | 16 +++++++++++++--- .../admin/indices/upgrade/UpgradeTest.java | 4 +++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java b/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java index 958b2c5838d..d1aba0a031d 100644 --- a/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java +++ b/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java @@ -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; @@ -94,9 +95,16 @@ public class OldIndexBackwardsCompatibilityTests extends StaticIndexBackwardComp 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()); @@ -147,10 +155,12 @@ public class OldIndexBackwardsCompatibilityTests extends StaticIndexBackwardComp .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"); } diff --git a/src/test/java/org/elasticsearch/rest/action/admin/indices/upgrade/UpgradeTest.java b/src/test/java/org/elasticsearch/rest/action/admin/indices/upgrade/UpgradeTest.java index bc32c60de46..fcf8baa4965 100644 --- a/src/test/java/org/elasticsearch/rest/action/admin/indices/upgrade/UpgradeTest.java +++ b/src/test/java/org/elasticsearch/rest/action/admin/indices/upgrade/UpgradeTest.java @@ -204,7 +204,9 @@ public class UpgradeTest extends ElasticsearchBackwardsCompatIntegrationTest { 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); } } }