Skip to content

Commit

Permalink
Tests: Add upgrade step to static bwc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rjernst committed Jan 8, 2015
1 parent 060f963 commit 7f9ffea
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@

package org.elasticsearch.bwcompat;

import org.apache.lucene.index.IndexFormatTooOldException;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.rest.action.admin.indices.upgrade.UpgradeTest;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import org.elasticsearch.test.rest.client.http.HttpRequestBuilder;
import org.hamcrest.Matchers;

import java.util.Arrays;
Expand Down Expand Up @@ -84,10 +87,14 @@ public void testOldIndexes() throws Exception {
}

void assertOldIndexWorks(String index) throws Exception {
loadIndex(index);
Settings settings = ImmutableSettings.builder()
.put(InternalNode.HTTP_ENABLED, true) // for _upgrade
.build();
loadIndex(index, settings);
assertBasicSearchWorks();
assertRealtimeGetWorks();
assertNewReplicasWork();
assertUpgradeWorks();
unloadIndex();
}

Expand Down Expand Up @@ -126,7 +133,9 @@ void assertNewReplicasWork() {
logger.debug("Creating another node for replica " + i);
internalCluster().startNode(ImmutableSettings.builder()
.put("data.node", true)
.put("master.node", false).build());
.put("master.node", false)
.put(InternalNode.HTTP_ENABLED, true) // for _upgrade
.build());
}
ensureGreen("test");
assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(ImmutableSettings.builder()
Expand All @@ -137,5 +146,12 @@ void assertNewReplicasWork() {
.put("number_of_replicas", 0))
.execute().actionGet());
}

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

UpgradeTest.assertNotUpgraded(httpClient, "test");
UpgradeTest.runUpgrade(httpClient, "test", "wait_for_completion", "true");
UpgradeTest.assertUpgraded(httpClient, "test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected static HttpRequestBuilder httpClient() {
static NodeInfo nodeInfo(final Client client) {
final NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().get();
final NodeInfo[] nodes = nodeInfos.getNodes();
assertEquals(1, nodes.length);
assertTrue(nodes.length > 0);
return nodes[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static String upgradePath(String index) {
return path;
}

static void assertNotUpgraded(HttpRequestBuilder httpClient, String index) throws Exception {
public static void assertNotUpgraded(HttpRequestBuilder httpClient, String index) throws Exception {
for (UpgradeStatus status : getUpgradeStatus(httpClient, upgradePath(index))) {
assertTrue("index " + status.indexName + " should not be zero sized", status.totalBytes != 0);
// TODO: it would be better for this to be strictly greater, but sometimes an extra flush
Expand All @@ -185,7 +185,7 @@ static void assertNotUpgraded(HttpRequestBuilder httpClient, String index) throw
}
}

static void assertUpgraded(HttpRequestBuilder httpClient, String index) throws Exception {
public static void assertUpgraded(HttpRequestBuilder httpClient, String index) throws Exception {
for (UpgradeStatus status : getUpgradeStatus(httpClient, upgradePath(index))) {
assertTrue("index " + status.indexName + " should not be zero sized", status.totalBytes != 0);
assertEquals("index " + status.indexName + " should be upgraded",
Expand Down Expand Up @@ -233,7 +233,7 @@ public UpgradeStatus(String indexName, int totalBytes, int toUpgradeBytes) {
}
}

static void runUpgrade(HttpRequestBuilder httpClient, String index, String... params) throws Exception {
public static void runUpgrade(HttpRequestBuilder httpClient, String index, String... params) throws Exception {
assert params.length % 2 == 0;
HttpRequestBuilder builder = httpClient.method("POST").path(upgradePath(index));
for (int i = 0; i < params.length; i += 2) {
Expand Down

0 comments on commit 7f9ffea

Please sign in to comment.