Search in sources :

Example 16 with InternalTestCluster

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

the class InternalTestClusterTests method testBeforeTest.

public void testBeforeTest() throws Exception {
    final boolean autoManageMinMasterNodes = randomBoolean();
    long clusterSeed = randomLong();
    final boolean masterNodes;
    final int minNumDataNodes;
    final int maxNumDataNodes;
    final int bootstrapMasterNodeIndex;
    if (autoManageMinMasterNodes) {
        masterNodes = randomBoolean();
        minNumDataNodes = randomIntBetween(0, 3);
        maxNumDataNodes = randomIntBetween(minNumDataNodes, 4);
        bootstrapMasterNodeIndex = -1;
    } else {
        // if we manage min master nodes, we need to lock down the number of nodes
        minNumDataNodes = randomIntBetween(0, 4);
        maxNumDataNodes = minNumDataNodes;
        masterNodes = false;
        bootstrapMasterNodeIndex = maxNumDataNodes == 0 ? -1 : randomIntBetween(0, maxNumDataNodes - 1);
    }
    final int numClientNodes = randomIntBetween(0, 2);
    String transportClient = getTestTransportType();
    NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() {

        @Override
        public Settings nodeSettings(int nodeOrdinal) {
            final Settings.Builder settings = Settings.builder().put(DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "file").putList(SettingsBasedSeedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey()).put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType());
            if (autoManageMinMasterNodes == false) {
                assert minNumDataNodes == maxNumDataNodes;
                assert masterNodes == false;
            }
            return settings.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 = "foobar";
    InternalTestCluster cluster0 = new InternalTestCluster(clusterSeed, createTempDir(), masterNodes, autoManageMinMasterNodes, minNumDataNodes, maxNumDataNodes, "clustername", nodeConfigurationSource, numClientNodes, nodePrefix, mockPlugins());
    cluster0.setBootstrapMasterNodeIndex(bootstrapMasterNodeIndex);
    InternalTestCluster cluster1 = new InternalTestCluster(clusterSeed, createTempDir(), masterNodes, autoManageMinMasterNodes, minNumDataNodes, maxNumDataNodes, "clustername", nodeConfigurationSource, numClientNodes, nodePrefix, mockPlugins());
    cluster1.setBootstrapMasterNodeIndex(bootstrapMasterNodeIndex);
    assertClusters(cluster0, cluster1, false);
    long seed = randomLong();
    try {
        {
            Random random = new Random(seed);
            cluster0.beforeTest(random);
        }
        {
            Random random = new Random(seed);
            cluster1.beforeTest(random);
        }
        assertArrayEquals(cluster0.getNodeNames(), cluster1.getNodeNames());
        Iterator<Client> iterator1 = cluster1.getClients().iterator();
        for (Client client : cluster0.getClients()) {
            assertTrue(iterator1.hasNext());
            Client other = iterator1.next();
            assertSettings(client.settings(), other.settings(), false);
        }
        cluster0.afterTest();
        cluster1.afterTest();
    } finally {
        IOUtils.close(cluster0, cluster1);
    }
}
Also used : Random(java.util.Random) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) NodeConfigurationSource(org.elasticsearch.test.NodeConfigurationSource) Client(org.elasticsearch.client.Client) Settings(org.elasticsearch.common.settings.Settings)

Example 17 with InternalTestCluster

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

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

Example 18 with InternalTestCluster

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

the class InternalTestClusterTests method testDifferentRolesMaintainPathOnRestart.

