use of org.apache.storm.generated.LocalAssignment 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.generated.LocalAssignment 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);
}
}
use of org.apache.storm.generated.LocalAssignment in project storm by apache.
the class SlotTest method testEquivilant.
@Test
public void testEquivilant() {
LocalAssignment a = mkLocalAssignment("A", mkExecutorInfoList(1, 2, 3, 4, 5), mkWorkerResources(100.0, 100.0, 100.0));
LocalAssignment aResized = mkLocalAssignment("A", mkExecutorInfoList(1, 2, 3, 4, 5), mkWorkerResources(100.0, 200.0, 100.0));
LocalAssignment b = mkLocalAssignment("B", mkExecutorInfoList(1, 2, 3, 4, 5, 6), mkWorkerResources(100.0, 100.0, 100.0));
LocalAssignment bReordered = mkLocalAssignment("B", mkExecutorInfoList(6, 5, 4, 3, 2, 1), mkWorkerResources(100.0, 100.0, 100.0));
assertTrue(Slot.equivalent(null, null));
assertTrue(Slot.equivalent(a, a));
assertTrue(Slot.equivalent(b, bReordered));
assertTrue(Slot.equivalent(bReordered, b));
assertFalse(Slot.equivalent(a, aResized));
assertFalse(Slot.equivalent(aResized, a));
assertFalse(Slot.equivalent(a, null));
assertFalse(Slot.equivalent(null, b));
assertFalse(Slot.equivalent(a, b));
}
Aggregations