DefaultApplicationSlaManagementService implements ApplicationSlaManagementService { @Override public Collection<ApplicationSLA> getApplicationSLAsForScheduler(String schedulerName) { return storage.findBySchedulerName(schedulerName) .doOnError(t -> logger.error("Error retrieving ApplicationSLAs for schedulerName " + schedulerName, t)) .toList() .toBlocking() .firstOrDefault(Collections.emptyList()); } @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 testGetApplicationBySchedulerName() throws Exception { ApplicationSLA myApp = ApplicationSlaSample.CriticalSmallKubeScheduler.build(); when(storage.findBySchedulerName(myApp.getSchedulerName())).thenReturn(Observable.just(myApp)); List<ApplicationSLA> result = new ArrayList<>(slaManagementService.getApplicationSLAsForScheduler(myApp.getSchedulerName())); assertThat(result).hasSize(1); assertThat(result.get(0).getAppName()).isEqualTo(myApp.getAppName()); assertThat(result.get(0).getSchedulerName()).isEqualTo(myApp.getSchedulerName()); }
@Test public void testGetApplicationBySchedulerNameFailure() { ApplicationSLA myApp = ApplicationSlaSample.CriticalSmallKubeScheduler.build(); Observable observable = Observable.error(new RuntimeException("generic failure")); when(storage.findBySchedulerName(myApp.getSchedulerName())).thenReturn(observable); assertThatThrownBy(() -> slaManagementService.getApplicationSLAsForScheduler(myApp.getSchedulerName())).isInstanceOf(RuntimeException.class).hasMessage("generic failure"); }