ApplicationStopper extends AbstractPeriodicTask { @Override public void run() { applicationLocker.executeThreadSafe(this.appUid, () -> { ApplicationInfo applicationInfo = applicationRepository.findOne(appUid); if (applicationInfo == null) { handleApplicationNotFound(); } else { if (applicationInfo.getEnrollmentState().isEnrolledByService(spaceEnrollerConfigId)) { handleApplicationEnrolled(applicationInfo); } else { handleApplicationBlackListed(applicationInfo); } } }); } @Builder  ApplicationStopper(Clock clock,
                       Duration period,
                       String appUid,
                       String spaceEnrollerConfigId,
                       String bindingId,
                       CloudFoundryApiService cloudFoundryApi,
                       ApplicationRepository applicationRepository,
                       ApplicationLocker applicationLocker,
                       boolean ignoreRouteBindingError,
                       ProxyMapEntryRepository proxyMap); @Override void run();  }
@Test public void test_task_is_reschedule_even_when_remote_error() throws Exception { when(cloudFoundryApi.getApplicationActivity(APP_UID)) .thenThrow(new CloudFoundryException(new Exception("Mock call"))); applicationStopper.run(); verify(cloudFoundryApi, never()).stopApplication(APP_UID); verify(applicationStopper, times(1)).rescheduleWithDefaultPeriod(); verify(applicationRepository, times(1)).save(any(ApplicationInfo.class)); }
@Test public void test_test_start_execute_task() throws Exception { doAnswer(invocationOnMock -> { log.debug("Fake business"); applicationStopper.run(); return null; }).when(clock).scheduleTask(eq(BINDING_ID), eq(Duration.ofSeconds(0)), eq(applicationStopper)); applicationStopper.startNow(); verify(clock, times(1)).scheduleTask(BINDING_ID, Duration.ofSeconds(0), applicationStopper); verify(applicationStopper, times(1)).run(); verify(applicationRepository, times(1)).save(any(ApplicationInfo.class)); }