[TEST] Add basic test for /cat/shards/{index}

Basic REST test for rendering the cat/shards endpoint.
This commit is contained in:
Simon Willnauer 2014-02-09 19:19:03 +01:00
parent e2b20843c8
commit dc308db4fe
2 changed files with 57 additions and 28 deletions

View File

@ -0,0 +1,54 @@
---
setup:
- skip:
features: regex
---
"Test cat shards output":
- do:
cat.shards: {}
- match:
$body: >
/^$/
- do:
index:
index: index1
type: type1
id: 1
body: { foo: bar }
refresh: true
- do:
cluster.health:
wait_for_status: yellow
- do:
cat.shards: {}
- match:
$body: >
/^(index1 \s+ \d \s+ (p|r) \s+ ((STARTED|INITIALIZING) \s+ (\d \s+ (\d+|\d+[.]\d+)(kb|b) \s+)? \d{1,3}.\d{1,3}.\d{1,3}.\d{1,3} \s+ .+|UNASSIGNED \s+) \n?){10}$/
- do:
indices.create:
index: index2
body:
settings:
number_of_replicas: "0"
- do:
cluster.health:
wait_for_status: yellow
- do:
cat.shards: {}
- match:
$body: >
/^(index(1|2) \s+ \d \s+ (p|r) \s+ ((STARTED|INITIALIZING) \s+ (\d \s+ (\d+|\d+[.]\d+)(kb|b) \s+)? \d{1,3}.\d{1,3}.\d{1,3}.\d{1,3} \s+ .+|UNASSIGNED \s+) \n?){15}$/
- do:
cat.shards:
index: index2
- match:
$body: >
/^(index2 \s+ \d \s+ (p|r) \s+ ((STARTED|INITIALIZING) \s+ (\d \s+ (\d+|\d+[.]\d+)(kb|b) \s+)? \d{1,3}.\d{1,3}.\d{1,3}.\d{1,3} \s+ .+|UNASSIGNED \s+) \n?){5}$/

View File

@ -19,7 +19,6 @@
package org.elasticsearch.rest.action.cat;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.admin.indices.stats.CommonStats;
@ -31,14 +30,9 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.Table;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.XContentThrowableRestResponse;
import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestTable;
import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.GET;
public class RestShardsAction extends AbstractCatAction {
@ -63,13 +57,12 @@ public class RestShardsAction extends AbstractCatAction {
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
clusterStateRequest.clear().nodes(true).routingTable(true).indices(indices);
client.admin().cluster().state(clusterStateRequest, new ActionListener<ClusterStateResponse>() {
client.admin().cluster().state(clusterStateRequest, new AbstractRestResponseActionListener<ClusterStateResponse>(request, channel, logger) {
@Override
public void onResponse(final ClusterStateResponse clusterStateResponse) {
IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
indicesStatsRequest.all();
client.admin().indices().stats(indicesStatsRequest, new ActionListener<IndicesStatsResponse>() {
client.admin().indices().stats(indicesStatsRequest, new AbstractRestResponseActionListener<IndicesStatsResponse>(request, channel, logger) {
@Override
public void onResponse(IndicesStatsResponse indicesStatsResponse) {
try {
@ -78,26 +71,8 @@ public class RestShardsAction extends AbstractCatAction {
onFailure(e);
}
}
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
}
});
}
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
}
});
}