Search in sources :

Example 11 with SimulatedTime

use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.

the class LogConfigManagerTest method testLogResetShouldNotTriggerForFutureTime.

@Test
public void testLogResetShouldNotTriggerForFutureTime() {
    try (SimulatedTime t = new SimulatedTime()) {
        long theFuture = Time.currentTimeMillis() + 1000;
        TreeMap<String, LogLevel> config = new TreeMap<>();
        config.put("foo", ll(theFuture));
        AtomicReference<TreeMap<String, LogLevel>> atomConf = new AtomicReference<>(config);
        LogConfigManager underTest = new LogConfigManagerUnderTest(atomConf);
        underTest.resetLogLevels();
        assertNotNull(atomConf.get());
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeMap(java.util.TreeMap) LogLevel(org.apache.storm.generated.LogLevel) Test(org.junit.Test)

Example 12 with SimulatedTime

use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.

the class LogConfigManagerTest method testLogResetsNamedLoggersWithPastTimeout.

@Test
public void testLogResetsNamedLoggersWithPastTimeout() {
    try (SimulatedTime t = new SimulatedTime()) {
        long past = Time.currentTimeMillis() - 1000;
        TreeMap<String, LogLevel> config = new TreeMap<>();
        config.put("my_debug_logger", ll("DEBUG", "INFO", past));
        config.put("my_info_logger", ll("INFO", "WARN", past));
        config.put("my_error_logger", ll("ERROR", "INFO", past));
        AtomicReference<TreeMap<String, LogLevel>> atomConf = new AtomicReference<>(config);
        LogConfigManager underTest = spy(new LogConfigManagerUnderTest(atomConf));
        underTest.resetLogLevels();
        assertEquals(new TreeMap<>(), atomConf.get());
        verify(underTest).setLoggerLevel(anyObject(), eq("my_debug_logger"), eq("INFO"));
        verify(underTest).setLoggerLevel(anyObject(), eq("my_info_logger"), eq("WARN"));
        verify(underTest).setLoggerLevel(anyObject(), eq("my_error_logger"), eq("INFO"));
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeMap(java.util.TreeMap) LogLevel(org.apache.storm.generated.LogLevel) Test(org.junit.Test)

Example 13 with SimulatedTime

use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.

the class TimeTest method shouldAdvanceForwardTest.

@Test
public void shouldAdvanceForwardTest() {
    try (SimulatedTime t = new SimulatedTime()) {
        long current = Time.currentTimeMillis();
        Time.advanceTime(1000);
        Assert.assertEquals(Time.deltaMs(current), 1000);
        Time.advanceTime(500);
        Assert.assertEquals(Time.deltaMs(current), 1500);
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) Test(org.junit.Test)

Example 14 with SimulatedTime

use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.

the class TimeTest method shouldNotAdvanceTimeTest.

@Test
public void shouldNotAdvanceTimeTest() {
    try (SimulatedTime t = new SimulatedTime()) {
        long current = Time.currentTimeMillis();
        Time.advanceTime(0);
        Assert.assertEquals(Time.deltaMs(current), 0);
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) Test(org.junit.Test)

Example 15 with SimulatedTime

use of org.apache.storm.utils.Time.SimulatedTime 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

SimulatedTime (org.apache.storm.utils.Time.SimulatedTime)22 Test (org.junit.Test)22 TreeMap (java.util.TreeMap)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 DynamicState (org.apache.storm.daemon.supervisor.Slot.DynamicState)6 StaticState (org.apache.storm.daemon.supervisor.Slot.StaticState)6 ILocalizer (org.apache.storm.localizer.ILocalizer)6 ISupervisor (org.apache.storm.scheduler.ISupervisor)6 LocalState (org.apache.storm.utils.LocalState)6 ExecutorInfo (org.apache.storm.generated.ExecutorInfo)5 LSWorkerHeartbeat (org.apache.storm.generated.LSWorkerHeartbeat)5 LocalAssignment (org.apache.storm.generated.LocalAssignment)5 LogLevel (org.apache.storm.generated.LogLevel)5 Matchers.anyObject (org.mockito.Matchers.anyObject)4 LogConfig (org.apache.storm.generated.LogConfig)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)1 TopicPartition (org.apache.kafka.common.TopicPartition)1