Search in sources :

Example 1 with BroadcastResponse

use of org.opensearch.action.support.broadcast.BroadcastResponse in project OpenSearch by opensearch-project.

the class BroadcastReplicationTests method testResultCombine.

public void testResultCombine() throws InterruptedException, ExecutionException, IOException {
    final String index = "test";
    int numShards = 1 + randomInt(3);
    setState(clusterService, stateWithAssignedPrimariesAndOneReplica(index, numShards));
    logger.debug("--> using initial state:\n{}", clusterService.state());
    PlainActionFuture<BroadcastResponse> response = PlainActionFuture.newFuture();
    broadcastReplicationAction.execute(new DummyBroadcastRequest().indices(index), response);
    int succeeded = 0;
    int failed = 0;
    for (Tuple<ShardId, ActionListener<ReplicationResponse>> shardRequests : broadcastReplicationAction.capturedShardRequests) {
        if (randomBoolean()) {
            ReplicationResponse.ShardInfo.Failure[] failures = new ReplicationResponse.ShardInfo.Failure[0];
            int shardsSucceeded = randomInt(1) + 1;
            succeeded += shardsSucceeded;
            ReplicationResponse replicationResponse = new ReplicationResponse();
            if (shardsSucceeded == 1 && randomBoolean()) {
                // sometimes add failure (no failure means shard unavailable)
                failures = new ReplicationResponse.ShardInfo.Failure[1];
                failures[0] = new ReplicationResponse.ShardInfo.Failure(shardRequests.v1(), null, new Exception("pretend shard failed"), RestStatus.GATEWAY_TIMEOUT, false);
                failed++;
            }
            replicationResponse.setShardInfo(new ReplicationResponse.ShardInfo(2, shardsSucceeded, failures));
            shardRequests.v2().onResponse(replicationResponse);
        } else {
            // sometimes fail
            failed += 2;
            // just add a general exception and see if failed shards will be incremented by 2
            shardRequests.v2().onFailure(new Exception("pretend shard failed"));
        }
    }
    assertBroadcastResponse(2 * numShards, succeeded, failed, response.get(), Exception.class);
}
Also used : BroadcastResponse(org.opensearch.action.support.broadcast.BroadcastResponse) DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException) UnavailableShardsException(org.opensearch.action.UnavailableShardsException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NoShardAvailableActionException(org.opensearch.action.NoShardAvailableActionException) ShardId(org.opensearch.index.shard.ShardId) ActionListener(org.opensearch.action.ActionListener)

Example 2 with BroadcastResponse

use of org.opensearch.action.support.broadcast.BroadcastResponse in project OpenSearch by opensearch-project.

the class OpenSearchAssertionsTests method testAssertBlocked.

public void testAssertBlocked() {
    Map<String, Set<ClusterBlock>> indexLevelBlocks = new HashMap<>();
    indexLevelBlocks.put("test", Collections.singleton(IndexMetadata.INDEX_READ_ONLY_BLOCK));
    assertBlocked(new BroadcastResponse(1, 0, 1, Collections.singletonList(new DefaultShardOperationFailedException("test", 0, new ClusterBlockException(indexLevelBlocks)))));
    indexLevelBlocks.put("test", Collections.singleton(IndexMetadata.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK));
    assertBlocked(new BroadcastResponse(1, 0, 1, Collections.singletonList(new DefaultShardOperationFailedException("test", 0, new ClusterBlockException(indexLevelBlocks)))));
    indexLevelBlocks.put("test", new HashSet<>(Arrays.asList(IndexMetadata.INDEX_READ_BLOCK, IndexMetadata.INDEX_METADATA_BLOCK)));
    assertBlocked(new BroadcastResponse(1, 0, 1, Collections.singletonList(new DefaultShardOperationFailedException("test", 0, new ClusterBlockException(indexLevelBlocks)))));
    indexLevelBlocks.put("test", new HashSet<>(Arrays.asList(IndexMetadata.INDEX_READ_ONLY_BLOCK, IndexMetadata.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK)));
    assertBlocked(new BroadcastResponse(1, 0, 1, Collections.singletonList(new DefaultShardOperationFailedException("test", 0, new ClusterBlockException(indexLevelBlocks)))));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) BroadcastResponse(org.opensearch.action.support.broadcast.BroadcastResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException)

Example 3 with BroadcastResponse

use of org.opensearch.action.support.broadcast.BroadcastResponse in project OpenSearch by opensearch-project.

the class BroadcastReplicationTests method testNoShards.

public void testNoShards() throws InterruptedException, ExecutionException, IOException {
    setState(clusterService, stateWithNoShard());
    logger.debug("--> using initial state:\n{}", clusterService.state());
    BroadcastResponse response = executeAndAssertImmediateResponse(broadcastReplicationAction, new DummyBroadcastRequest());
    assertBroadcastResponse(0, 0, 0, response, null);
}
Also used : BroadcastResponse(org.opensearch.action.support.broadcast.BroadcastResponse)

Example 4 with BroadcastResponse

use of org.opensearch.action.support.broadcast.BroadcastResponse in project OpenSearch by opensearch-project.

the class BroadcastReplicationTests method testNotStartedPrimary.

public void testNotStartedPrimary() throws InterruptedException, ExecutionException {
    final String index = "test";
    setState(clusterService, state(index, randomBoolean(), randomBoolean() ? ShardRoutingState.INITIALIZING : ShardRoutingState.UNASSIGNED, ShardRoutingState.UNASSIGNED));
    logger.debug("--> using initial state:\n{}", clusterService.state());
    PlainActionFuture<BroadcastResponse> response = PlainActionFuture.newFuture();
    broadcastReplicationAction.execute(new DummyBroadcastRequest(index), response);
    for (Tuple<ShardId, ActionListener<ReplicationResponse>> shardRequests : broadcastReplicationAction.capturedShardRequests) {
        if (randomBoolean()) {
            shardRequests.v2().onFailure(new NoShardAvailableActionException(shardRequests.v1()));
        } else {
            shardRequests.v2().onFailure(new UnavailableShardsException(shardRequests.v1(), "test exception"));
        }
    }
    response.get();
    logger.info("total shards: {}, ", response.get().getTotalShards());
    // we expect no failures here because UnavailableShardsException does not count as failed
    assertBroadcastResponse(2, 0, 0, response.get(), null);
}
Also used : ShardId(org.opensearch.index.shard.ShardId) ActionListener(org.opensearch.action.ActionListener) NoShardAvailableActionException(org.opensearch.action.NoShardAvailableActionException) UnavailableShardsException(org.opensearch.action.UnavailableShardsException) BroadcastResponse(org.opensearch.action.support.broadcast.BroadcastResponse)

Aggregations

BroadcastResponse (org.opensearch.action.support.broadcast.BroadcastResponse)4 ActionListener (org.opensearch.action.ActionListener)2 NoShardAvailableActionException (org.opensearch.action.NoShardAvailableActionException)2 UnavailableShardsException (org.opensearch.action.UnavailableShardsException)2 DefaultShardOperationFailedException (org.opensearch.action.support.DefaultShardOperationFailedException)2 ShardId (org.opensearch.index.shard.ShardId)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 ClusterBlockException (org.opensearch.cluster.block.ClusterBlockException)1