use of org.apache.storm.metric.StormMetricsRegistry in project storm by apache.
the class BasicContainerTest method testCleanUp.
@Test
public void testCleanUp() throws Exception {
final String topoId = "test_topology";
final int supervisorPort = 6628;
final int port = 8080;
final String workerId = "worker-id";
LocalAssignment la = new LocalAssignment();
la.set_topology_id(topoId);
Map<String, Object> superConf = new HashMap<>();
AdvancedFSOps ops = mock(AdvancedFSOps.class);
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
Map<String, Integer> workerState = new HashMap<String, Integer>();
workerState.put(workerId, port);
LocalState ls = mock(LocalState.class);
when(ls.getApprovedWorkers()).thenReturn(new HashMap<>(workerState));
ResourceIsolationInterface iso = mock(ResourceIsolationInterface.class);
MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", supervisorPort, port, la, iso, ls, workerId, new StormMetricsRegistry(), new HashMap<>(), ops, "profile");
mc.cleanUp();
assertNull(mc.workerId);
verify(ls).getApprovedWorkers();
Map<String, Integer> expectedNewState = new HashMap<String, Integer>();
verify(ls).setApprovedWorkers(expectedNewState);
}
use of org.apache.storm.metric.StormMetricsRegistry in project storm by apache.
the class BasicContainerTest method testSubstChildOpts.
@Test
public void testSubstChildOpts() throws Exception {
String workerId = "w-01";
String topoId = "s-01";
int supervisorPort = 6628;
int port = 9999;
int memOnheap = 512;
int memOffheap = 256;
LocalAssignment la = new LocalAssignment();
la.set_topology_id(topoId);
Map<String, Object> superConf = new HashMap<>();
AdvancedFSOps ops = mock(AdvancedFSOps.class);
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
LocalState ls = mock(LocalState.class);
ResourceIsolationInterface iso = mock(ResourceIsolationInterface.class);
MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", supervisorPort, port, la, iso, ls, workerId, new StormMetricsRegistry(), new HashMap<>(), ops, "profile");
assertListEquals(Arrays.asList("-Xloggc:/tmp/storm/logs/gc.worker-9999-s-01-w-01-9999.log", "-Xms256m", "-Xmx512m", "-XX:MaxDirectMemorySize=256m"), mc.substituteChildopts("-Xloggc:/tmp/storm/logs/gc.worker-%ID%-%TOPOLOGY-ID%-%WORKER-ID%-%WORKER-PORT%.log -Xms256m -Xmx%HEAP-MEM%m -XX:MaxDirectMemorySize=%OFF-HEAP-MEM%m", memOnheap, memOffheap));
assertListEquals(Arrays.asList("-Xloggc:/tmp/storm/logs/gc.worker-9999-s-01-w-01-9999.log", "-Xms256m", "-Xmx512m"), mc.substituteChildopts(Arrays.asList("-Xloggc:/tmp/storm/logs/gc.worker-%ID%-%TOPOLOGY-ID%-%WORKER-ID%-%WORKER-PORT%.log", "-Xms256m", "-Xmx%HEAP-MEM%m"), memOnheap, memOffheap));
assertListEquals(Collections.emptyList(), mc.substituteChildopts(null));
}
use of org.apache.storm.metric.StormMetricsRegistry in project storm by apache.
the class BasicContainerTest method testRecovery.
@Test
public void testRecovery() throws Exception {
final String topoId = "test_topology";
final String workerId = "myWorker";
final int supervisorPort = 6628;
final int port = 8080;
LocalAssignment la = new LocalAssignment();
la.set_topology_id(topoId);
Map<String, Integer> workerState = new HashMap<String, Integer>();
workerState.put(workerId, port);
LocalState ls = mock(LocalState.class);
when(ls.getApprovedWorkers()).thenReturn(workerState);
Map<String, Object> superConf = new HashMap<>();
AdvancedFSOps ops = mock(AdvancedFSOps.class);
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
ResourceIsolationInterface iso = mock(ResourceIsolationInterface.class);
MockBasicContainer mc = new MockBasicContainer(ContainerType.RECOVER_FULL, superConf, "SUPERVISOR", supervisorPort, port, la, iso, ls, null, new StormMetricsRegistry(), new HashMap<>(), ops, "profile");
assertEquals(workerId, mc.workerId);
}
use of org.apache.storm.metric.StormMetricsRegistry in project storm by apache.
the class BasicContainerTest method testCreateNewWorkerId.
@Test
public void testCreateNewWorkerId() throws Exception {
final String topoId = "test_topology";
final int supervisorPort = 6628;
final int port = 8080;
LocalAssignment la = new LocalAssignment();
la.set_topology_id(topoId);
Map<String, Object> superConf = new HashMap<>();
AdvancedFSOps ops = mock(AdvancedFSOps.class);
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
LocalState ls = mock(LocalState.class);
ResourceIsolationInterface iso = mock(ResourceIsolationInterface.class);
MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", supervisorPort, port, la, iso, ls, null, new StormMetricsRegistry(), new HashMap<>(), ops, "profile");
// null worker id means generate one...
assertNotNull(mc.workerId);
verify(ls).getApprovedWorkers();
Map<String, Integer> expectedNewState = new HashMap<String, Integer>();
expectedNewState.put(mc.workerId, port);
verify(ls).setApprovedWorkers(expectedNewState);
}
use of org.apache.storm.metric.StormMetricsRegistry in project storm by apache.
the class BasicContainerTest method testRunProfiling.
@Test
public void testRunProfiling() throws Exception {
final long pid = 100;
final String topoId = "test_topology";
final int supervisorPort = 6628;
final int port = 8080;
final String workerId = "worker-id";
final String stormLocal = ContainerTest.asAbsPath("tmp", "testing");
final String topoRoot = ContainerTest.asAbsPath(stormLocal, topoId, String.valueOf(port));
final File workerArtifactsPid = ContainerTest.asAbsFile(topoRoot, "worker.pid");
final Map<String, Object> superConf = new HashMap<>();
superConf.put(Config.STORM_LOCAL_DIR, stormLocal);
superConf.put(Config.STORM_WORKERS_ARTIFACTS_DIR, stormLocal);
LocalAssignment la = new LocalAssignment();
la.set_topology_id(topoId);
AdvancedFSOps ops = mock(AdvancedFSOps.class);
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
when(ops.slurpString(workerArtifactsPid)).thenReturn(String.valueOf(pid));
LocalState ls = mock(LocalState.class);
MockResourceIsolationManager iso = new MockResourceIsolationManager();
MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", supervisorPort, port, la, iso, ls, workerId, new StormMetricsRegistry(), new HashMap<>(), ops, "profile");
// HEAP DUMP
ProfileRequest req = new ProfileRequest();
req.set_action(ProfileAction.JMAP_DUMP);
mc.runProfiling(req, false);
assertEquals(1, iso.profileCmds.size());
CommandRun cmd = iso.profileCmds.get(0);
iso.profileCmds.clear();
assertEquals(Arrays.asList("profile", String.valueOf(pid), "jmap", topoRoot), cmd.cmd);
assertEquals(new File(topoRoot), cmd.pwd);
// JSTACK DUMP
req.set_action(ProfileAction.JSTACK_DUMP);
mc.runProfiling(req, false);
assertEquals(1, iso.profileCmds.size());
cmd = iso.profileCmds.get(0);
iso.profileCmds.clear();
assertEquals(Arrays.asList("profile", String.valueOf(pid), "jstack", topoRoot), cmd.cmd);
assertEquals(new File(topoRoot), cmd.pwd);
// RESTART
req.set_action(ProfileAction.JVM_RESTART);
mc.runProfiling(req, false);
assertEquals(1, iso.profileCmds.size());
cmd = iso.profileCmds.get(0);
iso.profileCmds.clear();
assertEquals(Arrays.asList("profile", String.valueOf(pid), "kill"), cmd.cmd);
assertEquals(new File(topoRoot), cmd.pwd);
// JPROFILE DUMP
req.set_action(ProfileAction.JPROFILE_DUMP);
mc.runProfiling(req, false);
assertEquals(1, iso.profileCmds.size());
cmd = iso.profileCmds.get(0);
iso.profileCmds.clear();
assertEquals(Arrays.asList("profile", String.valueOf(pid), "dump", topoRoot), cmd.cmd);
assertEquals(new File(topoRoot), cmd.pwd);
// JPROFILE START
req.set_action(ProfileAction.JPROFILE_STOP);
mc.runProfiling(req, false);
assertEquals(1, iso.profileCmds.size());
cmd = iso.profileCmds.get(0);
iso.profileCmds.clear();
assertEquals(Arrays.asList("profile", String.valueOf(pid), "start"), cmd.cmd);
assertEquals(new File(topoRoot), cmd.pwd);
// JPROFILE STOP
req.set_action(ProfileAction.JPROFILE_STOP);
mc.runProfiling(req, true);
assertEquals(1, iso.profileCmds.size());
cmd = iso.profileCmds.get(0);
iso.profileCmds.clear();
assertEquals(Arrays.asList("profile", String.valueOf(pid), "stop", topoRoot), cmd.cmd);
assertEquals(new File(topoRoot), cmd.pwd);
}
Aggregations