Search in sources :

Example 11 with InternalTestCluster

use of org.opensearch.test.InternalTestCluster in project OpenSearch by opensearch-project.

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);
    String nodePrefix = randomRealisticUnicodeOfCodepointLengthBetween(1, 10);
    Path baseDir = createTempDir();
    InternalTestCluster cluster0 = new InternalTestCluster(clusterSeed, baseDir, masterNodes, randomBoolean(), minNumDataNodes, maxNumDataNodes, clusterName, nodeConfigurationSource, numClientNodes, nodePrefix, Collections.emptyList(), Function.identity());
    InternalTestCluster cluster1 = new InternalTestCluster(clusterSeed, baseDir, masterNodes, randomBoolean(), minNumDataNodes, maxNumDataNodes, clusterName, nodeConfigurationSource, numClientNodes, nodePrefix, Collections.emptyList(), Function.identity());
    assertClusters(cluster0, cluster1, true);
}
Also used : Path(java.nio.file.Path) InternalTestCluster(org.opensearch.test.InternalTestCluster) NodeConfigurationSource(org.opensearch.test.NodeConfigurationSource)

Example 12 with InternalTestCluster

use of org.opensearch.test.InternalTestCluster in project OpenSearch by opensearch-project.

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.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;
        }
    };
    String nodePrefix = "test";
    Path baseDir = createTempDir();
    InternalTestCluster cluster = new InternalTestCluster(clusterSeed, baseDir, masterNodes, true, minNumDataNodes, maxNumDataNodes, clusterName1, nodeConfigurationSource, numClientNodes, nodePrefix, mockPlugins(), Function.identity());
    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.opensearch.test.InternalTestCluster) NodeConfigurationSource(org.opensearch.test.NodeConfigurationSource) Settings(org.opensearch.common.settings.Settings) DiscoverySettings(org.opensearch.node.Node.DiscoverySettings)

Example 13 with InternalTestCluster

use of org.opensearch.test.InternalTestCluster in project OpenSearch by opensearch-project.

the class AbstractDisruptionTestCase method startCluster.

List<String> startCluster(int numberOfNodes) {
    InternalTestCluster internalCluster = internalCluster();
    List<String> nodes = internalCluster.startNodes(numberOfNodes);
    ensureStableCluster(numberOfNodes);
    return nodes;
}
Also used : InternalTestCluster(org.opensearch.test.InternalTestCluster)

Aggregations

InternalTestCluster (org.opensearch.test.InternalTestCluster)13 NodeConfigurationSource (org.opensearch.test.NodeConfigurationSource)8 Path (java.nio.file.Path)4 ClusterService (org.opensearch.cluster.service.ClusterService)4 Settings (org.opensearch.common.settings.Settings)4 ArrayList (java.util.ArrayList)3 Client (org.opensearch.client.Client)3 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)3 DiscoverySettings (org.opensearch.node.Node.DiscoverySettings)3 HashMap (java.util.HashMap)2 Random (java.util.Random)2 ClusterState (org.opensearch.cluster.ClusterState)2 ShardRouting (org.opensearch.cluster.routing.ShardRouting)2 Plugin (org.opensearch.plugins.Plugin)2 MockRepository (org.opensearch.snapshots.mockstore.MockRepository)2 MockHttpTransport (org.opensearch.test.MockHttpTransport)2 TransportService (org.opensearch.transport.TransportService)2 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Arrays (java.util.Arrays)1