@Test public void executeWithOfflineRepository() throws Exception { ORID bucketId = AttachedEntityHelper.id(bucket); Asset asset1 = createMockAsset("#1:1"); Asset asset2 = createMockAsset("#1:2"); Asset asset3 = createMockAsset("#2:1"); List<Entry<Object, EntityId>> page = asList( createIndexEntry(bucketId, EntityHelper.id(asset1)), createIndexEntry(bucketId, EntityHelper.id(asset2)), createIndexEntry(bucketId, EntityHelper.id(asset3))); when(config.isOnline()).thenReturn(false); when(assetStore.countAssets(any())).thenReturn(3L); when(assetStore.getNextPage(any(), eq(REBUILD_PAGE_SIZE))).thenReturn(page, emptyList()); when(assetStore.getById(EntityHelper.id(asset1))).thenReturn(asset1); when(assetStore.getById(EntityHelper.id(asset2))).thenReturn(asset2); when(assetStore.getById(EntityHelper.id(asset3))).thenReturn(asset3); underTest.rebuild(repository); verify(assetStore, times(2)).getNextPage(any(), eq(REBUILD_PAGE_SIZE)); verify(browseNodeManager).createFromAssets(eq(repository), eq(asList(asset1, asset2, asset3))); }
@Override public void rebuild(final Repository repository) throws RebuildBrowseNodeFailedException { log.info("Deleting browse nodes for repository {}", repository.getName()); browseNodeManager.deleteByRepository(repository.getName()); log.info("Rebuilding browse nodes for repository {}", repository.getName()); Bucket bucket = bucketStore.read(repository.getName()); ORID bucketId = AttachedEntityHelper.id(bucket); try { long processed = 0; long total = assetStore.countAssets(ImmutableList.of(bucket)); if (total > 0) { ProgressLogIntervalHelper progressLogger = new ProgressLogIntervalHelper(log, 60); Stopwatch sw = Stopwatch.createStarted(); OIndexCursor cursor = assetStore.getIndex(AssetEntityAdapter.I_BUCKET_COMPONENT_NAME).cursor(); List<Entry<OCompositeKey, EntityId>> nextPage = assetStore.getNextPage(cursor, rebuildPageSize); while (!Iterables.isEmpty(nextPage)) { checkCancellation(); List<Asset> assets = new ArrayList<>(rebuildPageSize); for (Entry<OCompositeKey, EntityId> indexEntry : nextPage) { if (bucketId.equals(indexEntry.getKey().getKeys().get(BUCKET_KEY_ID))) { assets.add(assetStore.getById(indexEntry.getValue())); } } int assetsSize = Iterables.size(assets); browseNodeManager.createFromAssets(repository, assets); processed += assetsSize; long elapsed = sw.elapsed(TimeUnit.MILLISECONDS); progressLogger.info("Rebuilt browse nodes for {} / {} assets in {} ms", processed, total, elapsed); nextPage = assetStore.getNextPage(cursor, rebuildPageSize); } progressLogger.flush(); } } catch (Exception e) { throw new RebuildBrowseNodeFailedException("Could not re-create browse nodes", e); } }
OrientRebuildBrowseNodeService implements RebuildBrowseNodeService { @Override public void rebuild(final Repository repository) throws RebuildBrowseNodeFailedException { log.info("Deleting browse nodes for repository {}", repository.getName()); browseNodeManager.deleteByRepository(repository.getName()); log.info("Rebuilding browse nodes for repository {}", repository.getName()); Bucket bucket = bucketStore.read(repository.getName()); ORID bucketId = AttachedEntityHelper.id(bucket); try { long processed = 0; long total = assetStore.countAssets(ImmutableList.of(bucket)); if (total > 0) { ProgressLogIntervalHelper progressLogger = new ProgressLogIntervalHelper(log, 60); Stopwatch sw = Stopwatch.createStarted(); OIndexCursor cursor = assetStore.getIndex(AssetEntityAdapter.I_BUCKET_COMPONENT_NAME).cursor(); List<Entry<OCompositeKey, EntityId>> nextPage = assetStore.getNextPage(cursor, rebuildPageSize); while (!Iterables.isEmpty(nextPage)) { checkCancellation(); List<Asset> assets = new ArrayList<>(rebuildPageSize); for (Entry<OCompositeKey, EntityId> indexEntry : nextPage) { if (bucketId.equals(indexEntry.getKey().getKeys().get(BUCKET_KEY_ID))) { assets.add(assetStore.getById(indexEntry.getValue())); } } int assetsSize = Iterables.size(assets); browseNodeManager.createFromAssets(repository, assets); processed += assetsSize; long elapsed = sw.elapsed(TimeUnit.MILLISECONDS); progressLogger.info("Rebuilt browse nodes for {} / {} assets in {} ms", processed, total, elapsed); nextPage = assetStore.getNextPage(cursor, rebuildPageSize); } progressLogger.flush(); } } catch (Exception e) { throw new RebuildBrowseNodeFailedException("Could not re-create browse nodes", e); } } }
OrientRebuildBrowseNodeService implements RebuildBrowseNodeService { @Override public void rebuild(final Repository repository) throws RebuildBrowseNodeFailedException { log.info("Deleting browse nodes for repository {}", repository.getName()); browseNodeManager.deleteByRepository(repository.getName()); log.info("Rebuilding browse nodes for repository {}", repository.getName()); Bucket bucket = bucketStore.read(repository.getName()); ORID bucketId = AttachedEntityHelper.id(bucket); try { long processed = 0; long total = assetStore.countAssets(ImmutableList.of(bucket)); if (total > 0) { ProgressLogIntervalHelper progressLogger = new ProgressLogIntervalHelper(log, 60); Stopwatch sw = Stopwatch.createStarted(); OIndexCursor cursor = assetStore.getIndex(AssetEntityAdapter.I_BUCKET_COMPONENT_NAME).cursor(); List<Entry<OCompositeKey, EntityId>> nextPage = assetStore.getNextPage(cursor, rebuildPageSize); while (!Iterables.isEmpty(nextPage)) { checkCancellation(); List<Asset> assets = new ArrayList<>(rebuildPageSize); for (Entry<OCompositeKey, EntityId> indexEntry : nextPage) { if (bucketId.equals(indexEntry.getKey().getKeys().get(BUCKET_KEY_ID))) { assets.add(assetStore.getById(indexEntry.getValue())); } } int assetsSize = Iterables.size(assets); browseNodeManager.createFromAssets(repository, assets); processed += assetsSize; long elapsed = sw.elapsed(TimeUnit.MILLISECONDS); progressLogger.info("Rebuilt browse nodes for {} / {} assets in {} ms", processed, total, elapsed); nextPage = assetStore.getNextPage(cursor, rebuildPageSize); } progressLogger.flush(); } } catch (Exception e) { throw new RebuildBrowseNodeFailedException("Could not re-create browse nodes", e); } } @Inject  OrientRebuildBrowseNodeService(
      final AssetStore assetStore,
      final BucketStore bucketStore,
      final OrientBrowseNodeManager browseNodeManager,
      final BrowseNodeConfiguration configuration); }
