### Question:
NacosDelayTaskExecuteEngine extends AbstractNacosTaskExecuteEngine<AbstractDelayTask> { @Override public void addTask(Object key, AbstractDelayTask newTask) { lock.lock(); try { AbstractDelayTask existTask = tasks.get(key); if (null != existTask) { newTask.merge(existTask); } tasks.put(key, newTask); } finally { lock.unlock(); } } NacosDelayTaskExecuteEngine(String name);  NacosDelayTaskExecuteEngine(String name, Logger logger);  NacosDelayTaskExecuteEngine(String name, Logger logger, long processInterval);  NacosDelayTaskExecuteEngine(String name, int initCapacity, Logger logger);  NacosDelayTaskExecuteEngine(String name, int initCapacity, Logger logger, long processInterval); @Override void addTask(Object key, AbstractDelayTask newTask);  }### Answer:
@Test public void testSize() { assertEquals(0, nacosDelayTaskExecuteEngine.size()); nacosDelayTaskExecuteEngine.addTask("test", abstractTask); assertEquals(1, nacosDelayTaskExecuteEngine.size()); nacosDelayTaskExecuteEngine.removeTask("test"); assertEquals(0, nacosDelayTaskExecuteEngine.size()); }
@Test public void testIsEmpty() { assertTrue(nacosDelayTaskExecuteEngine.isEmpty()); nacosDelayTaskExecuteEngine.addTask("test", abstractTask); assertFalse(nacosDelayTaskExecuteEngine.isEmpty()); nacosDelayTaskExecuteEngine.removeTask("test"); assertTrue(nacosDelayTaskExecuteEngine.isEmpty()); }
@Test public void testAddProcessor() throws InterruptedException { when(testTaskProcessor.process(abstractTask)).thenReturn(true); nacosDelayTaskExecuteEngine.addProcessor("test", testTaskProcessor); nacosDelayTaskExecuteEngine.addTask("test", abstractTask); TimeUnit.MILLISECONDS.sleep(200); verify(testTaskProcessor).process(abstractTask); verify(taskProcessor, never()).process(abstractTask); }
@Test public void testRemoveProcessor() throws InterruptedException { when(taskProcessor.process(abstractTask)).thenReturn(true); nacosDelayTaskExecuteEngine.addProcessor("test", testTaskProcessor); nacosDelayTaskExecuteEngine.removeProcessor("test"); nacosDelayTaskExecuteEngine.addTask("test", abstractTask); TimeUnit.MILLISECONDS.sleep(200); verify(testTaskProcessor, never()).process(abstractTask); verify(taskProcessor).process(abstractTask); }
@Test public void testRetryTaskAfterFail() throws InterruptedException { when(taskProcessor.process(abstractTask)).thenReturn(false, true); nacosDelayTaskExecuteEngine.addTask("test", abstractTask); TimeUnit.MILLISECONDS.sleep(300); verify(taskProcessor, new Times(2)).process(abstractTask); }