Search in sources :

Example 1 with NodeConfigurationSource

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

the class InternalTestClusterTests method testTwoNodeCluster.

public void testTwoNodeCluster() throws Exception {
    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).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(randomLong(), baseDir, false, true, 2, 2, "test", nodeConfigurationSource, 0, enableHttpPipelining, nodePrefix, Arrays.asList(MockTcpTransportPlugin.class, TestZenDiscovery.TestPlugin.class), Function.identity());
    try {
        cluster.beforeTest(random(), 0.0);
        assertMMNinNodeSetting(cluster, 2);
        switch(randomInt(2)) {
            case 0:
                cluster.stopRandomDataNode();
                assertMMNinClusterSetting(cluster, 1);
                cluster.startNode();
                assertMMNinClusterSetting(cluster, 2);
                assertMMNinNodeSetting(cluster, 2);
                break;
            case 1:
                cluster.rollingRestart(new InternalTestCluster.RestartCallback() {

                    @Override
                    public Settings onNodeStopped(String nodeName) throws Exception {
                        assertMMNinClusterSetting(cluster, 1);
                        return super.onNodeStopped(nodeName);
                    }
                });
                assertMMNinClusterSetting(cluster, 2);
                break;
            case 2:
                cluster.fullRestart();
                break;
        }
        assertMMNinNodeSetting(cluster, 2);
    } finally {
        cluster.close();
    }
}
Also used : Path(java.nio.file.Path) MockTcpTransportPlugin(org.elasticsearch.transport.MockTcpTransportPlugin) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) NodeConfigurationSource(org.elasticsearch.test.NodeConfigurationSource) IOException(java.io.IOException) Settings(org.elasticsearch.common.settings.Settings) DiscoverySettings(org.elasticsearch.discovery.DiscoverySettings) TransportSettings(org.elasticsearch.transport.TransportSettings)

Example 2 with NodeConfigurationSource

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

the class InternalTestClusterTests method testInitializiationIsConsistent.

public void testInitializiationIsConsistent() {
    long clusterSeed = randomLong();
    boolean masterNodes = randomBoolean();
    int minNumDataNodes = randomIntBetween(0, 9);
    int maxNumDataNodes = randomIntBetween(minNumDataNodes, 10);
    String clusterName = randomRealisticUnicodeOfCodepointLengthBetween(1, 10);
    NodeConfigurationSource nodeConfigurationSource = NodeConfigurationSource.EMPTY;
    int numClientNodes = randomIntBetween(0, 10);
    boolean enableHttpPipelining = randomBoolean();
    String nodePrefix = randomRealisticUnicodeOfCodepointLengthBetween(1, 10);
    Path baseDir = createTempDir();
    InternalTestCluster cluster0 = new InternalTestCluster(clusterSeed, baseDir, masterNodes, randomBoolean(), minNumDataNodes, maxNumDataNodes, clusterName, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix, Collections.emptyList(), Function.identity());
    InternalTestCluster cluster1 = new InternalTestCluster(clusterSeed, baseDir, masterNodes, randomBoolean(), minNumDataNodes, maxNumDataNodes, clusterName, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix, Collections.emptyList(), Function.identity());
    // TODO: this is not ideal - we should have a way to make sure ports are initialized in the same way
    assertClusters(cluster0, cluster1, false);
}
Also used : Path(java.nio.file.Path) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) NodeConfigurationSource(org.elasticsearch.test.NodeConfigurationSource)

Example 3 with NodeConfigurationSource

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

the class InternalTestClusterTests method testTwoNodeCluster.

public void testTwoNodeCluster() throws Exception {
    String transportClient = getTestTransportType();
    NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() {

        @Override
        public Settings nodeSettings(int nodeOrdinal) {
            return Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType()).putList(DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "file").putList(SettingsBasedSeedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey()).build();
        }

        @Override
        public Path nodeConfigPath(int nodeOrdinal) {
            return null;
        }

        @Override
        public Settings transportClientSettings() {
            return Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, transportClient).build();
        }
    };
    String nodePrefix = "test";
    Path baseDir = createTempDir();
    List<Class<? extends Plugin>> plugins = new ArrayList<>(mockPlugins());
    plugins.add(NodeAttrCheckPlugin.class);
    InternalTestCluster cluster = new InternalTestCluster(randomLong(), baseDir, false, true, 2, 2, "test", nodeConfigurationSource, 0, nodePrefix, plugins);
    try {
        cluster.beforeTest(random());
        switch(randomInt(2)) {
            case 0:
                cluster.stopRandomDataNode();
                cluster.startNode();
                break;
            case 1:
                cluster.rollingRestart(InternalTestCluster.EMPTY_CALLBACK);
                break;
            case 2:
                cluster.fullRestart();
                break;
        }
    } finally {
        cluster.close();
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) NodeConfigurationSource(org.elasticsearch.test.NodeConfigurationSource) Plugin(org.elasticsearch.plugins.Plugin)

