@Override public void run() { try { long compensationTimeMs = getCompensationTimeMs(); logger.info("Running the evict task with compensationTime {}ms", compensationTimeMs); evict(compensationTimeMs); } catch (Throwable e) { logger.error("Could not run the evict task", e); } }
@Test public void testEvictionTaskCompensationTime() throws Exception { long evictionTaskPeriodNanos = serverConfig.getEvictionIntervalTimerInMs() * 1000000; AbstractInstanceRegistry.EvictionTask testTask = spy(registry.new EvictionTask()); when(testTask.getCurrentTimeNano()) .thenReturn(1l) // less than the period .thenReturn(1l + evictionTaskPeriodNanos) // exactly 1 period .thenReturn(1l + evictionTaskPeriodNanos*2 + 10000000l) // 10ms longer than 1 period .thenReturn(1l + evictionTaskPeriodNanos*3 - 1l); // less than 1 period assertThat(testTask.getCompensationTimeMs(), is(0l)); assertThat(testTask.getCompensationTimeMs(), is(0l)); assertThat(testTask.getCompensationTimeMs(), is(10l)); assertThat(testTask.getCompensationTimeMs(), is(0l)); } }
@Override public void run() { try { long compensationTimeMs = getCompensationTimeMs(); logger.info("Running the evict task with compensationTime {}ms", compensationTimeMs); evict(compensationTimeMs); } catch (Throwable e) { logger.error("Could not run the evict task", e); } }