fix test bug

This commit is contained in:
Martijn van Groningen 2016-01-20 16:51:27 +01:00
parent e4a142f792
commit d2c608e1a8
2 changed files with 7 additions and 4 deletions

View File

@ -31,6 +31,7 @@ import org.elasticsearch.action.support.ActionFilter;
import org.elasticsearch.action.support.ActionFilterChain;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.Randomness;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
@ -110,7 +111,8 @@ public final class IngestProxyActionFilter implements ActionFilter {
private DiscoveryNode randomIngestNode() {
assert NodeModule.isNodeIngestEnabled(clusterService.localNode().attributes()) == false;
DiscoveryNode[] ingestNodes = clusterService.state().getNodes().getIngestNodes().values().toArray(DiscoveryNode.class);
DiscoveryNodes nodes = clusterService.state().getNodes();
DiscoveryNode[] ingestNodes = nodes.getIngestNodes().values().toArray(DiscoveryNode.class);
if (ingestNodes.length == 0) {
throw new IllegalStateException("There are no ingest nodes in this cluster, unable to forward request to an ingest node.");
}

View File

@ -28,6 +28,7 @@ import org.elasticsearch.action.index.IndexAction;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.support.ActionFilterChain;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.node.DiscoveryNode;
@ -66,7 +67,7 @@ public class IngestProxyActionFilterTests extends ESTestCase {
@SuppressWarnings("unchecked")
private IngestProxyActionFilter buildFilter(int ingestNodes, int totalNodes) {
ClusterState clusterState = mock(ClusterState.class);
ClusterState.Builder clusterState = new ClusterState.Builder(new ClusterName("_name"));
DiscoveryNodes.Builder builder = new DiscoveryNodes.Builder();
DiscoveryNode localNode = null;
for (int i = 0; i < totalNodes; i++) {
@ -83,10 +84,10 @@ public class IngestProxyActionFilterTests extends ESTestCase {
localNode = node;
}
}
when(clusterState.nodes()).thenReturn(builder.build());
clusterState.nodes(builder);
ClusterService clusterService = mock(ClusterService.class);
when(clusterService.localNode()).thenReturn(localNode);
when(clusterService.state()).thenReturn(clusterState);
when(clusterService.state()).thenReturn(clusterState.build());
transportService = mock(TransportService.class);
return new IngestProxyActionFilter(clusterService, transportService);
}