@Test @RunWithCustomExecutor public void givingQueryWhenMetadataExceptionThenReturnFatal() throws Exception { HandlerIO handlerIO = mock(HandlerIO.class); MetaDataClient metaDataClient = mock(MetaDataClient.class); given(metaDataClientFactory.getClient()).willReturn(metaDataClient); VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID); JsonNode queryNode = JsonHandler.getFromInputStream( getClass().getResourceAsStream("/PrepareUpdateUnits/query.json")); given(handlerIO.getJsonFromWorkspace("query.json")).willReturn(queryNode); given(metaDataClient.selectUnits(any())).willThrow(MetaDataClientServerException.class); File distributionFile = tempFolder.newFile(); given(handlerIO.getOutput(DISTRIBUTION_FILE_RANK)).willReturn(new ProcessingUri(UriPrefix.WORKSPACE, distributionFile.getPath())); given(handlerIO.getNewLocalFile(distributionFile.getPath())).willReturn(distributionFile); ItemStatus itemStatus = prepareUpdateUnits.execute(WorkerParametersFactory.newWorkerParameters(), handlerIO); assertThat(itemStatus).isNotNull(); assertThat(itemStatus.getGlobalStatus()).isEqualTo(StatusCode.FATAL); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(PREPARE_UPDATE_UNIT_LIST); try (MetaDataClient client = metaDataClientFactory.getClient()) { JsonNode queryNode = handler.getJsonFromWorkspace("query.json"); SelectMultiQuery multiQuery = getSelectQueryFromJson(queryNode); final String distribFileName = handler.getOutput(DISTRIBUTION_FILE_RANK).getPath(); final File distribFile = handler.getNewLocalFile(distribFileName); final ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, multiQuery, batchSize); createDistributionFile(scrollRequest, distribFile); handler.transferFileToWorkspace(distribFileName, distribFile, true, false); itemStatus.increment(StatusCode.OK); } catch (InvalidParseOperationException | ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(PREPARE_UPDATE_UNIT_LIST).setItemsStatus(PREPARE_UPDATE_UNIT_LIST, itemStatus); }
PrepareUpdateUnits extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(PREPARE_UPDATE_UNIT_LIST); try (MetaDataClient client = metaDataClientFactory.getClient()) { JsonNode queryNode = handler.getJsonFromWorkspace("query.json"); SelectMultiQuery multiQuery = getSelectQueryFromJson(queryNode); final String distribFileName = handler.getOutput(DISTRIBUTION_FILE_RANK).getPath(); final File distribFile = handler.getNewLocalFile(distribFileName); final ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, multiQuery, batchSize); createDistributionFile(scrollRequest, distribFile); handler.transferFileToWorkspace(distribFileName, distribFile, true, false); itemStatus.increment(StatusCode.OK); } catch (InvalidParseOperationException | ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(PREPARE_UPDATE_UNIT_LIST).setItemsStatus(PREPARE_UPDATE_UNIT_LIST, itemStatus); } }
PrepareUpdateUnits extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(PREPARE_UPDATE_UNIT_LIST); try (MetaDataClient client = metaDataClientFactory.getClient()) { JsonNode queryNode = handler.getJsonFromWorkspace("query.json"); SelectMultiQuery multiQuery = getSelectQueryFromJson(queryNode); final String distribFileName = handler.getOutput(DISTRIBUTION_FILE_RANK).getPath(); final File distribFile = handler.getNewLocalFile(distribFileName); final ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, multiQuery, batchSize); createDistributionFile(scrollRequest, distribFile); handler.transferFileToWorkspace(distribFileName, distribFile, true, false); itemStatus.increment(StatusCode.OK); } catch (InvalidParseOperationException | ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(PREPARE_UPDATE_UNIT_LIST).setItemsStatus(PREPARE_UPDATE_UNIT_LIST, itemStatus); } PrepareUpdateUnits(); @VisibleForTesting  PrepareUpdateUnits(MetaDataClientFactory metaDataClientFactory, int batchSize); }
PrepareUpdateUnits extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(PREPARE_UPDATE_UNIT_LIST); try (MetaDataClient client = metaDataClientFactory.getClient()) { JsonNode queryNode = handler.getJsonFromWorkspace("query.json"); SelectMultiQuery multiQuery = getSelectQueryFromJson(queryNode); final String distribFileName = handler.getOutput(DISTRIBUTION_FILE_RANK).getPath(); final File distribFile = handler.getNewLocalFile(distribFileName); final ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, multiQuery, batchSize); createDistributionFile(scrollRequest, distribFile); handler.transferFileToWorkspace(distribFileName, distribFile, true, false); itemStatus.increment(StatusCode.OK); } catch (InvalidParseOperationException | ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(PREPARE_UPDATE_UNIT_LIST).setItemsStatus(PREPARE_UPDATE_UNIT_LIST, itemStatus); } PrepareUpdateUnits(); @VisibleForTesting  PrepareUpdateUnits(MetaDataClientFactory metaDataClientFactory, int batchSize); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); }
PrepareUpdateUnits extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { final ItemStatus itemStatus = new ItemStatus(PREPARE_UPDATE_UNIT_LIST); try (MetaDataClient client = metaDataClientFactory.getClient()) { JsonNode queryNode = handler.getJsonFromWorkspace("query.json"); SelectMultiQuery multiQuery = getSelectQueryFromJson(queryNode); final String distribFileName = handler.getOutput(DISTRIBUTION_FILE_RANK).getPath(); final File distribFile = handler.getNewLocalFile(distribFileName); final ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, multiQuery, batchSize); createDistributionFile(scrollRequest, distribFile); handler.transferFileToWorkspace(distribFileName, distribFile, true, false); itemStatus.increment(StatusCode.OK); } catch (InvalidParseOperationException | ProcessingException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(PREPARE_UPDATE_UNIT_LIST).setItemsStatus(PREPARE_UPDATE_UNIT_LIST, itemStatus); } PrepareUpdateUnits(); @VisibleForTesting  PrepareUpdateUnits(MetaDataClientFactory metaDataClientFactory, int batchSize); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler);  }