@Test public void testWaitWithThreeParametersPauseThenTrue() throws Exception { RequestResponseOK<ItemStatus> pause = new RequestResponseOK<ItemStatus>().addResult(new ItemStatus().setGlobalState(ProcessState.PAUSE).increment( StatusCode.OK)); OperationStatusClient operationStatusClient = mock(OperationStatusClient.class); when(operationStatusClient.getOperationProcessStatus(any(), any())) .thenReturn(pause); VitamPoolingClient vitamPoolingClient = new VitamPoolingClient(operationStatusClient); boolean wait = vitamPoolingClient.wait(TENANT_ID, GUID, null); assertThat(wait).isTrue(); }
public boolean wait(int tenantId, String processId, ProcessState state, int nbTry, long timeWait, TimeUnit timeUnit) throws VitamException { StopWatch stopWatch = StopWatch.createStarted(); do { final RequestResponse<ItemStatus> requestResponse = this.operationStatusClient.getOperationProcessStatus( new VitamContext(tenantId), processId); if (requestResponse.isOk()) { ItemStatus itemStatus = ((RequestResponseOK<ItemStatus>) requestResponse).getResults().get(0); final ProcessState processState = itemStatus.getGlobalState(); final StatusCode statusCode = itemStatus.getGlobalStatus(); switch (processState) { case COMPLETED: return true; case PAUSE: if (StatusCode.STARTED.compareTo(statusCode) <= 0) { return true; } if (stopWatch.getTime(TimeUnit.MINUTES) >= 1) { return false; } break; case RUNNING: break; } if (null != timeUnit) { timeWait = timeUnit.toMillis(timeWait); } nbTry--; if (nbTry > 0) { try { Thread.sleep(timeWait); } catch (InterruptedException e) { SysErrLogger.FAKE_LOGGER.ignoreLog(e); } } } else { throw new VitamException((VitamError) requestResponse); } } while (nbTry > 0); return false; }
VitamPoolingClient { public boolean wait(int tenantId, String processId, ProcessState state, int nbTry, long timeWait, TimeUnit timeUnit) throws VitamException { StopWatch stopWatch = StopWatch.createStarted(); do { final RequestResponse<ItemStatus> requestResponse = this.operationStatusClient.getOperationProcessStatus( new VitamContext(tenantId), processId); if (requestResponse.isOk()) { ItemStatus itemStatus = ((RequestResponseOK<ItemStatus>) requestResponse).getResults().get(0); final ProcessState processState = itemStatus.getGlobalState(); final StatusCode statusCode = itemStatus.getGlobalStatus(); switch (processState) { case COMPLETED: return true; case PAUSE: if (StatusCode.STARTED.compareTo(statusCode) <= 0) { return true; } if (stopWatch.getTime(TimeUnit.MINUTES) >= 1) { return false; } break; case RUNNING: break; } if (null != timeUnit) { timeWait = timeUnit.toMillis(timeWait); } nbTry--; if (nbTry > 0) { try { Thread.sleep(timeWait); } catch (InterruptedException e) { SysErrLogger.FAKE_LOGGER.ignoreLog(e); } } } else { throw new VitamException((VitamError) requestResponse); } } while (nbTry > 0); return false; } }
VitamPoolingClient { public boolean wait(int tenantId, String processId, ProcessState state, int nbTry, long timeWait, TimeUnit timeUnit) throws VitamException { StopWatch stopWatch = StopWatch.createStarted(); do { final RequestResponse<ItemStatus> requestResponse = this.operationStatusClient.getOperationProcessStatus( new VitamContext(tenantId), processId); if (requestResponse.isOk()) { ItemStatus itemStatus = ((RequestResponseOK<ItemStatus>) requestResponse).getResults().get(0); final ProcessState processState = itemStatus.getGlobalState(); final StatusCode statusCode = itemStatus.getGlobalStatus(); switch (processState) { case COMPLETED: return true; case PAUSE: if (StatusCode.STARTED.compareTo(statusCode) <= 0) { return true; } if (stopWatch.getTime(TimeUnit.MINUTES) >= 1) { return false; } break; case RUNNING: break; } if (null != timeUnit) { timeWait = timeUnit.toMillis(timeWait); } nbTry--; if (nbTry > 0) { try { Thread.sleep(timeWait); } catch (InterruptedException e) { SysErrLogger.FAKE_LOGGER.ignoreLog(e); } } } else { throw new VitamException((VitamError) requestResponse); } } while (nbTry > 0); return false; } VitamPoolingClient(OperationStatusClient operationStatusClient); }
VitamPoolingClient { public boolean wait(int tenantId, String processId, ProcessState state, int nbTry, long timeWait, TimeUnit timeUnit) throws VitamException { StopWatch stopWatch = StopWatch.createStarted(); do { final RequestResponse<ItemStatus> requestResponse = this.operationStatusClient.getOperationProcessStatus( new VitamContext(tenantId), processId); if (requestResponse.isOk()) { ItemStatus itemStatus = ((RequestResponseOK<ItemStatus>) requestResponse).getResults().get(0); final ProcessState processState = itemStatus.getGlobalState(); final StatusCode statusCode = itemStatus.getGlobalStatus(); switch (processState) { case COMPLETED: return true; case PAUSE: if (StatusCode.STARTED.compareTo(statusCode) <= 0) { return true; } if (stopWatch.getTime(TimeUnit.MINUTES) >= 1) { return false; } break; case RUNNING: break; } if (null != timeUnit) { timeWait = timeUnit.toMillis(timeWait); } nbTry--; if (nbTry > 0) { try { Thread.sleep(timeWait); } catch (InterruptedException e) { SysErrLogger.FAKE_LOGGER.ignoreLog(e); } } } else { throw new VitamException((VitamError) requestResponse); } } while (nbTry > 0); return false; } VitamPoolingClient(OperationStatusClient operationStatusClient); boolean wait(int tenantId, String processId, ProcessState state, int nbTry, long timeWait, TimeUnit timeUnit); boolean wait(int tenantId, String processId, int nbTry, long timeout, TimeUnit timeUnit); boolean wait(int tenantId, String processId, ProcessState state); boolean wait(int tenantId, String processId); }
VitamPoolingClient { public boolean wait(int tenantId, String processId, ProcessState state, int nbTry, long timeWait, TimeUnit timeUnit) throws VitamException { StopWatch stopWatch = StopWatch.createStarted(); do { final RequestResponse<ItemStatus> requestResponse = this.operationStatusClient.getOperationProcessStatus( new VitamContext(tenantId), processId); if (requestResponse.isOk()) { ItemStatus itemStatus = ((RequestResponseOK<ItemStatus>) requestResponse).getResults().get(0); final ProcessState processState = itemStatus.getGlobalState(); final StatusCode statusCode = itemStatus.getGlobalStatus(); switch (processState) { case COMPLETED: return true; case PAUSE: if (StatusCode.STARTED.compareTo(statusCode) <= 0) { return true; } if (stopWatch.getTime(TimeUnit.MINUTES) >= 1) { return false; } break; case RUNNING: break; } if (null != timeUnit) { timeWait = timeUnit.toMillis(timeWait); } nbTry--; if (nbTry > 0) { try { Thread.sleep(timeWait); } catch (InterruptedException e) { SysErrLogger.FAKE_LOGGER.ignoreLog(e); } } } else { throw new VitamException((VitamError) requestResponse); } } while (nbTry > 0); return false; } VitamPoolingClient(OperationStatusClient operationStatusClient); boolean wait(int tenantId, String processId, ProcessState state, int nbTry, long timeWait, TimeUnit timeUnit); boolean wait(int tenantId, String processId, int nbTry, long timeout, TimeUnit timeUnit); boolean wait(int tenantId, String processId, ProcessState state); boolean wait(int tenantId, String processId);  }