Skip to content

Commit

Permalink
Merge pull request #290 from jrslv/system-tests-refactoring
Browse files Browse the repository at this point in the history
Refactored system tests to use Configuration object
  • Loading branch information
jrslv committed Oct 20, 2015
2 parents 6bb1a8b + 0929960 commit 33477a0
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.apache.mesos.elasticsearch.systemtest;

/**
* SystemTest configuration object
*/
public class Configuration {
private String executorImageName = "mesos/elasticsearch-executor";
private String schedulerImageName = "mesos/elasticsearch-scheduler";
private String schedulerName = "elasticsearch-scheduler";
private int schedulerGuiPort = 31100;
private int privateRegistryPort = 15000;
private int elasticsearchNodesCount = 3;
private int elasticsearchMemorySize = 256;
private String elasticsearchJobName = "esdemo";

public String getExecutorImageName() {
return executorImageName;
}

public String getSchedulerImageName() {
return schedulerImageName;
}

public String getSchedulerName() {
return schedulerName;
}

public int getSchedulerGuiPort() {
return schedulerGuiPort;
}

public int getPrivateRegistryPort() {
return privateRegistryPort;
}

public int getElasticsearchNodesCount() {
return elasticsearchNodesCount;
}

public int getElasticsearchMemorySize() {
return elasticsearchMemorySize;
}

public String getElasticsearchJobName() {
return elasticsearchJobName;
}

public String[] getPortRanges() {
return new String[]{
"ports(*):[9200-9200,9300-9300]",
"ports(*):[9201-9201,9301-9301]",
"ports(*):[9202-9202,9302-9302]"
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@
*/
public class ElasticsearchSchedulerContainer extends AbstractContainer {

public static final String SCHEDULER_IMAGE = "mesos/elasticsearch-scheduler";

public static final String SCHEDULER_NAME = "elasticsearch-scheduler";
private static final org.apache.mesos.elasticsearch.systemtest.Configuration TEST_CONFIG = new org.apache.mesos.elasticsearch.systemtest.Configuration();

protected String mesosIp;

private String frameworkRole;

private String zookeeperFrameworkUrl;

private String dataDirectory;

protected ElasticsearchSchedulerContainer(DockerClient dockerClient, String mesosIp) {
Expand All @@ -42,27 +39,26 @@ protected ElasticsearchSchedulerContainer(DockerClient dockerClient, String meso

@Override
protected void pullImage() {
dockerClient.pullImageCmd(SCHEDULER_IMAGE);
dockerClient.pullImageCmd(TEST_CONFIG.getSchedulerImageName());
}

@Override
protected CreateContainerCmd dockerCommand() {
return dockerClient
.createContainerCmd(SCHEDULER_IMAGE)
.withName(SCHEDULER_NAME + "_" + new SecureRandom().nextInt())
.createContainerCmd(TEST_CONFIG.getSchedulerImageName())
.withName(TEST_CONFIG.getSchedulerName() + "_" + new SecureRandom().nextInt())
.withEnv("JAVA_OPTS=-Xms128m -Xmx256m")
.withExtraHosts(IntStream.rangeClosed(1, 3).mapToObj(value -> "slave" + value + ":" + mesosIp).toArray(String[]::new))
.withCmd(
ZookeeperCLIParameter.ZOOKEEPER_MESOS_URL, getZookeeperMesosUrl(),
ZookeeperCLIParameter.ZOOKEEPER_FRAMEWORK_URL, getZookeeperFrameworkUrl(),
ZookeeperCLIParameter.ZOOKEEPER_FRAMEWORK_TIMEOUT, "30000",
ElasticsearchCLIParameter.ELASTICSEARCH_NODES, "3",
Configuration.ELASTICSEARCH_RAM, "256",
Configuration.WEB_UI_PORT, "31100",
Configuration.EXECUTOR_NAME, "esdemo",
ElasticsearchCLIParameter.ELASTICSEARCH_NODES, Integer.toString(TEST_CONFIG.getElasticsearchNodesCount()),
Configuration.ELASTICSEARCH_RAM, Integer.toString(TEST_CONFIG.getElasticsearchMemorySize()),
Configuration.WEB_UI_PORT, Integer.toString(TEST_CONFIG.getSchedulerGuiPort()),
Configuration.EXECUTOR_NAME, TEST_CONFIG.getElasticsearchJobName(),
Configuration.DATA_DIR, getDataDirectory(),
Configuration.FRAMEWORK_ROLE, frameworkRole
);
Configuration.FRAMEWORK_ROLE, frameworkRole);
}

private String getDataDirectory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
/**
* Main app to run Mesos Elasticsearch with Mini Mesos.
*/
@SuppressWarnings({"PMD.AvoidUsingHardCodedIP"})
public class Main {

public static final Logger LOGGER = Logger.getLogger(Main.class);
public static final Configuration TEST_CONFIG = new Configuration();

public static void main(String[] args) throws InterruptedException {
MesosCluster cluster = new MesosCluster(
MesosClusterConfig.builder()
.numberOfSlaves(3)
.privateRegistryPort(15000) // Currently you have to choose an available port by yourself
.slaveResources(new String[]{"ports(*):[9200-9200,9300-9300]", "ports(*):[9201-9201,9301-9301]", "ports(*):[9202-9202,9302-9302]"})
.numberOfSlaves(TEST_CONFIG.getElasticsearchNodesCount())
.privateRegistryPort(TEST_CONFIG.getPrivateRegistryPort()) // Currently you have to choose an available port by yourself
.slaveResources(TEST_CONFIG.getPortRanges())
.build()
);

Expand All @@ -37,7 +37,7 @@ public void run() {
}
});
cluster.start();
cluster.injectImage("mesos/elasticsearch-executor");
cluster.injectImage(TEST_CONFIG.getExecutorImageName());

LOGGER.info("Starting scheduler");

Expand All @@ -47,7 +47,7 @@ public void run() {

seedData(cluster, scheduler);

LOGGER.info("Scheduler started at http://" + scheduler.getIpAddress() + ":31100");
LOGGER.info("Scheduler started at http://" + scheduler.getIpAddress() + ":" + TEST_CONFIG.getSchedulerGuiPort());
LOGGER.info("Type CTRL-C to quit");
while (true) {
Thread.sleep(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class TasksResponse {

public static final Logger LOGGER = Logger.getLogger(TasksResponse.class);

private static final Configuration TEST_CONFIG = new Configuration();
private HttpResponse<JsonNode> response;
private String schedulerIpAddress;
private int nodesCount;
Expand All @@ -41,11 +42,10 @@ public TasksResponse(String schedulerIpAddress, int nodesCount, String nodesStat
}

class TasksCall implements Callable<Boolean> {

@Override
public Boolean call() throws Exception {
try {
String tasksEndPoint = "http://" + schedulerIpAddress + ":31100/v1/tasks";
String tasksEndPoint = "http://" + schedulerIpAddress + ":" + TEST_CONFIG.getSchedulerGuiPort() + "/v1/tasks";
LOGGER.debug("Fetching tasks on " + tasksEndPoint);
response = Unirest.get(tasksEndPoint).asJson();
if (nodesState == null || nodesState.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
/**
* Tests scheduler APIs
*/
@SuppressWarnings({"PMD.AvoidUsingHardCodedIP"})
public class DataRetrievableAllNodesSystemTest extends TestBase {

private static final Logger LOGGER = Logger.getLogger(DataRetrievableAllNodesSystemTest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import org.apache.mesos.mini.MesosCluster;
import org.apache.mesos.mini.mesos.MesosClusterConfig;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.*;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -21,23 +18,23 @@
/**
* Tests data volumes
*/
@SuppressWarnings({"PMD.AvoidUsingHardCodedIP"})
public class DataVolumesSystemTest {

public static final Logger LOGGER = Logger.getLogger(DataVolumesSystemTest.class);
protected static final org.apache.mesos.elasticsearch.systemtest.Configuration TEST_CONFIG = new org.apache.mesos.elasticsearch.systemtest.Configuration();

@Rule
public final MesosCluster cluster = new MesosCluster(
MesosClusterConfig.builder()
.numberOfSlaves(3)
.privateRegistryPort(15000) // Currently you have to choose an available port by yourself
.slaveResources(new String[]{"ports(*):[9200-9200,9300-9300]", "ports(*):[9201-9201,9301-9301]", "ports(*):[9202-9202,9302-9302]"})
.numberOfSlaves(TEST_CONFIG.getElasticsearchNodesCount())
.privateRegistryPort(TEST_CONFIG.getPrivateRegistryPort()) // Currently you have to choose an available port by yourself
.slaveResources(TEST_CONFIG.getPortRanges())
.build()
);

@Before
public void beforeScheduler() throws Exception {
cluster.injectImage("mesos/elasticsearch-executor");
cluster.injectImage(TEST_CONFIG.getExecutorImageName());
}

@After
Expand All @@ -50,7 +47,7 @@ public void testDataVolumes() {
LOGGER.info("Starting Elasticsearch scheduler");
ElasticsearchSchedulerContainer scheduler = new ElasticsearchSchedulerContainer(cluster.getConfig().dockerClient, cluster.getMesosContainer().getIpAddress());
cluster.addAndStartContainer(scheduler);
LOGGER.info("Started Elasticsearch scheduler on " + scheduler.getIpAddress() + ":8080");
LOGGER.info("Started Elasticsearch scheduler on " + scheduler.getIpAddress() + ":" + TEST_CONFIG.getSchedulerGuiPort());

TasksResponse tasksResponse = new TasksResponse(scheduler.getIpAddress(), cluster.getConfig().getNumberOfSlaves());

Expand Down Expand Up @@ -83,7 +80,7 @@ public void testDataVolumes_differentDataDir() {
String dataDirectory = "/var/lib/mesos/slave";
scheduler.setDataDirectory(dataDirectory);
cluster.addAndStartContainer(scheduler);
LOGGER.info("Started Elasticsearch scheduler on " + scheduler.getIpAddress() + ":8080");
LOGGER.info("Started Elasticsearch scheduler on " + scheduler.getIpAddress() + ":" + TEST_CONFIG.getSchedulerGuiPort());

TasksResponse tasksResponse = new TasksResponse(scheduler.getIpAddress(), cluster.getConfig().getNumberOfSlaves());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,5 @@ public void ensureEnvVarPointsToLibMesos() throws IOException {
execCmdStream = clusterClient.execStartCmd(exec.getId()).exec();
result = IOUtils.toString(execCmdStream, "UTF-8");
assertFalse(result.contains("No such file"));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
* Tests configuration of framework roles
*/
public class FrameworkRoleSystemTest {
protected static final int NODE_COUNT = 3;
protected static final Configuration TEST_CONFIG = new Configuration();

protected static final MesosClusterConfig CONFIG = MesosClusterConfig.builder()
.numberOfSlaves(NODE_COUNT)
.privateRegistryPort(15000) // Currently you have to choose an available port by yourself
.slaveResources(new String[]{"ports(*):[9200-9200,9300-9300]", "ports(*):[9201-9201,9301-9301]", "ports(*):[9202-9202,9302-9302]"})
.numberOfSlaves(TEST_CONFIG.getElasticsearchNodesCount())
.privateRegistryPort(TEST_CONFIG.getPrivateRegistryPort()) // Currently you have to choose an available port by yourself
.slaveResources(TEST_CONFIG.getPortRanges())
.extraEnvironmentVariables(new TreeMap<String, String>(){{
this.put("MESOS_ROLES", "*,foobar");
}})
Expand Down Expand Up @@ -64,7 +64,7 @@ private void testMiniMesosReportsFrameworkRole(String role) throws UnirestExcept
role
);
CLUSTER.addAndStartContainer(scheduler);
LOGGER.info("Started Elasticsearch scheduler on " + scheduler.getIpAddress() + ":31100");
LOGGER.info("Started Elasticsearch scheduler on " + scheduler.getIpAddress() + ":" + TEST_CONFIG.getSchedulerGuiPort());

Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> CLUSTER.getStateInfo().getFramework("elasticsearch") != null);
Assert.assertEquals(role, CLUSTER.getStateInfo().getFramework("elasticsearch").getRole());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,23 @@
public class ReconciliationSystemTest {
public static final int DOCKER_PORT = 2376;
private static final Logger LOGGER = Logger.getLogger(ReconciliationSystemTest.class);
private static final int CLUSTER_SIZE = 3;
@ClassRule
public static final MesosCluster CLUSTER = new MesosCluster(
MesosClusterConfig.builder()
.numberOfSlaves(CLUSTER_SIZE)
.privateRegistryPort(15000) // Currently you have to choose an available port by yourself
.slaveResources(new String[]{"ports(*):[9200-9200,9300-9300]", "ports(*):[9201-9201,9301-9301]", "ports(*):[9202-9202,9302-9302]"})
.build()
);
private static final org.apache.mesos.elasticsearch.systemtest.Configuration TEST_CONFIG = new org.apache.mesos.elasticsearch.systemtest.Configuration();

private static final int TIMEOUT = 60;
private static final String MESOS_LOCAL_IMAGE_NAME = "mesos-local";
private static final ContainerLifecycleManagement CONTAINER_MANAGER = new ContainerLifecycleManagement();
private static String mesosClusterId;
private static DockerClient innerDockerClient;

@ClassRule
public static final MesosCluster CLUSTER = new MesosCluster(
MesosClusterConfig.builder()
.numberOfSlaves(TEST_CONFIG.getElasticsearchNodesCount())
.privateRegistryPort(TEST_CONFIG.getPrivateRegistryPort()) // Currently you have to choose an available port by yourself
.slaveResources(TEST_CONFIG.getPortRanges())
.build()
);

@BeforeClass
public static void beforeScheduler() throws Exception {
String innerDockerHost;
Expand All @@ -62,7 +64,7 @@ public static void beforeScheduler() throws Exception {
innerDockerClient = DockerClientBuilder.getInstance(dockerConfigBuilder.build()).build();

LOGGER.debug("Injecting executor");
CLUSTER.injectImage("mesos/elasticsearch-executor");
CLUSTER.injectImage(TEST_CONFIG.getExecutorImageName());
await().atMost(TIMEOUT, TimeUnit.SECONDS).until(() -> CLUSTER.getConfig().dockerClient.listContainersCmd().exec().size() > 0); // Wait until mesos-local has started.
List<Container> containers = CLUSTER.getConfig().dockerClient.listContainersCmd().exec();

Expand Down Expand Up @@ -93,7 +95,7 @@ public void forceCheckExecutorTimeout() throws IOException {
ElasticsearchSchedulerContainer scheduler = new TimeoutSchedulerContainer(CLUSTER.getConfig().dockerClient, CLUSTER.getMesosContainer().getIpAddress());
CONTAINER_MANAGER.addAndStart(scheduler);
assertCorrectNumberOfExecutors(); // Start with 3
assertLessThan(CLUSTER_SIZE); // Then should be less than 3, because at some point we kill an executor
assertLessThan(TEST_CONFIG.getElasticsearchNodesCount()); // Then should be less than 3, because at some point we kill an executor
assertCorrectNumberOfExecutors(); // Then at some point should get back to 3.
}

Expand Down Expand Up @@ -137,7 +139,7 @@ public void ifExecutorIsLostWhileSchedulerIsDead() throws IOException {
}

private void assertCorrectNumberOfExecutors() throws IOException {
assertCorrectNumberOfExecutors(CLUSTER_SIZE);
assertCorrectNumberOfExecutors(TEST_CONFIG.getElasticsearchNodesCount());
}

private void assertLessThan(int expected) throws IOException {
Expand Down Expand Up @@ -181,8 +183,8 @@ protected TimeoutSchedulerContainer(DockerClient dockerClient, String mesosIp) {
@Override
protected CreateContainerCmd dockerCommand() {
return dockerClient
.createContainerCmd(SCHEDULER_IMAGE)
.withName(SCHEDULER_NAME + "_" + new SecureRandom().nextInt())
.createContainerCmd(TEST_CONFIG.getSchedulerImageName())
.withName(TEST_CONFIG.getSchedulerName() + "_" + new SecureRandom().nextInt())
.withEnv("JAVA_OPTS=-Xms128m -Xmx256m")
.withExtraHosts(IntStream.rangeClosed(1, 3).mapToObj(value -> "slave" + value + ":" + mesosIp).toArray(String[]::new))
.withCmd(
Expand Down

0 comments on commit 33477a0

Please sign in to comment.