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);
}
}
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);
}
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();
}
}
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);
}
Aggregations