make IngestProxyActionFilterTests work again
This commit is contained in:
parent
0769636ea2
commit
5d94f5d35f
|
@ -29,9 +29,7 @@ import org.elasticsearch.action.index.IndexRequest;
|
||||||
import org.elasticsearch.action.support.ActionFilter;
|
import org.elasticsearch.action.support.ActionFilter;
|
||||||
import org.elasticsearch.action.support.ActionFilterChain;
|
import org.elasticsearch.action.support.ActionFilterChain;
|
||||||
import org.elasticsearch.cluster.ClusterService;
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
|
||||||
import org.elasticsearch.common.Randomness;
|
import org.elasticsearch.common.Randomness;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
|
@ -127,11 +125,9 @@ public final class IngestProxyActionFilter implements ActionFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private DiscoveryNode randomIngestNode() {
|
private DiscoveryNode randomIngestNode() {
|
||||||
ClusterState state = clusterService.state();
|
assert IngestModule.isIngestEnabled(clusterService.localNode().attributes()) == false;
|
||||||
DiscoveryNodes nodes = state.nodes();
|
|
||||||
assert IngestModule.isIngestEnabled(nodes.localNode().attributes()) == false;
|
|
||||||
List<DiscoveryNode> ingestNodes = new ArrayList<>();
|
List<DiscoveryNode> ingestNodes = new ArrayList<>();
|
||||||
for (DiscoveryNode node : nodes) {
|
for (DiscoveryNode node : clusterService.state().nodes()) {
|
||||||
if (IngestModule.isIngestEnabled(node.getAttributes())) {
|
if (IngestModule.isIngestEnabled(node.getAttributes())) {
|
||||||
ingestNodes.add(node);
|
ingestNodes.add(node);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ public class IngestProxyActionFilterTests extends ESTestCase {
|
||||||
private IngestProxyActionFilter buildFilter(int ingestNodes, int totalNodes) {
|
private IngestProxyActionFilter buildFilter(int ingestNodes, int totalNodes) {
|
||||||
ClusterState clusterState = mock(ClusterState.class);
|
ClusterState clusterState = mock(ClusterState.class);
|
||||||
DiscoveryNodes.Builder builder = new DiscoveryNodes.Builder();
|
DiscoveryNodes.Builder builder = new DiscoveryNodes.Builder();
|
||||||
|
DiscoveryNode localNode = null;
|
||||||
for (int i = 0; i < totalNodes; i++) {
|
for (int i = 0; i < totalNodes; i++) {
|
||||||
String nodeId = "node" + i;
|
String nodeId = "node" + i;
|
||||||
Map<String, String> attributes = new HashMap<>();
|
Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -76,10 +77,15 @@ public class IngestProxyActionFilterTests extends ESTestCase {
|
||||||
} else if (randomBoolean()) {
|
} else if (randomBoolean()) {
|
||||||
attributes.put("ingest", "true");
|
attributes.put("ingest", "true");
|
||||||
}
|
}
|
||||||
builder.put(new DiscoveryNode(nodeId, nodeId, DummyTransportAddress.INSTANCE, attributes, VersionUtils.randomVersion(random())));
|
DiscoveryNode node = new DiscoveryNode(nodeId, nodeId, DummyTransportAddress.INSTANCE, attributes, VersionUtils.randomVersion(random()));
|
||||||
|
builder.put(node);
|
||||||
|
if (i == totalNodes - 1) {
|
||||||
|
localNode = node;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
when(clusterState.nodes()).thenReturn(builder.build());
|
when(clusterState.nodes()).thenReturn(builder.build());
|
||||||
ClusterService clusterService = mock(ClusterService.class);
|
ClusterService clusterService = mock(ClusterService.class);
|
||||||
|
when(clusterService.localNode()).thenReturn(localNode);
|
||||||
when(clusterService.state()).thenReturn(clusterState);
|
when(clusterService.state()).thenReturn(clusterState);
|
||||||
transportService = mock(TransportService.class);
|
transportService = mock(TransportService.class);
|
||||||
return new IngestProxyActionFilter(clusterService, transportService);
|
return new IngestProxyActionFilter(clusterService, transportService);
|
||||||
|
|
Loading…
Reference in New Issue