Example 4 with NodeConfigurationSource

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

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";
    String transportClient = getTestTransportType();
    NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() {

        @Override
        public Settings nodeSettings(int nodeOrdinal) {
            return Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType()).putList(DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "file").putList(SettingsBasedSeedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey()).build();
        }

        @Override
        public Path nodeConfigPath(int nodeOrdinal) {
            return null;
        }

        @Override
        public Settings transportClientSettings() {
            return Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, transportClient).build();
        }
    };
    String nodePrefix = "test";
    Path baseDir = createTempDir();
    InternalTestCluster cluster = new InternalTestCluster(clusterSeed, baseDir, masterNodes, true, minNumDataNodes, maxNumDataNodes, clusterName1, nodeConfigurationSource, numClientNodes, nodePrefix, mockPlugins());
    try {
        cluster.beforeTest(random());
        final int originalMasterCount = cluster.numMasterNodes();
        final Map<String, Path[]> shardNodePaths = new HashMap<>();
        for (String name : cluster.getNodeNames()) {
            shardNodePaths.put(name, getNodePaths(cluster, name));
        }
        String poorNode = randomValueOtherThanMany(n -> originalMasterCount == 1 && n.equals(cluster.getMasterName()), () -> randomFrom(cluster.getNodeNames()));
        Path dataPath = getNodePaths(cluster, poorNode)[0];
        final Settings poorNodeDataPathSettings = cluster.dataPathSettings(poorNode);
        final Path testMarker = dataPath.resolve("testMarker");
        Files.createDirectories(testMarker);
        cluster.stopRandomNode(InternalTestCluster.nameFilter(poorNode));
        // 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();
        assertThat(getNodePaths(cluster, newNode1)[0], not(dataPath));
        // starting a node should re-use data folders and not clean it
        assertFileExists(testMarker);
        final String newNode2 = cluster.startNode();
        final Path newDataPath = getNodePaths(cluster, newNode2)[0];
        final Path newTestMarker = newDataPath.resolve("newTestMarker");
        assertThat(newDataPath, not(dataPath));
        Files.createDirectories(newTestMarker);
        final String newNode3 = cluster.startNode(poorNodeDataPathSettings);
        assertThat(getNodePaths(cluster, newNode3)[0], equalTo(dataPath));
        cluster.beforeTest(random());
        // 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());
        // 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)));
        }
    } finally {
        cluster.close();
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) NodeConfigurationSource(org.elasticsearch.test.NodeConfigurationSource) Settings(org.elasticsearch.common.settings.Settings)

Example 5 with NodeConfigurationSource

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

the class TribeIT method startRemoteClusters.

@Before
public void startRemoteClusters() {
    final int minNumDataNodes = 2;
    final int maxNumDataNodes = 4;
    final NodeConfigurationSource nodeConfigurationSource = getNodeConfigSource();
    final Collection<Class<? extends Plugin>> plugins = nodePlugins();
    if (cluster1 == null) {
        cluster1 = new InternalTestCluster(randomLong(), createTempDir(), true, true, minNumDataNodes, maxNumDataNodes, UUIDs.randomBase64UUID(random()), nodeConfigurationSource, 0, false, "cluster_1", plugins, Function.identity());
    }
    if (cluster2 == null) {
        cluster2 = new InternalTestCluster(randomLong(), createTempDir(), true, true, minNumDataNodes, maxNumDataNodes, UUIDs.randomBase64UUID(random()), nodeConfigurationSource, 0, false, "cluster_2", plugins, Function.identity());
    }
    doWithAllClusters(c -> {
        try {
            c.beforeTest(random(), 0.1);
            c.ensureAtLeastNumDataNodes(minNumDataNodes);
        } catch (Exception e) {
            throw new RuntimeException("Failed to set up remote cluster [" + c.getClusterName() + "]", e);
        }
    });
}
Also used : AfterClass(org.junit.AfterClass) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) NodeConfigurationSource(org.elasticsearch.test.NodeConfigurationSource) MasterNotDiscoveredException(org.elasticsearch.discovery.MasterNotDiscoveredException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) IOException(java.io.IOException) MockTcpTransportPlugin(org.elasticsearch.transport.MockTcpTransportPlugin) Plugin(org.elasticsearch.plugins.Plugin) Before(org.junit.Before)

Aggregations

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