Search in sources :

Example 6 with NodeConfigurationSource

use of org.elasticsearch.test.NodeConfigurationSource in project elasticsearch by elastic.

the class InternalTestClusterTests method testDataFolderAssignmentAndCleaning.

public void testDataFolderAssignmentAndCleaning() throws IOException, InterruptedException {
    long clusterSeed = randomLong();
    boolean masterNodes = randomBoolean();
    // we need one stable node
    final int minNumDataNodes = 2;
    final int maxNumDataNodes = 2;
    final int numClientNodes = randomIntBetween(0, 2);
    final String clusterName1 = "shared1";
    NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() {

        @Override
        public Settings nodeSettings(int nodeOrdinal) {
            return Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false).put(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), 2 + (masterNodes ? InternalTestCluster.DEFAULT_HIGH_NUM_MASTER_NODES : 0) + maxNumDataNodes + numClientNodes).put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).build();
        }

        @Override
        public Settings transportClientSettings() {
            return Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).build();
        }
    };
    boolean enableHttpPipelining = randomBoolean();
    String nodePrefix = "test";
    Path baseDir = createTempDir();
    InternalTestCluster cluster = new InternalTestCluster(clusterSeed, baseDir, masterNodes, true, minNumDataNodes, maxNumDataNodes, clusterName1, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix, Arrays.asList(MockTcpTransportPlugin.class, TestZenDiscovery.TestPlugin.class), Function.identity());
    try {
        cluster.beforeTest(random(), 0.0);
        final int originalMasterCount = cluster.numMasterNodes();
        assertMMNinNodeSetting(cluster, originalMasterCount);
        final Map<String, Path[]> shardNodePaths = new HashMap<>();
        for (String name : cluster.getNodeNames()) {
            shardNodePaths.put(name, getNodePaths(cluster, name));
        }
        String poorNode = randomFrom(cluster.getNodeNames());
        Path dataPath = getNodePaths(cluster, poorNode)[0];
        final Path testMarker = dataPath.resolve("testMarker");
        Files.createDirectories(testMarker);
        int expectedMasterCount = originalMasterCount;
        if (cluster.getInstance(ClusterService.class, poorNode).localNode().isMasterNode()) {
            expectedMasterCount--;
        }
        cluster.stopRandomNode(InternalTestCluster.nameFilter(poorNode));
        if (expectedMasterCount != originalMasterCount) {
            // check for updated
            assertMMNinClusterSetting(cluster, expectedMasterCount);
        }
        // stopping a node half way shouldn't clean data
        assertFileExists(testMarker);
        final String stableNode = randomFrom(cluster.getNodeNames());
        final Path stableDataPath = getNodePaths(cluster, stableNode)[0];
        final Path stableTestMarker = stableDataPath.resolve("stableTestMarker");
        assertThat(stableDataPath, not(dataPath));
        Files.createDirectories(stableTestMarker);
        final String newNode1 = cluster.startNode();
        expectedMasterCount++;
        assertThat(getNodePaths(cluster, newNode1)[0], equalTo(dataPath));
        // starting a node should re-use data folders and not clean it
        assertFileExists(testMarker);
        if (expectedMasterCount > 1) {
            // this is the first master, it's in cluster state settings won't be updated
            assertMMNinClusterSetting(cluster, expectedMasterCount);
        }
        assertMMNinNodeSetting(newNode1, cluster, expectedMasterCount);
        final String newNode2 = cluster.startNode();
        expectedMasterCount++;
        assertMMNinClusterSetting(cluster, expectedMasterCount);
        final Path newDataPath = getNodePaths(cluster, newNode2)[0];
        final Path newTestMarker = newDataPath.resolve("newTestMarker");
        assertThat(newDataPath, not(dataPath));
        Files.createDirectories(newTestMarker);
        cluster.beforeTest(random(), 0.0);
        // the cluster should be reset for a new test, cleaning up the extra path we made
        assertFileNotExists(newTestMarker);
        // a new unknown node used this path, it should be cleaned
        assertFileNotExists(testMarker);
        // but leaving the structure of existing, reused nodes
        assertFileExists(stableTestMarker);
        for (String name : cluster.getNodeNames()) {
            assertThat("data paths for " + name + " changed", getNodePaths(cluster, name), equalTo(shardNodePaths.get(name)));
        }
        cluster.beforeTest(random(), 0.0);
        // but leaving the structure of existing, reused nodes
        assertFileExists(stableTestMarker);
        for (String name : cluster.getNodeNames()) {
            assertThat("data paths for " + name + " changed", getNodePaths(cluster, name), equalTo(shardNodePaths.get(name)));
        }
        assertMMNinNodeSetting(cluster, originalMasterCount);
    } finally {
        cluster.close();
    }
}
Also used : Path(java.nio.file.Path) MockTcpTransportPlugin(org.elasticsearch.transport.MockTcpTransportPlugin) HashMap(java.util.HashMap) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) NodeConfigurationSource(org.elasticsearch.test.NodeConfigurationSource)

Aggregations

InternalTestCluster (org.elasticsearch.test.InternalTestCluster)6 NodeConfigurationSource (org.elasticsearch.test.NodeConfigurationSource)6 Path (java.nio.file.Path)5 MockTcpTransportPlugin (org.elasticsearch.transport.MockTcpTransportPlugin)5 IOException (java.io.IOException)3 Settings (org.elasticsearch.common.settings.Settings)3 DiscoverySettings (org.elasticsearch.discovery.DiscoverySettings)3 Plugin (org.elasticsearch.plugins.Plugin)3 TransportSettings (org.elasticsearch.transport.TransportSettings)3 HashMap (java.util.HashMap)2 Random (java.util.Random)2 Client (org.elasticsearch.client.Client)2 TestZenDiscovery (org.elasticsearch.test.discovery.TestZenDiscovery)2 Files (java.nio.file.Files)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1