use of org.opensearch.transport.ActionNotFoundTransportException in project OpenSearch by opensearch-project.
the class CloseIndexResponseTests method testToXContent.
/**
* Test that random responses can be written to xcontent without errors.
* Also check some specific simple cases for output.
*/
public void testToXContent() throws IOException {
CloseIndexResponse response = randomResponse();
XContentType xContentType = randomFrom(XContentType.values());
try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) {
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
}
Index index = new Index("test", "uuid");
IndexResult indexResult = new CloseIndexResponse.IndexResult(index);
CloseIndexResponse closeIndexResponse = new CloseIndexResponse(true, true, Collections.singletonList(indexResult));
assertEquals("{\"acknowledged\":true,\"shards_acknowledged\":true,\"indices\":{\"test\":{\"closed\":true}}}", Strings.toString(closeIndexResponse));
CloseIndexResponse.ShardResult[] shards = new CloseIndexResponse.ShardResult[1];
shards[0] = new CloseIndexResponse.ShardResult(0, new CloseIndexResponse.ShardResult.Failure[] { new CloseIndexResponse.ShardResult.Failure("test", 0, new ActionNotFoundTransportException("test"), "nodeId") });
indexResult = new CloseIndexResponse.IndexResult(index, shards);
closeIndexResponse = new CloseIndexResponse(true, true, Collections.singletonList(indexResult));
assertEquals("{\"acknowledged\":true,\"shards_acknowledged\":true," + "\"indices\":{\"test\":{\"closed\":false,\"failedShards\":{\"0\":{" + "\"failures\":[{\"node\":\"nodeId\",\"shard\":0,\"index\":\"test\",\"status\":\"INTERNAL_SERVER_ERROR\"," + "\"reason\":{\"type\":\"action_not_found_transport_exception\"," + "\"reason\":\"No handler for action [test]\"}}]}}}}}", Strings.toString(closeIndexResponse));
}
use of org.opensearch.transport.ActionNotFoundTransportException in project OpenSearch by opensearch-project.
the class ExceptionSerializationTests method testActionNotFoundTransportException.
public void testActionNotFoundTransportException() throws IOException {
ActionNotFoundTransportException ex = serialize(new ActionNotFoundTransportException("AACCCTION"));
assertEquals("AACCCTION", ex.action());
assertEquals("No handler for action [AACCCTION]", ex.getMessage());
}
use of org.opensearch.transport.ActionNotFoundTransportException in project OpenSearch by opensearch-project.
the class CloseIndexResponseTests method createServerTestInstance.
@Override
protected org.opensearch.action.admin.indices.close.CloseIndexResponse createServerTestInstance(XContentType xContentType) {
boolean acknowledged = true;
final String[] indicesNames = generateRandomStringArray(10, 10, false, true);
final List<org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult> indexResults = new ArrayList<>();
for (String indexName : indicesNames) {
final Index index = new Index(indexName, randomAlphaOfLength(5));
if (randomBoolean()) {
indexResults.add(new org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult(index));
} else {
if (randomBoolean()) {
acknowledged = false;
Exception exception = randomFrom(new IndexNotFoundException(index), new ActionNotFoundTransportException("test"));
indexResults.add(new org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult(index, exception));
} else {
final int nbShards = randomIntBetween(1, 5);
org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult[] shards = new org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult[nbShards];
for (int i = 0; i < nbShards; i++) {
org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult.Failure[] failures = null;
if (randomBoolean()) {
acknowledged = false;
int nbFailures = randomIntBetween(1, 3);
failures = new org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult.Failure[nbFailures];
for (int j = 0; j < failures.length; j++) {
String nodeId = null;
if (frequently()) {
nodeId = randomAlphaOfLength(5);
}
failures[j] = newFailure(indexName, i, nodeId);
}
}
shards[i] = new org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult(i, failures);
}
indexResults.add(new org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult(index, shards));
}
}
}
final boolean shardsAcknowledged = acknowledged ? randomBoolean() : false;
return new org.opensearch.action.admin.indices.close.CloseIndexResponse(acknowledged, shardsAcknowledged, indexResults);
}
Aggregations