From 5d94f5d35f128145d9780b1dd39000a2c5511f3a Mon Sep 17 00:00:00 2001 From: javanna Date: Tue, 12 Jan 2016 16:06:56 +0100 Subject: [PATCH] make IngestProxyActionFilterTests work again --- .../action/ingest/IngestProxyActionFilter.java | 8 ++------ .../action/ingest/IngestProxyActionFilterTests.java | 8 +++++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/ingest/IngestProxyActionFilter.java b/core/src/main/java/org/elasticsearch/action/ingest/IngestProxyActionFilter.java index 98c256f8a72..be9051bc9ca 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/IngestProxyActionFilter.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/IngestProxyActionFilter.java @@ -29,9 +29,7 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.support.ActionFilter; import org.elasticsearch.action.support.ActionFilterChain; import org.elasticsearch.cluster.ClusterService; -import org.elasticsearch.cluster.ClusterState; 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; @@ -127,11 +125,9 @@ public final class IngestProxyActionFilter implements ActionFilter { } private DiscoveryNode randomIngestNode() { - ClusterState state = clusterService.state(); - DiscoveryNodes nodes = state.nodes(); - assert IngestModule.isIngestEnabled(nodes.localNode().attributes()) == false; + assert IngestModule.isIngestEnabled(clusterService.localNode().attributes()) == false; List ingestNodes = new ArrayList<>(); - for (DiscoveryNode node : nodes) { + for (DiscoveryNode node : clusterService.state().nodes()) { if (IngestModule.isIngestEnabled(node.getAttributes())) { ingestNodes.add(node); } diff --git a/core/src/test/java/org/elasticsearch/action/ingest/IngestProxyActionFilterTests.java b/core/src/test/java/org/elasticsearch/action/ingest/IngestProxyActionFilterTests.java index 186c806b8e0..ed1bc7ee0ce 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/IngestProxyActionFilterTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/IngestProxyActionFilterTests.java @@ -68,6 +68,7 @@ public class IngestProxyActionFilterTests extends ESTestCase { private IngestProxyActionFilter buildFilter(int ingestNodes, int totalNodes) { ClusterState clusterState = mock(ClusterState.class); DiscoveryNodes.Builder builder = new DiscoveryNodes.Builder(); + DiscoveryNode localNode = null; for (int i = 0; i < totalNodes; i++) { String nodeId = "node" + i; Map attributes = new HashMap<>(); @@ -76,10 +77,15 @@ public class IngestProxyActionFilterTests extends ESTestCase { } else if (randomBoolean()) { 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()); ClusterService clusterService = mock(ClusterService.class); + when(clusterService.localNode()).thenReturn(localNode); when(clusterService.state()).thenReturn(clusterState); transportService = mock(TransportService.class); return new IngestProxyActionFilter(clusterService, transportService);