OrientRebuildBrowseNodeService implements RebuildBrowseNodeService { @Override public void rebuild(final Repository repository) throws RebuildBrowseNodeFailedException { log.info("Deleting browse nodes for repository {}", repository.getName()); browseNodeManager.deleteByRepository(repository.getName()); log.info("Rebuilding browse nodes for repository {}", repository.getName()); Bucket bucket = bucketStore.read(repository.getName()); ORID bucketId = AttachedEntityHelper.id(bucket); try { long processed = 0; long total = assetStore.countAssets(ImmutableList.of(bucket)); if (total > 0) { ProgressLogIntervalHelper progressLogger = new ProgressLogIntervalHelper(log, 60); Stopwatch sw = Stopwatch.createStarted(); OIndexCursor cursor = assetStore.getIndex(AssetEntityAdapter.I_BUCKET_COMPONENT_NAME).cursor(); List<Entry<OCompositeKey, EntityId>> nextPage = assetStore.getNextPage(cursor, rebuildPageSize); while (!Iterables.isEmpty(nextPage)) { checkCancellation(); List<Asset> assets = new ArrayList<>(rebuildPageSize); for (Entry<OCompositeKey, EntityId> indexEntry : nextPage) { if (bucketId.equals(indexEntry.getKey().getKeys().get(BUCKET_KEY_ID))) { assets.add(assetStore.getById(indexEntry.getValue())); } } int assetsSize = Iterables.size(assets); browseNodeManager.createFromAssets(repository, assets); processed += assetsSize; long elapsed = sw.elapsed(TimeUnit.MILLISECONDS); progressLogger.info("Rebuilt browse nodes for {} / {} assets in {} ms", processed, total, elapsed); nextPage = assetStore.getNextPage(cursor, rebuildPageSize); } progressLogger.flush(); } } catch (Exception e) { throw new RebuildBrowseNodeFailedException("Could not re-create browse nodes", e); } } @Inject  OrientRebuildBrowseNodeService(
      final AssetStore assetStore,
      final BucketStore bucketStore,
      final OrientBrowseNodeManager browseNodeManager,
      final BrowseNodeConfiguration configuration); @Override void rebuild(final Repository repository); }
OrientRebuildBrowseNodeService implements RebuildBrowseNodeService { @Override public void rebuild(final Repository repository) throws RebuildBrowseNodeFailedException { log.info("Deleting browse nodes for repository {}", repository.getName()); browseNodeManager.deleteByRepository(repository.getName()); log.info("Rebuilding browse nodes for repository {}", repository.getName()); Bucket bucket = bucketStore.read(repository.getName()); ORID bucketId = AttachedEntityHelper.id(bucket); try { long processed = 0; long total = assetStore.countAssets(ImmutableList.of(bucket)); if (total > 0) { ProgressLogIntervalHelper progressLogger = new ProgressLogIntervalHelper(log, 60); Stopwatch sw = Stopwatch.createStarted(); OIndexCursor cursor = assetStore.getIndex(AssetEntityAdapter.I_BUCKET_COMPONENT_NAME).cursor(); List<Entry<OCompositeKey, EntityId>> nextPage = assetStore.getNextPage(cursor, rebuildPageSize); while (!Iterables.isEmpty(nextPage)) { checkCancellation(); List<Asset> assets = new ArrayList<>(rebuildPageSize); for (Entry<OCompositeKey, EntityId> indexEntry : nextPage) { if (bucketId.equals(indexEntry.getKey().getKeys().get(BUCKET_KEY_ID))) { assets.add(assetStore.getById(indexEntry.getValue())); } } int assetsSize = Iterables.size(assets); browseNodeManager.createFromAssets(repository, assets); processed += assetsSize; long elapsed = sw.elapsed(TimeUnit.MILLISECONDS); progressLogger.info("Rebuilt browse nodes for {} / {} assets in {} ms", processed, total, elapsed); nextPage = assetStore.getNextPage(cursor, rebuildPageSize); } progressLogger.flush(); } } catch (Exception e) { throw new RebuildBrowseNodeFailedException("Could not re-create browse nodes", e); } } @Inject  OrientRebuildBrowseNodeService(
      final AssetStore assetStore,
      final BucketStore bucketStore,
      final OrientBrowseNodeManager browseNodeManager,
      final BrowseNodeConfiguration configuration); @Override void rebuild(final Repository repository);  }