use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.
the class LogConfigManagerTest method testLogResetTriggersForPastTime.
@Test
public void testLogResetTriggersForPastTime() {
try (SimulatedTime t = new SimulatedTime()) {
long past = Time.currentTimeMillis() - 1000;
TreeMap<String, LogLevel> config = new TreeMap<>();
config.put("foo", ll("INFO", "WARN", past));
AtomicReference<TreeMap<String, LogLevel>> atomConf = new AtomicReference<>(config);
LogConfigManager underTest = new LogConfigManagerUnderTest(atomConf);
underTest.resetLogLevels();
assertEquals(new TreeMap<>(), atomConf.get());
}
}
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"));
}
}
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());
}
}
use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.
the class KafkaSpoutRebalanceTest method spoutMustIgnoreAcksForTuplesItIsNotAssignedAfterRebalance.
@Test
public void spoutMustIgnoreAcksForTuplesItIsNotAssignedAfterRebalance() throws Exception {
//Acking tuples for partitions that are no longer assigned is useless since the spout will not be allowed to commit them
try (SimulatedTime simulatedTime = new SimulatedTime()) {
KafkaSpout<String, String> spout = new KafkaSpout<>(getKafkaSpoutConfig(-1, this.offsetCommitPeriodMs), consumerFactory);
String topic = SingleTopicKafkaSpoutConfiguration.TOPIC;
TopicPartition partitionThatWillBeRevoked = new TopicPartition(topic, 1);
TopicPartition assignedPartition = new TopicPartition(topic, 2);
//Emit a message on each partition and revoke the first partition
List<KafkaSpoutMessageId> emittedMessageIds = emitOneMessagePerPartitionThenRevokeOnePartition(spout, partitionThatWillBeRevoked, assignedPartition);
//Ack both emitted tuples
spout.ack(emittedMessageIds.get(0));
spout.ack(emittedMessageIds.get(1));
//Ensure the commit timer has expired
Time.advanceTime(offsetCommitPeriodMs + KafkaSpout.TIMER_DELAY_MS);
//Make the spout commit any acked tuples
spout.nextTuple();
//Verify that it only committed the message on the assigned partition
verify(consumerMock, times(1)).commitSync(commitCapture.capture());
Map<TopicPartition, OffsetAndMetadata> commitCaptureMap = commitCapture.getValue();
assertThat(commitCaptureMap, hasKey(assignedPartition));
assertThat(commitCaptureMap, not(hasKey(partitionThatWillBeRevoked)));
}
}
use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.
the class SingleTopicKafkaSpoutTest method shouldReplayInOrderFailedMessages.
@Test
public void shouldReplayInOrderFailedMessages() throws Exception {
try (SimulatedTime simulatedTime = new SimulatedTime()) {
int messageCount = 10;
initializeSpout(messageCount);
//play and ack 1 tuple
ArgumentCaptor<Object> messageIdAcked = ArgumentCaptor.forClass(Object.class);
spout.nextTuple();
verify(collector).emit(anyObject(), anyObject(), messageIdAcked.capture());
spout.ack(messageIdAcked.getValue());
reset(collector);
//play and fail 1 tuple
ArgumentCaptor<Object> messageIdFailed = ArgumentCaptor.forClass(Object.class);
spout.nextTuple();
verify(collector).emit(anyObject(), anyObject(), messageIdFailed.capture());
spout.fail(messageIdFailed.getValue());
reset(collector);
//Emit all remaining messages. Failed tuples retry immediately with current configuration, so no need to wait.
IntStream.range(0, messageCount).forEach(value -> {
spout.nextTuple();
});
ArgumentCaptor<Object> remainingMessageIds = ArgumentCaptor.forClass(Object.class);
//All messages except the first acked message should have been emitted
verify(collector, times(messageCount - 1)).emit(eq(SingleTopicKafkaSpoutConfiguration.STREAM), anyObject(), remainingMessageIds.capture());
remainingMessageIds.getAllValues().iterator().forEachRemaining(spout::ack);
Time.advanceTime(commitOffsetPeriodMs + KafkaSpout.TIMER_DELAY_MS);
//Commit offsets
spout.nextTuple();
verifyAllMessagesCommitted(messageCount);
}
}
Aggregations