Commit 1747ed9b by 朽木不可雕也

修改时间随机函数

parent f174155a
......@@ -33,6 +33,7 @@ import static com.zhiweidata.automatictest.publics.BeanContainer.SCHEDULER;
import static com.zhiweidata.automatictest.publics.BeanContainer.SQL_SESSION_FACTORY;
import static com.zhiweidata.automatictest.publics.BeanContainer.STANDARD_DATE_FORMAT;
import static java.util.Objects.nonNull;
import static com.zhiweidata.automatictest.barragecrawlerserver.util.TimeUtil.randomHour;
/**
* @author aszswaz
......@@ -55,7 +56,7 @@ public abstract class CreateTaskJob implements Job {
triggerBuilder.withDescription(description);
triggerBuilder.withIdentity(name, group);
triggerBuilder.startAt(TimeUtil.randmoDate(1));
triggerBuilder.startAt(randomHour(5));
SCHEDULER.scheduleJob(jobBuilder.build(), triggerBuilder.build());
}
......@@ -118,7 +119,7 @@ public abstract class CreateTaskJob implements Job {
triggerBuilder.withIdentity(name, group);
triggerBuilder.withDescription("弹幕导出,以及导出的excel文件的分析");
// 在未来 N 天内,随机一个时间启动弹幕的导出测试任务
triggerBuilder.startAt(TimeUtil.randmoDate(EXPORT_START_MAX_DELAY));
triggerBuilder.startAt(TimeUtil.randomDay(EXPORT_START_MAX_DELAY));
SCHEDULER.scheduleJob(jobBuilder.build(), triggerBuilder.build());
}
......
......@@ -217,7 +217,7 @@ public class ExportTaskJob implements Job {
if (responseMessage.getCode() != 409) return;
TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();
triggerBuilder.withDescription("导出弹幕测试");
triggerBuilder.startAt(TimeUtil.randmoDate(2));
triggerBuilder.startAt(TimeUtil.randomDay(2));
SCHEDULER.scheduleJob(this.detail, triggerBuilder.build());
}
}
......@@ -13,15 +13,28 @@ import org.jetbrains.annotations.NotNull;
@SuppressWarnings("JavaDoc")
public class TimeUtil {
/**
* 在未来的 X 天内,随机一个日期
* 在未来的N天内,随机一个时间
*
* @param mostDay 未来的 X 天内
* @param mostDay 未来的 N 天内
*/
@NotNull
public static Date randmoDate(int mostDay) {
public static Date randomDay(int mostDay) {
long openInterval = System.currentTimeMillis();
long closeInterval = openInterval + mostDay * 24 * 60 * 60 * 1000L;
long randmoTime = openInterval + (long) (Math.random() * (closeInterval - openInterval + 1));
return new Date(randmoTime);
long randomTime = openInterval + (long) (Math.random() * (closeInterval - openInterval + 1));
return new Date(randomTime);
}
/**
* 在未来的N小时内随机一个时间
*
* @param hour 未来的N小时内
*/
@NotNull
public static Date randomHour(int hour) {
long openInterval = System.currentTimeMillis();
long closeInterval = openInterval + hour * 60 * 60 * 1000L;
long randomTime = openInterval + (long) (Math.random() * (openInterval - closeInterval + 1));
return new Date(randomTime);
}
}
......@@ -16,7 +16,7 @@ class TimeUtilTest {
@Test
void randmoDate() {
Date date = TimeUtil.randmoDate(7);
Date date = TimeUtil.randomDay(7);
log.info(STANDARD_DATE_FORMAT.format(date));
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment