events: test refactored as Spring Boot test to verify random delay expression and default value in yaml
This commit is contained in:
parent
efe5677c80
commit
6a7a9ac1ec
@ -29,6 +29,9 @@ import org.thingsboard.server.service.ttl.AbstractCleanUpService;
|
|||||||
@Service
|
@Service
|
||||||
public class EventsCleanUpService extends AbstractCleanUpService {
|
public class EventsCleanUpService extends AbstractCleanUpService {
|
||||||
|
|
||||||
|
public static final String RANDOM_DELAY_INTERVAL_MS_EXPRESSION =
|
||||||
|
"#{T(org.apache.commons.lang3.RandomUtils).nextLong(0, ${sql.ttl.events.execution_interval_ms})}";
|
||||||
|
|
||||||
@Value("${sql.ttl.events.events_ttl}")
|
@Value("${sql.ttl.events.events_ttl}")
|
||||||
private long ttl;
|
private long ttl;
|
||||||
|
|
||||||
@ -45,7 +48,7 @@ public class EventsCleanUpService extends AbstractCleanUpService {
|
|||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(initialDelayString = "#{T(org.apache.commons.lang3.RandomUtils).nextLong(0, ${sql.ttl.events.execution_interval_ms})}", fixedDelayString = "${sql.ttl.events.execution_interval_ms}")
|
@Scheduled(initialDelayString = RANDOM_DELAY_INTERVAL_MS_EXPRESSION, fixedDelayString = "${sql.ttl.events.execution_interval_ms}")
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
if (ttlTaskExecutionEnabled && isSystemTenantPartitionMine()) {
|
if (ttlTaskExecutionEnabled && isSystemTenantPartitionMine()) {
|
||||||
eventService.cleanupEvents(ttl, debugTtl);
|
eventService.cleanupEvents(ttl, debugTtl);
|
||||||
|
|||||||
@ -17,20 +17,34 @@ package org.thingsboard.server.service.ttl;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||||
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||||
|
import static org.thingsboard.server.service.ttl.EventsCleanUpService.RANDOM_DELAY_INTERVAL_MS_EXPRESSION;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(classes = EventsCleanUpServiceTest.class)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class EventsCleanUpServiceTest {
|
public class EventsCleanUpServiceTest {
|
||||||
|
|
||||||
|
@Value(RANDOM_DELAY_INTERVAL_MS_EXPRESSION)
|
||||||
|
long randomDelayMs;
|
||||||
|
@Value("${sql.ttl.events.execution_interval_ms}")
|
||||||
|
long executionIntervalMs;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenInterval_whenRandomDelay_ThenDelayInInterval() {
|
public void givenInterval_whenRandomDelay_ThenDelayInInterval() {
|
||||||
final long executionIntervalMs = 2220000; //37min
|
log.info("randomDelay {}", randomDelayMs);
|
||||||
final long randomDelay = org.apache.commons.lang3.RandomUtils.nextLong(0, executionIntervalMs); //same as @Scheduled(initialDelayString = ...
|
log.info("executionIntervalMs {}", executionIntervalMs);
|
||||||
log.info("randomDelay {}", randomDelay);
|
assertThat(executionIntervalMs, is(2220000L));
|
||||||
assertThat(randomDelay, greaterThanOrEqualTo(0L));
|
assertThat(randomDelayMs, greaterThanOrEqualTo(0L));
|
||||||
assertThat(randomDelay, lessThanOrEqualTo(executionIntervalMs));
|
assertThat(randomDelayMs, lessThanOrEqualTo(executionIntervalMs));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user