[TEST] Close the node env after test is done

This commit is contained in:
Simon Willnauer 2014-12-11 21:21:09 +01:00
parent 3877dc618d
commit dac520170f
1 changed files with 65 additions and 69 deletions

View File

@ -18,22 +18,15 @@
*/ */
package org.elasticsearch.gateway.local.state.shards; package org.elasticsearch.gateway.local.state.shards;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.*; import org.elasticsearch.cluster.routing.*;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.test.ElasticsearchTestCase;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -41,7 +34,8 @@ import java.util.Map;
public class LocalGatewayShardStateTests extends ElasticsearchTestCase { public class LocalGatewayShardStateTests extends ElasticsearchTestCase {
public void testWriteShardState() throws Exception { public void testWriteShardState() throws Exception {
LocalGatewayShardsState state = new LocalGatewayShardsState(ImmutableSettings.EMPTY, newNodeEnvironment(), null); try (NodeEnvironment env = newNodeEnvironment()) {
LocalGatewayShardsState state = new LocalGatewayShardsState(ImmutableSettings.EMPTY, env, null);
ShardId id = new ShardId("foo", 1); ShardId id = new ShardId("foo", 1);
long version = between(1, Integer.MAX_VALUE / 2); long version = between(1, Integer.MAX_VALUE / 2);
boolean primary = randomBoolean(); boolean primary = randomBoolean();
@ -55,16 +49,17 @@ public class LocalGatewayShardStateTests extends ElasticsearchTestCase {
shardStateInfo = state.loadShardInfo(id); shardStateInfo = state.loadShardInfo(id);
assertEquals(shardStateInfo, state1); assertEquals(shardStateInfo, state1);
ShardStateInfo state3 = new ShardStateInfo(version+1, primary); ShardStateInfo state3 = new ShardStateInfo(version + 1, primary);
state.maybeWriteShardState(id, state3, state1); state.maybeWriteShardState(id, state3, state1);
shardStateInfo = state.loadShardInfo(id); shardStateInfo = state.loadShardInfo(id);
assertEquals(shardStateInfo, state3); assertEquals(shardStateInfo, state3);
assertTrue(state.getCurrentState().isEmpty()); assertTrue(state.getCurrentState().isEmpty());
}
} }
public void testPersistRoutingNode() throws Exception { public void testPersistRoutingNode() throws Exception {
LocalGatewayShardsState state = new LocalGatewayShardsState(ImmutableSettings.EMPTY, newNodeEnvironment(), null); try (NodeEnvironment env = newNodeEnvironment()) {
LocalGatewayShardsState state = new LocalGatewayShardsState(ImmutableSettings.EMPTY, env, null);
int numShards = between(0, 100); int numShards = between(0, 100);
List<MutableShardRouting> shards = new ArrayList<>(); List<MutableShardRouting> shards = new ArrayList<>();
List<MutableShardRouting> active = new ArrayList<>(); List<MutableShardRouting> active = new ArrayList<>();
@ -122,4 +117,5 @@ public class LocalGatewayShardStateTests extends ElasticsearchTestCase {
} }
} }
} }
}
} }