Search in sources :

Example 16 with LocalState

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

Example 17 with LocalState

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

Example 18 with LocalState

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

Example 19 with LocalState

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);
    }
}
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)

Aggregations

LocalState (org.apache.storm.utils.LocalState)19 Test (org.junit.Test)13 LocalAssignment (org.apache.storm.generated.LocalAssignment)12 HashMap (java.util.HashMap)8 LSWorkerHeartbeat (org.apache.storm.generated.LSWorkerHeartbeat)7 DynamicState (org.apache.storm.daemon.supervisor.Slot.DynamicState)6 StaticState (org.apache.storm.daemon.supervisor.Slot.StaticState)6 ExecutorInfo (org.apache.storm.generated.ExecutorInfo)6 ILocalizer (org.apache.storm.localizer.ILocalizer)5 ISupervisor (org.apache.storm.scheduler.ISupervisor)5 SimulatedTime (org.apache.storm.utils.Time.SimulatedTime)5 File (java.io.File)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 LSTopoHistory (org.apache.storm.generated.LSTopoHistory)2 Preconditions (com.google.common.base.Preconditions)1 EventHandler (com.lmax.disruptor.EventHandler)1 Charset (java.nio.charset.Charset)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 Collection (java.util.Collection)1