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 958b2c5838dae..d1aba0a031dbd 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 @@ 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()); @@ -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"); } 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 bc32c60de4615..fcf8baa496587 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 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); } } }