CalvalusStaging { void observeStagingStatus(String jobId) throws WpsStagingException { ProductionService productionService; Production production; try { productionService = CalvalusProductionService.getServiceContainerSingleton().getProductionService(); production = productionService.getProduction(jobId); String userName = production.getProductionRequest().getUserName(); while (!production.getStagingStatus().isDone()) { Thread.sleep(500); productionService.updateStatuses(userName); ProcessStatus stagingStatus = production.getStagingStatus(); LOG.info(String.format("Staging status: state=%s, progress=%s, message='%s'", stagingStatus.getState(), stagingStatus.getProgress(), stagingStatus.getMessage())); } } catch (ProductionException | IOException | InterruptedException exception) { throw new WpsStagingException(exception); } if (production.getStagingStatus().getState() == ProcessState.COMPLETED) { LOG.info("Staging completed."); } else { LOG.log(Level.SEVERE, "Error: Staging did not complete normally: " + production.getStagingStatus().getMessage()); } } CalvalusStaging(WpsServerContext wpsServerContext);   }
@Ignore @Test public void canObserveStagingStatusStillRunning() throws Exception { PowerMockito.mockStatic(CalvalusLogger.class); PowerMockito.mockStatic(Thread.class); PowerMockito.mockStatic(CalvalusProductionService.class); Logger mockLogger = mock(Logger.class); PowerMockito.when(CalvalusLogger.getLogger()).thenReturn(mockLogger); mockProductionService = mock(ProductionService.class); ProductionRequest mockProductionRequest = mock(ProductionRequest.class); ProcessStatus mockProcessStatus = getProcessStatusStillRunning(); when(mockProductionRequest.getUserName()).thenReturn(DUMMY_USER_NAME); when(mockProduction.getName()).thenReturn(DUMMY_JOB_ID); when(mockProduction.getStagingPath()).thenReturn(DUMMY_PATH); when(mockProduction.getProductionRequest()).thenReturn(mockProductionRequest); when(mockProduction.getStagingStatus()).thenReturn(mockProcessStatus); when(mockProductionService.getProduction(anyString())).thenReturn(mockProduction); ServiceContainer mockServiceContainer = mock(ServiceContainer.class); PowerMockito.when(mockServiceContainer.getProductionService()).thenReturn(mockProductionService); PowerMockito.when(CalvalusProductionService.getServiceContainerSingleton()).thenReturn(mockServiceContainer); ArgumentCaptor<String> userCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<String> statusCaptor = ArgumentCaptor.forClass(String.class); calvalusStaging = new CalvalusStaging(mockServerContext); calvalusStaging.observeStagingStatus("jobId"); verify(mockProductionService, times(2)).updateStatuses(userCaptor.capture()); verify(mockLogger, times(3)).info(statusCaptor.capture()); assertThat(userCaptor.getValue(), equalTo("dummyUser")); assertThat(statusCaptor.getAllValues().get(0), equalTo("Staging status: state=RUNNING, progress=0.8, message='Still running'")); assertThat(statusCaptor.getAllValues().get(1), equalTo("Staging status: state=RUNNING, progress=0.9, message='Still running'")); assertThat(statusCaptor.getAllValues().get(2), equalTo("Staging completed.")); }
@Ignore @Test public void canObserveStagingStatusAlreadyDone() throws Exception { mockProductionService = mock(ProductionService.class); ProductionRequest mockProductionRequest = mock(ProductionRequest.class); ProcessStatus mockProcessStatus = getProcessStatusAlreadyDone(); when(mockProductionRequest.getUserName()).thenReturn(DUMMY_USER_NAME); when(mockProduction.getName()).thenReturn(DUMMY_JOB_ID); when(mockProduction.getStagingPath()).thenReturn(DUMMY_PATH); when(mockProduction.getProductionRequest()).thenReturn(mockProductionRequest); when(mockProduction.getStagingStatus()).thenReturn(mockProcessStatus); when(mockProductionService.getProduction(anyString())).thenReturn(mockProduction); ServiceContainer mockServiceContainer = mock(ServiceContainer.class); PowerMockito.when(mockServiceContainer.getProductionService()).thenReturn(mockProductionService); PowerMockito.when(CalvalusProductionService.getServiceContainerSingleton()).thenReturn(mockServiceContainer); Logger mockLogger2 = mock(Logger.class); PowerMockito.mockStatic(CalvalusLogger.class); PowerMockito.when(CalvalusLogger.getLogger()).thenReturn(mockLogger2); ArgumentCaptor<String> statusCaptor = ArgumentCaptor.forClass(String.class); calvalusStaging = new CalvalusStaging(mockServerContext); calvalusStaging.observeStagingStatus("jobId"); verify(mockLogger2, times(1)).info(statusCaptor.capture()); assertThat(statusCaptor.getValue(), equalTo("Staging completed.")); }