This repository has been archived by the owner on Jun 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
MesosClusterTest.java
48 lines (37 loc) · 1.76 KB
/
MesosClusterTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package org.apache.mesos.mini;
import com.github.dockerjava.api.model.PortBinding;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.apache.mesos.mini.mesos.MesosClusterConfig;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Test;
public class MesosClusterTest {
private static final MesosClusterConfig config = 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]"})
.build();
@ClassRule
public static MesosCluster cluster = new MesosCluster(config);
@Test
public void mesosClusterCanBeStarted() throws Exception {
JSONObject stateInfo = cluster.getStateInfoJSON();
Assert.assertEquals(3, stateInfo.getInt("activated_slaves"));
}
@Test
public void mesosClusterCanBeStarted2() throws Exception {
JSONObject stateInfo = cluster.getStateInfoJSON();
Assert.assertEquals(3, stateInfo.getInt("activated_slaves"));
String mesosMasterUrl = cluster.getMesosMasterURL();
Assert.assertTrue(mesosMasterUrl.contains(":5050"));
}
@Test
public void testPullAndStartContainer() throws UnirestException {
String containerId = cluster.addAndStartContainer("tutum/hello-world");
String ipAddress = config.dockerClient.inspectContainerCmd(containerId).exec().getNetworkSettings().getIpAddress();
String url = "http://" + ipAddress + ":80";
Assert.assertEquals(200, Unirest.get(url).asString().getStatus());
}
}