Skip to content

Commit

Permalink
Also check index blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
tlrx committed Nov 13, 2018
1 parent dc77f70 commit bbaf292
Showing 1 changed file with 24 additions and 12 deletions.
Expand Up @@ -194,27 +194,42 @@ private <T> T assertListenerThrows(String msg, PlainActionFuture<?> listener, Cl
return cause;
}

private void setStateWithBlock(final ClusterService clusterService, final ClusterBlock block, final boolean globalBlock) {
final ClusterBlocks.Builder blocks = ClusterBlocks.builder();
if (globalBlock) {
blocks.addGlobalBlock(block);
} else {
blocks.addIndexBlock("index", block);
}
setState(clusterService, ClusterState.builder(clusterService.state()).blocks(blocks).build());
}

public void testBlocksInReroutePhase() throws Exception {
final ClusterBlock nonRetryableBlock =
new ClusterBlock(1, "non retryable", false, true, false, RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL);
final ClusterBlock retryableBlock =
new ClusterBlock(1, "retryable", true, true, false, RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL);

final boolean globalBlock = randomBoolean();
final TestAction action = new TestAction(Settings.EMPTY, "internal:testActionWithBlocks",
transportService, clusterService, shardStateAction, threadPool) {
@Override
protected ClusterBlockLevel globalBlockLevel() {
return ClusterBlockLevel.WRITE;
return globalBlock ? ClusterBlockLevel.WRITE : null;
}

@Override
protected ClusterBlockLevel indexBlockLevel() {
return globalBlock == false ? ClusterBlockLevel.WRITE : null;
}
};

setState(clusterService, ClusterStateCreationUtils.stateWithActivePrimary("index", true, 0));

{
setState(clusterService,
ClusterState.builder(clusterService.state()).blocks(ClusterBlocks.builder().addGlobalBlock(nonRetryableBlock)));
setStateWithBlock(clusterService, nonRetryableBlock, globalBlock);

Request request = new Request();
Request request = globalBlock ? new Request() : new Request().index("index");
PlainActionFuture<TestResponse> listener = new PlainActionFuture<>();
ReplicationTask task = maybeTask();

Expand All @@ -227,10 +242,9 @@ protected ClusterBlockLevel globalBlockLevel() {
assertPhase(task, "failed");
}
{
setState(clusterService,
ClusterState.builder(clusterService.state()).blocks(ClusterBlocks.builder().addGlobalBlock(retryableBlock)));
setStateWithBlock(clusterService, retryableBlock, globalBlock);

Request requestWithTimeout = new Request().timeout("5ms");
Request requestWithTimeout = (globalBlock ? new Request() : new Request().index("index")).timeout("5ms");
PlainActionFuture<TestResponse> listener = new PlainActionFuture<>();
ReplicationTask task = maybeTask();

Expand All @@ -244,10 +258,9 @@ protected ClusterBlockLevel globalBlockLevel() {
assertTrue(requestWithTimeout.isRetrySet.get());
}
{
setState(clusterService,
ClusterState.builder(clusterService.state()).blocks(ClusterBlocks.builder().addGlobalBlock(retryableBlock)));
setStateWithBlock(clusterService, retryableBlock, globalBlock);

Request request = new Request();
Request request = globalBlock ? new Request() : new Request().index("index");
PlainActionFuture<TestResponse> listener = new PlainActionFuture<>();
ReplicationTask task = maybeTask();

Expand All @@ -258,8 +271,7 @@ protected ClusterBlockLevel globalBlockLevel() {
assertPhase(task, "waiting_for_retry");
assertTrue(request.isRetrySet.get());

setState(clusterService,
ClusterState.builder(clusterService.state()).blocks(ClusterBlocks.builder().addGlobalBlock(nonRetryableBlock)));
setStateWithBlock(clusterService, nonRetryableBlock, globalBlock);

ClusterBlockException exception = assertListenerThrows("primary phase should fail operation when moving from a retryable " +
"block to a non-retryable one", listener, ClusterBlockException.class);
Expand Down

0 comments on commit bbaf292

Please sign in to comment.