MetaNotifyTask implements Runnable { @Override public void run() { try { logger.info("[{}][construct]",taskName); new RetryNTimes<>(retryTimes, retryPolicy).execute(new AbstractCommand<Object>() { @Override public String getName() { return taskName; } @Override protected void doExecute() throws Exception { doNotify(); future().setSuccess(); } @Override protected void doReset() { } }); logger.info("[{}][success]",taskName); } catch (Exception e) { logger.error("[{}][failed][rootCause]{}",taskName, e); } } MetaNotifyTask(String taskName, int retryTimes, RetryPolicy retryPolicy); @Override void run(); abstract T doNotify();  }
@Test public void testMetaNotifyTaskSuccess() { task.run(); verify(foo, times(1)).foo(); }
@Test public void testMetaNotifyTaskFail() { doThrow(new ResourceAccessException("test")).when(foo).foo(); task.run(); verify(foo,times(retryTimes + 1)).foo(); }
@Test public void testMetaNotifyTaskRetryFail() { doThrow(new RuntimeException("test")).when(foo).foo(); task.run(); verify(foo,times(1)).foo(); }