Search in sources :

Example 21 with LocalAssignment

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);
}
Also used : HashMap(java.util.HashMap) LocalAssignment(org.apache.storm.generated.LocalAssignment) LocalState(org.apache.storm.utils.LocalState) Test(org.junit.Test)

Example 22 with LocalAssignment

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);
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) StaticState(org.apache.storm.daemon.supervisor.Slot.StaticState) ISupervisor(org.apache.storm.scheduler.ISupervisor) LSWorkerHeartbeat(org.apache.storm.generated.LSWorkerHeartbeat) ExecutorInfo(org.apache.storm.generated.ExecutorInfo) ILocalizer(org.apache.storm.localizer.ILocalizer) LocalAssignment(org.apache.storm.generated.LocalAssignment) DynamicState(org.apache.storm.daemon.supervisor.Slot.DynamicState) LocalState(org.apache.storm.utils.LocalState) Test(org.junit.Test)

Example 23 with LocalAssignment

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));
}
Also used : LocalAssignment(org.apache.storm.generated.LocalAssignment) Test(org.junit.Test)

Aggregations

LocalAssignment (org.apache.storm.generated.LocalAssignment)23 Test (org.junit.Test)18 HashMap (java.util.HashMap)15 LocalState (org.apache.storm.utils.LocalState)12 ExecutorInfo (org.apache.storm.generated.ExecutorInfo)8 File (java.io.File)6 Map (java.util.Map)5 DynamicState (org.apache.storm.daemon.supervisor.Slot.DynamicState)5 StaticState (org.apache.storm.daemon.supervisor.Slot.StaticState)5 LSWorkerHeartbeat (org.apache.storm.generated.LSWorkerHeartbeat)5 ILocalizer (org.apache.storm.localizer.ILocalizer)5 ISupervisor (org.apache.storm.scheduler.ISupervisor)5 SimulatedTime (org.apache.storm.utils.Time.SimulatedTime)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 List (java.util.List)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 NodeInfo (org.apache.storm.generated.NodeInfo)3 ProfileRequest (org.apache.storm.generated.ProfileRequest)3 StringWriter (java.io.StringWriter)2