以下测试用例的睡眠100次失败,但是如果睡眠增加,则测试通过。但是,由于这是一种惰性方法,因此我想在一个函数中实现此功能以评估睡眠时间。这样就可以在不同的环境下正常工作而没有静态睡眠值。
public void testDeRegistration() throws Exception {
storeEntity(EntityType.PROCESS, "summarize4");
Process mockProcess = getStore().get(EntityType.PROCESS, "summarize4");
mockProcess.setParallel(2);
Date startTime = EntityUtil.getStartTime(mockProcess, cluster);
ExecutionInstance instance1 = new ProcessExecutionInstance(mockProcess, new DateTime(startTime), cluster);
// Schedule 3 instances.
SchedulerService.JobScheduleRequestBuilder request = (SchedulerService.JobScheduleRequestBuilder)
*emphasized text* scheduler.createRequestBuilder(handler, instance1.getId());
request.setInstance(instance1);
scheduler.register(request.build());
ExecutionInstance instance2 = new ProcessExecutionInstance(mockProcess,
new DateTime(startTime.getTime() + 60000), cluster);
SchedulerService.JobScheduleRequestBuilder request2 = (SchedulerService.JobScheduleRequestBuilder)
scheduler.createRequestBuilder(handler, instance2.getId());
request2.setInstance(instance2);
scheduler.register(request2.build());
ExecutionInstance instance3 = new ProcessExecutionInstance(mockProcess,
new DateTime(startTime.getTime() + 120000), cluster);
SchedulerService.JobScheduleRequestBuilder request3 = (SchedulerService.JobScheduleRequestBuilder)
scheduler.createRequestBuilder(handler, instance3.getId());
request3.setInstance(instance3);
scheduler.register(request3.build());
// Abort third instance
stateStore.putExecutionInstance(new InstanceState(instance3));
scheduler.unregister(handler, instance3.getId());
Thread.sleep(100);
Assert.assertEquals(((MockDAGEngine) mockDagEngine).getTotalRuns(instance1), new Integer(1));
Assert.assertEquals(((MockDAGEngine) mockDagEngine).getTotalRuns(instance2), new Integer(1));
// Second instance should not run.
Assert.assertEquals(((MockDAGEngine) mockDagEngine).getTotalRuns(instance3), null);
}
答案 0 :(得分:1)
Awaitility.await().atMost(500, TimeUnit.MILLISECONDS)
.until(() -> Objects.equals(((MockDAGEngine) mockDagEngine).getTotalRuns(instance1), 1))
与二审相同