@Test public void rebuildIsCancelable() throws Exception { ODocument doc = mock(ODocument.class); when(doc.field("groupId", OType.STRING)).thenReturn("group"); when(doc.field("artifactId", OType.STRING)).thenReturn("artifact"); when(doc.field("baseVersions", OType.EMBEDDEDSET)).thenReturn(newHashSet("version")); Component component = mock(Component.class); NestedAttributesMap attributes = mock(NestedAttributesMap.class); when(attributes.get(P_BASE_VERSION)).thenReturn("version"); doReturn(attributes).when(component).formatAttributes(); doReturn(infiniteIterator(doc)).when(storageTx).browse(anyString(), anyMapOf(String.class, Object.class), anyInt(), anyLong()); doReturn(infiniteIterator(component)).when(storageTx).browseComponents(any(), any()); doReturn(infiniteIterator(mock(Asset.class))).when(storageTx).browseAssets(any(Component.class)); final AtomicBoolean canceled = new AtomicBoolean(false); final List<Throwable> uncaught = new ArrayList<>(); Thread taskThread = new Thread(() -> { CancelableHelper.set(canceled); new OrientMetadataRebuilder(10, 20).rebuild(repository, true, false, "group", "artifact", "version"); }); taskThread.setUncaughtExceptionHandler((t, e) -> { if (e instanceof TaskInterruptedException) { return; } uncaught.add(e); }); taskThread.start(); sleep((long) (Math.random() * 1000)); canceled.set(true); taskThread.join(5000); if (taskThread.isAlive()) { fail("Task did not cancel"); } if (uncaught.size() > 0) { throw new MultipleFailureException(uncaught); } }
@Override public boolean rebuild( final Repository repository, final boolean update, final boolean rebuildChecksums, @Nullable final String groupId, @Nullable final String artifactId, @Nullable final String baseVersion) { checkNotNull(repository); final StorageTx tx = repository.facet(StorageFacet.class).txSupplier().get(); UnitOfWork.beginBatch(tx); try { return rebuildInTransaction(repository, update, rebuildChecksums, groupId, artifactId, baseVersion); } finally { UnitOfWork.end(); } }
OrientMetadataRebuilder extends AbstractMetadataRebuilder { @Override public boolean rebuild( final Repository repository, final boolean update, final boolean rebuildChecksums, @Nullable final String groupId, @Nullable final String artifactId, @Nullable final String baseVersion) { checkNotNull(repository); final StorageTx tx = repository.facet(StorageFacet.class).txSupplier().get(); UnitOfWork.beginBatch(tx); try { return rebuildInTransaction(repository, update, rebuildChecksums, groupId, artifactId, baseVersion); } finally { UnitOfWork.end(); } } }
OrientMetadataRebuilder extends AbstractMetadataRebuilder { @Override public boolean rebuild( final Repository repository, final boolean update, final boolean rebuildChecksums, @Nullable final String groupId, @Nullable final String artifactId, @Nullable final String baseVersion) { checkNotNull(repository); final StorageTx tx = repository.facet(StorageFacet.class).txSupplier().get(); UnitOfWork.beginBatch(tx); try { return rebuildInTransaction(repository, update, rebuildChecksums, groupId, artifactId, baseVersion); } finally { UnitOfWork.end(); } } @Inject  OrientMetadataRebuilder(
      @Named("${nexus.maven.metadata.rebuild.bufferSize:-1000}") final int bufferSize,
      @Named("${nexus.maven.metadata.rebuild.timeoutSeconds:-60}") final int timeoutSeconds); }
OrientMetadataRebuilder extends AbstractMetadataRebuilder { @Override public boolean rebuild( final Repository repository, final boolean update, final boolean rebuildChecksums, @Nullable final String groupId, @Nullable final String artifactId, @Nullable final String baseVersion) { checkNotNull(repository); final StorageTx tx = repository.facet(StorageFacet.class).txSupplier().get(); UnitOfWork.beginBatch(tx); try { return rebuildInTransaction(repository, update, rebuildChecksums, groupId, artifactId, baseVersion); } finally { UnitOfWork.end(); } } @Inject  OrientMetadataRebuilder(
      @Named("${nexus.maven.metadata.rebuild.bufferSize:-1000}") final int bufferSize,
      @Named("${nexus.maven.metadata.rebuild.timeoutSeconds:-60}") final int timeoutSeconds); @Override boolean rebuild(
      final Repository repository,
      final boolean update,
      final boolean rebuildChecksums,
      @Nullable final String groupId,
      @Nullable final String artifactId,
      @Nullable final String baseVersion); @Override boolean rebuildInTransaction(
      final Repository repository,
      final boolean update,
      final boolean rebuildChecksums,
      @Nullable final String groupId,
      @Nullable final String artifactId,
      @Nullable final String baseVersion); @Override boolean exists(final Repository repository, final MavenPath mavenPath); @Override void deleteMetadata(final Repository repository, final List<String []> gavs); }
OrientMetadataRebuilder extends AbstractMetadataRebuilder { @Override public boolean rebuild( final Repository repository, final boolean update, final boolean rebuildChecksums, @Nullable final String groupId, @Nullable final String artifactId, @Nullable final String baseVersion) { checkNotNull(repository); final StorageTx tx = repository.facet(StorageFacet.class).txSupplier().get(); UnitOfWork.beginBatch(tx); try { return rebuildInTransaction(repository, update, rebuildChecksums, groupId, artifactId, baseVersion); } finally { UnitOfWork.end(); } } @Inject  OrientMetadataRebuilder(
      @Named("${nexus.maven.metadata.rebuild.bufferSize:-1000}") final int bufferSize,
      @Named("${nexus.maven.metadata.rebuild.timeoutSeconds:-60}") final int timeoutSeconds); @Override boolean rebuild(
      final Repository repository,
      final boolean update,
      final boolean rebuildChecksums,
      @Nullable final String groupId,
      @Nullable final String artifactId,
      @Nullable final String baseVersion); @Override boolean rebuildInTransaction(
      final Repository repository,
      final boolean update,
      final boolean rebuildChecksums,
      @Nullable final String groupId,
      @Nullable final String artifactId,
      @Nullable final String baseVersion); @Override boolean exists(final Repository repository, final MavenPath mavenPath); @Override void deleteMetadata(final Repository repository, final List<String []> gavs);  }