add randomized multi data path nodes tests

This commit is contained in:
Shay Banon 2013-12-21 23:01:22 +01:00
parent be27ed3a25
commit 30a0fc30d5
2 changed files with 49 additions and 25 deletions

View File

@ -20,16 +20,15 @@
package org.elasticsearch.indices.store;
import org.apache.lucene.store.Directory;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.index.shard.service.InternalIndexShard;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
import org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.Set;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.Matchers.*;
@ -37,16 +36,12 @@ import static org.hamcrest.Matchers.*;
/**
*
*/
@ClusterScope(scope=Scope.TEST, numNodes = 1)
public class SimpleDistributorTests extends ElasticsearchIntegrationTest {
public final static String[] STORE_TYPES = {"fs", "simplefs", "niofs", "mmapfs"};
@Test
public void testAvailableSpaceDetection() {
File dataRoot = cluster().getInstance(Environment.class).dataFiles()[0];
cluster().stopRandomNode();
cluster().startNode(settingsBuilder().putArray("path.data", new File(dataRoot, "data1").getAbsolutePath(), new File(dataRoot, "data2").getAbsolutePath()));
for (String store : STORE_TYPES) {
createIndexWithStoreType("test", store, StrictDistributor.class.getCanonicalName());
}
@ -54,50 +49,60 @@ public class SimpleDistributorTests extends ElasticsearchIntegrationTest {
@Test
public void testDirectoryToString() throws IOException {
File dataRoot = cluster().getInstance(Environment.class).dataFiles()[0];
String dataPath1 = new File(dataRoot, "data1").getCanonicalPath();
String dataPath2 = new File(dataRoot, "data2").getCanonicalPath();
cluster().stopRandomNode();
cluster().startNode(settingsBuilder().putArray("path.data", dataPath1, dataPath2));
createIndexWithStoreType("test", "niofs", "least_used");
String storeString = getStoreDirectory("test", 0).toString();
logger.info(storeString);
assertThat(storeString, startsWith("store(least_used[rate_limited(niofs(" + dataPath1));
assertThat(storeString, containsString("), rate_limited(niofs(" + dataPath2));
File[] dataPaths = dataPaths();
assertThat(storeString, startsWith("store(least_used[rate_limited(niofs(" + dataPaths[0].getAbsolutePath()));
if (dataPaths.length > 1) {
assertThat(storeString, containsString("), rate_limited(niofs(" + dataPaths[1].getAbsolutePath()));
}
assertThat(storeString, endsWith(", type=MERGE, rate=20.0)])"));
createIndexWithStoreType("test", "niofs", "random");
storeString = getStoreDirectory("test", 0).toString();
logger.info(storeString);
assertThat(storeString, startsWith("store(random[rate_limited(niofs(" + dataPath1));
assertThat(storeString, containsString("), rate_limited(niofs(" + dataPath2));
dataPaths = dataPaths();
assertThat(storeString, startsWith("store(random[rate_limited(niofs(" + dataPaths[0].getAbsolutePath()));
if (dataPaths.length > 1) {
assertThat(storeString, containsString("), rate_limited(niofs(" + dataPaths[1].getAbsolutePath()));
}
assertThat(storeString, endsWith(", type=MERGE, rate=20.0)])"));
createIndexWithStoreType("test", "mmapfs", "least_used");
storeString = getStoreDirectory("test", 0).toString();
logger.info(storeString);
assertThat(storeString, startsWith("store(least_used[rate_limited(mmapfs(" + dataPath1));
assertThat(storeString, containsString("), rate_limited(mmapfs(" + dataPath2));
dataPaths = dataPaths();
assertThat(storeString, startsWith("store(least_used[rate_limited(mmapfs(" + dataPaths[0].getAbsolutePath()));
if (dataPaths.length > 1) {
assertThat(storeString, containsString("), rate_limited(mmapfs(" + dataPaths[1].getAbsolutePath()));
}
assertThat(storeString, endsWith(", type=MERGE, rate=20.0)])"));
createIndexWithStoreType("test", "simplefs", "least_used");
storeString = getStoreDirectory("test", 0).toString();
logger.info(storeString);
assertThat(storeString, startsWith("store(least_used[rate_limited(simplefs(" + dataPath1));
assertThat(storeString, containsString("), rate_limited(simplefs(" + dataPath2));
dataPaths = dataPaths();
assertThat(storeString, startsWith("store(least_used[rate_limited(simplefs(" + dataPaths[0].getAbsolutePath()));
if (dataPaths.length > 1) {
assertThat(storeString, containsString("), rate_limited(simplefs(" + dataPaths[1].getAbsolutePath()));
}
assertThat(storeString, endsWith(", type=MERGE, rate=20.0)])"));
createIndexWithStoreType("test", "memory", "least_used");
storeString = getStoreDirectory("test", 0).toString();
logger.info(storeString);
dataPaths = dataPaths();
assertThat(storeString, equalTo("store(least_used[byte_buffer])"));
createIndexWithoutRateLimitingStoreType("test", "niofs", "least_used");
storeString = getStoreDirectory("test", 0).toString();
logger.info(storeString);
assertThat(storeString, startsWith("store(least_used[niofs(" + dataPath1));
assertThat(storeString, containsString("), niofs(" + dataPath2));
dataPaths = dataPaths();
assertThat(storeString, startsWith("store(least_used[niofs(" + dataPaths[0].getAbsolutePath()));
if (dataPaths.length > 1) {
assertThat(storeString, containsString("), niofs(" + dataPaths[1].getAbsolutePath()));
}
assertThat(storeString, endsWith(")])"));
}
@ -128,10 +133,19 @@ public class SimpleDistributorTests extends ElasticsearchIntegrationTest {
assertThat(client().admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet().isTimedOut(), equalTo(false));
}
private File[] dataPaths() {
Set<String> nodes = cluster().nodesInclude("test");
assertThat(nodes.isEmpty(), equalTo(false));
NodeEnvironment env = cluster().getInstance(NodeEnvironment.class, nodes.iterator().next());
return env.nodeDataLocations();
}
private Directory getStoreDirectory(String index, int shardId) {
IndicesService indicesService = cluster().getInstance(IndicesService.class);
Set<String> nodes = cluster().nodesInclude("test");
assertThat(nodes.isEmpty(), equalTo(false));
IndicesService indicesService = cluster().getInstance(IndicesService.class, nodes.iterator().next());
InternalIndexShard indexShard = (InternalIndexShard) (indicesService.indexService(index).shard(shardId));
return indexShard.store().directory();
}
}

View File

@ -164,6 +164,16 @@ public final class TestCluster implements Iterable<Client> {
} else {
builder.put(Transport.TransportSettings.TRANSPORT_TCP_COMPRESS, random.nextInt(10) == 0);
}
// randomize (multi/single) data path, special case for 0, don't set it at all...
int numOfDataPaths = random.nextInt(5);
if (numOfDataPaths > 0) {
StringBuilder dataPath = new StringBuilder();
for (int i = 0; i < numOfDataPaths; i++) {
dataPath.append("data/d").append(i).append(',');
}
builder.put("path.data", dataPath.toString());
}
this.defaultSettings = builder.build();
this.nodeSettingsSource = nodeSettingsSource;
}