Search in sources :

Example 21 with SimulatedTime

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

the class LogConfigManagerTest method testLogResetResetsRootLoggerIfSet.

@Test
public void testLogResetResetsRootLoggerIfSet() {
    try (SimulatedTime t = new SimulatedTime()) {
        long past = Time.currentTimeMillis() - 1000;
        TreeMap<String, LogLevel> config = new TreeMap<>();
        config.put(LogManager.ROOT_LOGGER_NAME, ll("DEBUG", "WARN", 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(LogManager.ROOT_LOGGER_NAME), eq("WARN"));
    }
}
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 22 with SimulatedTime

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

the class LogConfigManagerTest method testProcessRootLogLevelToDebugSetsLoggerAndTimeout2.

@Test
public void testProcessRootLogLevelToDebugSetsLoggerAndTimeout2() {
    try (SimulatedTime t = new SimulatedTime()) {
        LogConfig mockConfig = new LogConfig();
        AtomicReference<TreeMap<String, LogLevel>> mockConfigAtom = new AtomicReference<>(null);
        long inThirtySeconds = Time.currentTimeMillis() + 30_000;
        mockConfig.put_to_named_logger_level("ROOT", ll("DEBUG", inThirtySeconds));
        LogConfigManager underTest = spy(new LogConfigManagerUnderTest(mockConfigAtom));
        underTest.processLogConfigChange(mockConfig);
        // test that the set-logger-level function was not called
        LOG.info("Tests {}", mockConfigAtom.get());
        verify(underTest).setLoggerLevel(anyObject(), eq(""), eq("DEBUG"));
        LogLevel rootResult = mockConfigAtom.get().get(LogManager.ROOT_LOGGER_NAME);
        assertNotNull(rootResult);
        assertEquals(LogLevelAction.UPDATE, rootResult.get_action());
        assertEquals("DEBUG", rootResult.get_target_log_level());
        // defaults to INFO level when the logger isn't found previously
        assertEquals("INFO", rootResult.get_reset_log_level());
        assertEquals(inThirtySeconds, rootResult.get_reset_log_level_timeout_epoch());
    }
}
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) LogConfig(org.apache.storm.generated.LogConfig) 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