DefaultApplicationSlaManagementService implements ApplicationSlaManagementService { @Override public Observable<Void> removeApplicationSLA(String applicationName) { if (applicationName.equals(DEFAULT_APPLICATION)) { return Observable.error(new IllegalArgumentException(DEFAULT_APPLICATION + " cannot be removed")); } return storage.remove(applicationName).doOnCompleted(() -> capacityMonitoringService.refresh().subscribe()); } @Inject  DefaultApplicationSlaManagementService(CapacityMonitoringService capacityMonitoringService,
                                                  ApplicationSlaStore storage,
                                                  ManagementSubsystemInitializer initializer); @Override Collection<ApplicationSLA> getApplicationSLAs(); @Override Collection<ApplicationSLA> getApplicationSLAsForScheduler(String schedulerName); @Override Optional<ApplicationSLA> findApplicationSLA(String applicationName); @Override ApplicationSLA getApplicationSLA(String applicationName); @Override Observable<Void> addApplicationSLA(ApplicationSLA applicationSLA); @Override Observable<Void> removeApplicationSLA(String applicationName);  }
@Test public void testRemovePersistsApplicationSlaAndUpdatesCapacityRequirements() throws Exception { ApplicationSLA myApp = ApplicationSlaSample.CriticalSmall.build(); when(storage.findAll()).thenReturn(Observable.just(myApp)); when(storage.remove(myApp.getAppName())).thenReturn(Observable.empty()); ObservableRecorder<Void> cpmRecorder = ObservableRecorder.newRecorder(Observable.empty()); when(capacityMonitoringService.refresh()).thenReturn(cpmRecorder.getObservable()); slaManagementService.removeApplicationSLA(myApp.getAppName()).toBlocking().firstOrDefault(null); testScheduler.triggerActions(); verify(capacityMonitoringService, times(1)).refresh(); assertThat(cpmRecorder.numberOfFinishedSubscriptions()).isEqualTo(1); }
@Test public void testRemoveNotAllowedForDefaultApplication() throws Exception { try { slaManagementService.removeApplicationSLA(DEFAULT_APPLICATION).toBlocking().firstOrDefault(null); fail(DEFAULT_APPLICATION + " cannot be removed"); } catch (IllegalArgumentException e) { } }