From ee406e9c3f241bdd1f044435e825549ea08d0cec Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Tue, 10 May 2016 18:28:41 +0200 Subject: [PATCH] Use immutable ShardRouting Relates to elastic/elasticsearchelastic/elasticsearch#17821 Original commit: elastic/x-pack-elasticsearch@92a9581327ec30f455f7acbad98328afecfaa53f --- .../routing/ShardRoutingTestUtils.java | 30 ------------------- .../cluster/ClusterStatsResolverTests.java | 2 +- .../indices/IndexStatsResolverTests.java | 7 ++--- .../indices/IndicesStatsResolverTests.java | 7 ++--- .../resolver/node/NodeStatsResolverTests.java | 7 ++--- .../resolver/shards/ShardsResolverTests.java | 26 ++++++++-------- .../execution/TriggeredWatchStoreTests.java | 25 +++++++++------- 7 files changed, 38 insertions(+), 66 deletions(-) delete mode 100644 elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/cluster/routing/ShardRoutingTestUtils.java diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/cluster/routing/ShardRoutingTestUtils.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/cluster/routing/ShardRoutingTestUtils.java deleted file mode 100644 index bc71b2637a8..00000000000 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/cluster/routing/ShardRoutingTestUtils.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.cluster.routing; - -public class ShardRoutingTestUtils { - - /** - * Gives access to package private {@link ShardRouting#initialize(String, String, long)} method for test purpose. - **/ - public static void initialize(ShardRouting shardRouting, String nodeId) { - shardRouting.initialize(nodeId, null, -1); - } - - /** - * Gives access to package private {@link ShardRouting#moveToStarted()} method for test purpose. - **/ - public static void moveToStarted(ShardRouting shardRouting) { - shardRouting.moveToStarted(); - } - - /** - * Gives access to package private {@link ShardRouting#relocate(String, long)} method for test purpose. - **/ - public static void relocate(ShardRouting shardRouting, String nodeId) { - shardRouting.relocate(nodeId, -1); - } -} diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java index dc470d63388..12a82894e3e 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java @@ -137,7 +137,7 @@ public class ClusterStatsResolverTests extends MonitoringIndexNameResolverTestCa private ShardStats[] randomShardStats() { Index index = new Index("test", UUID.randomUUID().toString()); Path shardPath = createTempDir().resolve("indices").resolve(index.getUUID()).resolve("0"); - ShardRouting shardRouting = ShardRouting.newUnassigned(index, 0, null, false, + ShardRouting shardRouting = ShardRouting.newUnassigned(new ShardId(index, 0), null, false, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo")); CommonStats shardCommonStats = new CommonStats(); shardCommonStats.fieldData = new FieldDataStats(); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexStatsResolverTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexStatsResolverTests.java index 2146b4147f3..1be2c883894 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexStatsResolverTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexStatsResolverTests.java @@ -11,7 +11,6 @@ import org.elasticsearch.action.admin.indices.stats.IndexStats; import org.elasticsearch.action.admin.indices.stats.ShardStats; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.ShardRouting; -import org.elasticsearch.cluster.routing.ShardRoutingTestUtils; import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.common.xcontent.XContentType; @@ -80,10 +79,10 @@ public class IndexStatsResolverTests extends MonitoringIndexNameResolverTestCase Index index = new Index("test-" + randomIntBetween(0, 5), UUID.randomUUID().toString()); ShardId shardId = new ShardId(index, 0); Path path = createTempDir().resolve("indices").resolve(index.getUUID()).resolve("0"); - ShardRouting shardRouting = ShardRouting.newUnassigned(index, 0, null, true, + ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, null, true, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null)); - ShardRoutingTestUtils.initialize(shardRouting, "node-0"); - ShardRoutingTestUtils.moveToStarted(shardRouting); + shardRouting = shardRouting.initialize("node-0", null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); + shardRouting = shardRouting.moveToStarted(); CommonStats stats = new CommonStats(); stats.fieldData = new FieldDataStats(); stats.queryCache = new QueryCacheStats(); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndicesStatsResolverTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndicesStatsResolverTests.java index a15ff66f9ea..e28342679e4 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndicesStatsResolverTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndicesStatsResolverTests.java @@ -12,7 +12,6 @@ import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponseTestUtil import org.elasticsearch.action.admin.indices.stats.ShardStats; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.ShardRouting; -import org.elasticsearch.cluster.routing.ShardRoutingTestUtils; import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.common.xcontent.XContentType; @@ -88,10 +87,10 @@ public class IndicesStatsResolverTests extends MonitoringIndexNameResolverTestCa for (int i=0; i < randomIntBetween(2, 5); i++) { ShardId shardId = new ShardId(index, i); Path path = createTempDir().resolve("indices").resolve(index.getUUID()).resolve(String.valueOf(i)); - ShardRouting shardRouting = ShardRouting.newUnassigned(index, i, null, true, + ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, null, true, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null)); - ShardRoutingTestUtils.initialize(shardRouting, "node-0"); - ShardRoutingTestUtils.moveToStarted(shardRouting); + shardRouting = shardRouting.initialize("node-0", null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); + shardRouting = shardRouting.moveToStarted(); CommonStats stats = new CommonStats(); stats.fieldData = new FieldDataStats(); stats.queryCache = new QueryCacheStats(); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/node/NodeStatsResolverTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/node/NodeStatsResolverTests.java index 330547355ce..a2a6c7aa229 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/node/NodeStatsResolverTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/node/NodeStatsResolverTests.java @@ -13,7 +13,6 @@ import org.elasticsearch.action.admin.indices.stats.IndexShardStats; import org.elasticsearch.action.admin.indices.stats.ShardStats; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.ShardRouting; -import org.elasticsearch.cluster.routing.ShardRoutingTestUtils; import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.common.xcontent.XContentType; @@ -107,10 +106,10 @@ public class NodeStatsResolverTests extends MonitoringIndexNameResolverTestCase< Index index = new Index("test-" + randomIntBetween(0, 5), UUID.randomUUID().toString()); ShardId shardId = new ShardId(index, 0); Path path = createTempDir().resolve("indices").resolve(index.getUUID()).resolve("0"); - ShardRouting shardRouting = ShardRouting.newUnassigned(index, 0, null, true, + ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, null, true, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null)); - ShardRoutingTestUtils.initialize(shardRouting, "node-0"); - ShardRoutingTestUtils.moveToStarted(shardRouting); + shardRouting = shardRouting.initialize("node-0", null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); + shardRouting = shardRouting.moveToStarted(); CommonStats stats = new CommonStats(); stats.fieldData = new FieldDataStats(); stats.queryCache = new QueryCacheStats(); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsResolverTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsResolverTests.java index f75452df163..38021b420fd 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsResolverTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsResolverTests.java @@ -8,11 +8,11 @@ package org.elasticsearch.marvel.agent.resolver.shards; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.ShardRouting; -import org.elasticsearch.cluster.routing.ShardRoutingTestUtils; import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.Index; +import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.marvel.agent.collector.shards.ShardMonitoringDoc; import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils; import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolverTestCase; @@ -33,11 +33,11 @@ public class ShardsResolverTests extends MonitoringIndexNameResolverTestCase