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