public void testDifferentRolesMaintainPathOnRestart() throws Exception {
    final Path baseDir = createTempDir();
    final int numNodes = 5;
    String transportClient = getTestTransportType();
    InternalTestCluster cluster = new InternalTestCluster(randomLong(), baseDir, false, false, 0, 0, "test", new NodeConfigurationSource() {

        @Override
        public Settings nodeSettings(int nodeOrdinal) {
            return Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType()).put(Node.INITIAL_STATE_TIMEOUT_SETTING.getKey(), 0).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();
        }
    }, 0, "", mockPlugins());
    cluster.beforeTest(random());
    List<DiscoveryNodeRole> roles = new ArrayList<>();
    for (int i = 0; i < numNodes; i++) {
        final DiscoveryNodeRole role = i == numNodes - 1 && roles.contains(DiscoveryNodeRole.MASTER_ROLE) == false ? // last node and still no master
        DiscoveryNodeRole.MASTER_ROLE : randomFrom(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE);
        roles.add(role);
    }
    cluster.setBootstrapMasterNodeIndex(randomIntBetween(0, (int) roles.stream().filter(role -> role.equals(DiscoveryNodeRole.MASTER_ROLE)).count() - 1));
    try {
        Map<DiscoveryNodeRole, Set<String>> pathsPerRole = new HashMap<>();
        for (int i = 0; i < numNodes; i++) {
            final DiscoveryNodeRole role = roles.get(i);
            final String node;
            if (role == DiscoveryNodeRole.MASTER_ROLE) {
                node = cluster.startMasterOnlyNode();
            } else if (role == DiscoveryNodeRole.DATA_ROLE) {
                node = cluster.startDataOnlyNode();
            } else {
                throw new IllegalStateException("get your story straight");
            }
            Set<String> rolePaths = pathsPerRole.computeIfAbsent(role, k -> new HashSet<>());
            for (Path path : getNodePaths(cluster, node)) {
                assertTrue(rolePaths.add(path.toString()));
            }
        }
        cluster.validateClusterFormed();
        cluster.fullRestart();
        Map<DiscoveryNodeRole, Set<String>> result = new HashMap<>();
        for (String name : cluster.getNodeNames()) {
            DiscoveryNode node = cluster.getInstance(ClusterService.class, name).localNode();
            List<String> paths = Arrays.stream(getNodePaths(cluster, name)).map(Path::toString).collect(Collectors.toList());
            if (node.isMasterEligibleNode()) {
                result.computeIfAbsent(DiscoveryNodeRole.MASTER_ROLE, k -> new HashSet<>()).addAll(paths);
            } else {
                result.computeIfAbsent(DiscoveryNodeRole.DATA_ROLE, k -> new HashSet<>()).addAll(paths);
            }
        }
        assertThat(result.size(), equalTo(pathsPerRole.size()));
        for (DiscoveryNodeRole role : result.keySet()) {
            assertThat("path are not the same for " + role, result.get(role), equalTo(pathsPerRole.get(role)));
        }
    } finally {
        cluster.close();
    }
}
Also used : Path(java.nio.file.Path) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) SettingsBasedSeedHostsProvider(org.elasticsearch.discovery.SettingsBasedSeedHostsProvider) Arrays(java.util.Arrays) NetworkModule(org.elasticsearch.common.network.NetworkModule) Environment(org.elasticsearch.env.Environment) ClusterService(org.elasticsearch.cluster.service.ClusterService) Matchers.not(org.hamcrest.Matchers.not) HashMap(java.util.HashMap) Random(java.util.Random) ElasticsearchAssertions.assertFileNotExists(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFileNotExists) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) DiscoveryModule(org.elasticsearch.discovery.DiscoveryModule) Map(java.util.Map) Node(org.elasticsearch.node.Node) ESTestCase(org.elasticsearch.test.ESTestCase) Path(java.nio.file.Path) Iterator(java.util.Iterator) Files(java.nio.file.Files) IOUtils(io.crate.common.io.IOUtils) Client(org.elasticsearch.client.Client) Collection(java.util.Collection) Plugin(org.elasticsearch.plugins.Plugin) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) MockHttpTransport(org.elasticsearch.test.MockHttpTransport) List(java.util.List) ElasticsearchAssertions.assertFileExists(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFileExists) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) Matchers.equalTo(org.hamcrest.Matchers.equalTo) NodeConfigurationSource(org.elasticsearch.test.NodeConfigurationSource) LuceneTestCase(org.apache.lucene.util.LuceneTestCase) DISCOVERY_SEED_PROVIDERS_SETTING(org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) Collections(java.util.Collections) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) HashSet(java.util.HashSet) Set(java.util.Set) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) NodeConfigurationSource(org.elasticsearch.test.NodeConfigurationSource) ClusterService(org.elasticsearch.cluster.service.ClusterService) Settings(org.elasticsearch.common.settings.Settings) HashSet(java.util.HashSet)

Example 19 with InternalTestCluster

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

the class MasterDisruptionIT method testMappingNewFieldsTimeoutDoesntAffectCheckpoints.

@Test
public void testMappingNewFieldsTimeoutDoesntAffectCheckpoints() throws Exception {
    InternalTestCluster internalCluster = internalCluster();
    internalCluster.startNodes(3, Settings.builder().put(MappingUpdatedAction.INDICES_MAPPING_DYNAMIC_TIMEOUT_SETTING.getKey(), "1ms").build());
    ensureStableCluster(3);
    logger.info("creating table t with 1 shards and 1 replica");
    execute("create table t (id int primary key, x object(dynamic)) clustered into 1 shards with " + "(number_of_replicas = 1, \"routing.allocation.exclude._name\" = '" + internalCluster().getMasterName() + "', \"write.wait_for_active_shards\" = 1)");
    ensureGreen();
    execute("insert into t values (?, ?)", new Object[] { 1, Map.of("first field", "first value") });
    ServiceDisruptionScheme disruption = new BlockMasterServiceOnMaster(random());
    setDisruptionScheme(disruption);
    disruption.startDisrupting();
    try {
        execute("insert into t values (?, ?), (?, ?), (?, ?)", new Object[] { 2, Map.of("2nd field", "2nd value"), 3, Map.of("3rd field", "3rd value"), 4, Map.of("4th field", "4th value") });
    } catch (Exception e) {
    // failure is acceptable
    }
    disruption.stopDisrupting();
    String indexName = toIndexName(sqlExecutor.getCurrentSchema(), "t", null);
    assertBusy(() -> {
        IndicesStatsResponse stats = client().admin().indices().prepareStats(indexName).clear().get();
        for (ShardStats shardStats : stats.getShards()) {
            assertThat(shardStats.getShardRouting().toString(), shardStats.getSeqNoStats().getGlobalCheckpoint(), equalTo(shardStats.getSeqNoStats().getLocalCheckpoint()));
        }
    }, 1, TimeUnit.MINUTES);
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) ServiceDisruptionScheme(org.elasticsearch.test.disruption.ServiceDisruptionScheme) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) BlockMasterServiceOnMaster(org.elasticsearch.test.disruption.BlockMasterServiceOnMaster) Test(org.junit.Test)

Aggregations

InternalTestCluster (org.elasticsearch.test.InternalTestCluster)19 NodeConfigurationSource (org.elasticsearch.test.NodeConfigurationSource)11 Path (java.nio.file.Path)10 Settings (org.elasticsearch.common.settings.Settings)6 IOException (java.io.IOException)5 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)5 Plugin (org.elasticsearch.plugins.Plugin)5 MockTcpTransportPlugin (org.elasticsearch.transport.MockTcpTransportPlugin)5 HashMap (java.util.HashMap)4 Random (java.util.Random)4 Client (org.elasticsearch.client.Client)4 ClusterService (org.elasticsearch.cluster.service.ClusterService)4 DiscoverySettings (org.elasticsearch.discovery.DiscoverySettings)3 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)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