use of org.apache.storm.utils.LocalState 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 port = 9999;
int memOnheap = 512;
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);
MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", port, la, null, ls, workerId, new HashMap<>(), ops, "profile");
assertListEquals(Arrays.asList("-Xloggc:/tmp/storm/logs/gc.worker-9999-s-01-w-01-9999.log", "-Xms256m", "-Xmx512m"), mc.substituteChildopts("-Xloggc:/tmp/storm/logs/gc.worker-%ID%-%TOPOLOGY-ID%-%WORKER-ID%-%WORKER-PORT%.log -Xms256m -Xmx%HEAP-MEM%m", memOnheap));
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));
assertListEquals(Collections.emptyList(), mc.substituteChildopts(null));
}
use of org.apache.storm.utils.LocalState in project storm by apache.
the class BasicContainerTest method testCreateNewWorkerId.
@Test
public void testCreateNewWorkerId() throws Exception {
final String topoId = "test_topology";
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);
MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", port, la, null, ls, null, 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.utils.LocalState 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 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);
MockBasicContainer mc = new MockBasicContainer(ContainerType.RECOVER_FULL, superConf, "SUPERVISOR", port, la, null, ls, null, new HashMap<>(), ops, "profile");
assertEquals(workerId, mc._workerId);
}
use of org.apache.storm.utils.LocalState in project storm by apache.
the class SlotTest method testRelaunch.
@Test
public void testRelaunch() throws Exception {
try (SimulatedTime t = new SimulatedTime(1010)) {
int port = 8080;
String topoId = "CURRENT";
List<ExecutorInfo> execList = mkExecutorInfoList(1, 2, 3, 4, 5);
LocalAssignment assignment = mkLocalAssignment(topoId, execList, mkWorkerResources(100.0, 100.0, 100.0));
ILocalizer localizer = mock(ILocalizer.class);
Container container = mock(Container.class);
ContainerLauncher containerLauncher = mock(ContainerLauncher.class);
LSWorkerHeartbeat oldhb = mkWorkerHB(topoId, port, execList, Time.currentTimeSecs() - 10);
LSWorkerHeartbeat goodhb = mkWorkerHB(topoId, port, execList, Time.currentTimeSecs());
when(container.readHeartbeat()).thenReturn(oldhb, oldhb, goodhb, goodhb);
when(container.areAllProcessesDead()).thenReturn(false, true);
ISupervisor iSuper = mock(ISupervisor.class);
LocalState state = mock(LocalState.class);
StaticState staticState = new StaticState(localizer, 5000, 120000, 1000, 1000, containerLauncher, "localhost", port, iSuper, state);
DynamicState dynamicState = new DynamicState(assignment, container, assignment);
DynamicState nextState = Slot.stateMachineStep(dynamicState, staticState);
assertEquals(MachineState.KILL_AND_RELAUNCH, nextState.state);
verify(container).kill();
assertTrue(Time.currentTimeMillis() > 1000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.KILL_AND_RELAUNCH, nextState.state);
verify(container).forceKill();
assertTrue(Time.currentTimeMillis() > 2000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.WAITING_FOR_WORKER_START, nextState.state);
verify(container).relaunch();
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.WAITING_FOR_WORKER_START, nextState.state);
assertTrue(Time.currentTimeMillis() > 3000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.RUNNING, nextState.state);
}
}
Aggregations