@Test @RunWithCustomExecutor public void whenBuildGraphThenOK() { final int[] cpt = {0}; when(mongoCursorUnit.hasNext()).thenAnswer(o -> { if (cpt[0] > 4) { return false; } cpt[0]++; return true; }); final int[] cptGot = {0}; when(mongoCursorGot.hasNext()).thenAnswer(o -> { if (cptGot[0] > 4) { return false; } cptGot[0]++; return true; }); GraphComputeResponse response = graphBuilderService.computeGraph(MetadataCollections.UNIT, Sets.newHashSet("fake1", "fake2", "fake3"), true, true); assertThat(response.getUnitCount()).isEqualTo(3); assertThat(response.getGotCount()).isEqualTo(3); }
@Override public GraphComputeResponse computeGraph(JsonNode queryDSL) throws MetaDataException { Integer tenant = VitamThreadUtils.getVitamSession().getTenantId(); AtomicBoolean lock = lockers.get(tenant); boolean tryBuildGraph = lock.compareAndSet(false, true); if (!tryBuildGraph) { throw new MetaDataException("Compute graph process already in progress"); } try { GraphComputeResponse response = new GraphComputeResponse(); ScrollSpliterator<Set<String>> scroll = executeQuery(queryDSL); StreamSupport.stream(scroll, false).forEach( item -> { GraphComputeResponse stats = computeGraph(MetadataCollections.UNIT, item, true, false); response.increment(stats); }); return response; } finally { lock.set(false); } }
GraphComputeServiceImpl implements GraphComputeService { @Override public GraphComputeResponse computeGraph(JsonNode queryDSL) throws MetaDataException { Integer tenant = VitamThreadUtils.getVitamSession().getTenantId(); AtomicBoolean lock = lockers.get(tenant); boolean tryBuildGraph = lock.compareAndSet(false, true); if (!tryBuildGraph) { throw new MetaDataException("Compute graph process already in progress"); } try { GraphComputeResponse response = new GraphComputeResponse(); ScrollSpliterator<Set<String>> scroll = executeQuery(queryDSL); StreamSupport.stream(scroll, false).forEach( item -> { GraphComputeResponse stats = computeGraph(MetadataCollections.UNIT, item, true, false); response.increment(stats); }); return response; } finally { lock.set(false); } } }
GraphComputeServiceImpl implements GraphComputeService { @Override public GraphComputeResponse computeGraph(JsonNode queryDSL) throws MetaDataException { Integer tenant = VitamThreadUtils.getVitamSession().getTenantId(); AtomicBoolean lock = lockers.get(tenant); boolean tryBuildGraph = lock.compareAndSet(false, true); if (!tryBuildGraph) { throw new MetaDataException("Compute graph process already in progress"); } try { GraphComputeResponse response = new GraphComputeResponse(); ScrollSpliterator<Set<String>> scroll = executeQuery(queryDSL); StreamSupport.stream(scroll, false).forEach( item -> { GraphComputeResponse stats = computeGraph(MetadataCollections.UNIT, item, true, false); response.increment(stats); }); return response; } finally { lock.set(false); } } private  GraphComputeServiceImpl(
        VitamRepositoryProvider vitamRepositoryProvider,
        MetaDataImpl metaData,
        VitamCache<String, Document> cache,
        List<Integer> tenants); }
GraphComputeServiceImpl implements GraphComputeService { @Override public GraphComputeResponse computeGraph(JsonNode queryDSL) throws MetaDataException { Integer tenant = VitamThreadUtils.getVitamSession().getTenantId(); AtomicBoolean lock = lockers.get(tenant); boolean tryBuildGraph = lock.compareAndSet(false, true); if (!tryBuildGraph) { throw new MetaDataException("Compute graph process already in progress"); } try { GraphComputeResponse response = new GraphComputeResponse(); ScrollSpliterator<Set<String>> scroll = executeQuery(queryDSL); StreamSupport.stream(scroll, false).forEach( item -> { GraphComputeResponse stats = computeGraph(MetadataCollections.UNIT, item, true, false); response.increment(stats); }); return response; } finally { lock.set(false); } } private  GraphComputeServiceImpl(
        VitamRepositoryProvider vitamRepositoryProvider,
        MetaDataImpl metaData,
        VitamCache<String, Document> cache,
        List<Integer> tenants); @VisibleForTesting static synchronized GraphComputeService initialize(
        VitamRepositoryProvider vitamRepositoryProvider,
        MetaDataImpl metaData,
        VitamCache<String, Document> cache,
        List<Integer> tenants); static synchronized GraphComputeService initialize(
        VitamRepositoryProvider vitamRepositoryProvider,
        MetaDataImpl metaData); static GraphComputeService getInstance(); @Override GraphComputeResponse computeGraph(JsonNode queryDSL); @Override GraphComputeResponse computeGraph(MetadataCollections metadataCollections,
        Set<String> documentsId,
        boolean computeObjectGroupGraph, boolean invalidateComputedInheritedRules); @Override void bulkUpdateMongo(MetadataCollections metaDaCollection, List<WriteModel<Document>> collection); @Override void bulkElasticsearch(MetadataCollections metaDaCollection, Set<String> collection); @Override void bulkElasticsearch(MetadataCollections metaDaCollection, List<Document> collection); @Override void close(); @Override boolean isInProgress(); @Override LoadingCache<String, Document> getCache(); }
GraphComputeServiceImpl implements GraphComputeService { @Override public GraphComputeResponse computeGraph(JsonNode queryDSL) throws MetaDataException { Integer tenant = VitamThreadUtils.getVitamSession().getTenantId(); AtomicBoolean lock = lockers.get(tenant); boolean tryBuildGraph = lock.compareAndSet(false, true); if (!tryBuildGraph) { throw new MetaDataException("Compute graph process already in progress"); } try { GraphComputeResponse response = new GraphComputeResponse(); ScrollSpliterator<Set<String>> scroll = executeQuery(queryDSL); StreamSupport.stream(scroll, false).forEach( item -> { GraphComputeResponse stats = computeGraph(MetadataCollections.UNIT, item, true, false); response.increment(stats); }); return response; } finally { lock.set(false); } } private  GraphComputeServiceImpl(
        VitamRepositoryProvider vitamRepositoryProvider,
        MetaDataImpl metaData,
        VitamCache<String, Document> cache,
        List<Integer> tenants); @VisibleForTesting static synchronized GraphComputeService initialize(
        VitamRepositoryProvider vitamRepositoryProvider,
        MetaDataImpl metaData,
        VitamCache<String, Document> cache,
        List<Integer> tenants); static synchronized GraphComputeService initialize(
        VitamRepositoryProvider vitamRepositoryProvider,
        MetaDataImpl metaData); static GraphComputeService getInstance(); @Override GraphComputeResponse computeGraph(JsonNode queryDSL); @Override GraphComputeResponse computeGraph(MetadataCollections metadataCollections,
        Set<String> documentsId,
        boolean computeObjectGroupGraph, boolean invalidateComputedInheritedRules); @Override void bulkUpdateMongo(MetadataCollections metaDaCollection, List<WriteModel<Document>> collection); @Override void bulkElasticsearch(MetadataCollections metaDaCollection, Set<String> collection); @Override void bulkElasticsearch(MetadataCollections metaDaCollection, List<Document> collection); @Override void close(); @Override boolean isInProgress(); @Override LoadingCache<String, Document> getCache();  }