Search in sources :

Example 1 with ActionNotFoundTransportException

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));
}
Also used : XContentType(org.opensearch.common.xcontent.XContentType) IndexResult(org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult) IndexResult(org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult) Index(org.opensearch.index.Index) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) ActionNotFoundTransportException(org.opensearch.transport.ActionNotFoundTransportException)

Example 2 with ActionNotFoundTransportException

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());
}
Also used : ActionNotFoundTransportException(org.opensearch.transport.ActionNotFoundTransportException)

Example 3 with ActionNotFoundTransportException

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);
}
Also used : ArrayList(java.util.ArrayList) Index(org.opensearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString) OpenSearchStatusException(org.opensearch.OpenSearchStatusException) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) ActionNotFoundTransportException(org.opensearch.transport.ActionNotFoundTransportException) IOException(java.io.IOException) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) ActionNotFoundTransportException(org.opensearch.transport.ActionNotFoundTransportException)

Aggregations

ActionNotFoundTransportException (org.opensearch.transport.ActionNotFoundTransportException)3 Index (org.opensearch.index.Index)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 OpenSearchStatusException (org.opensearch.OpenSearchStatusException)1 IndexResult (org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult)1 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)1 XContentType (org.opensearch.common.xcontent.XContentType)1 IndexNotFoundException (org.opensearch.index.IndexNotFoundException)1