@Test public void rebuildDoesntFailOnException() throws Exception { final String group1 = "group1"; final String artifact1 = "artifact1"; final String version1 = "1.0-SNAPSHOT"; final String group2 = "group2"; final String artifact2 = "artifact2"; final String version2 = "2.0-SNAPSHOT"; Content content = mock(Content.class); when(mavenFacet.get(any(MavenPath.class))).thenReturn(content); ODocument doc = mock(ODocument.class); when(doc.field("groupId", OType.STRING)).thenReturn(group1, group2); when(doc.field("artifactId", OType.STRING)).thenReturn(artifact1, artifact2); when(doc.field("baseVersions", OType.EMBEDDEDSET)).thenReturn(newHashSet(version1), newHashSet(version2)); Component component = mock(Component.class); NestedAttributesMap attributes = mock(NestedAttributesMap.class); when(attributes.get(P_BASE_VERSION)).thenReturn(version1, version2); when(component.formatAttributes()).thenReturn(attributes); MavenPath gav1Path = mock(MavenPath.class); Coordinates gav1Coordinates = mock(Coordinates.class); when(gav1Path.getCoordinates()).thenReturn(gav1Coordinates); when(gav1Coordinates.getGroupId()).thenReturn(group1); when(gav1Coordinates.getArtifactId()).thenReturn(artifact1); when(gav1Coordinates.getBaseVersion()).thenReturn(version1); MavenPath gav2Path = mock(MavenPath.class); Coordinates gav2Coordinates = mock(Coordinates.class); when(gav2Path.getCoordinates()).thenReturn(gav2Coordinates); when(gav2Coordinates.getGroupId()).thenReturn(group2); when(gav2Coordinates.getArtifactId()).thenReturn(artifact2); when(gav2Coordinates.getBaseVersion()).thenReturn(version2); when(mavenPathParser.parsePath(anyString())).thenReturn(gav1Path, gav2Path); doReturn(iteratorWithItems(doc, doc)).when(storageTx) .browse(anyString(), anyMapOf(String.class, Object.class), anyInt(), anyLong()); when(storageTx.browseComponents(any(), any())).thenAnswer(i -> iteratorWithItems(component)); when(storageTx.browseAssets(any(Component.class))).thenAnswer(i -> iteratorWithItems(mock(Asset.class))); when(content.openInputStream()).thenThrow(new IOException()).thenReturn(mock(InputStream.class)); new OrientMetadataRebuilder(10, 20).rebuild(repository, true, false, null, null, null); verify(content, times(4)).openInputStream(); ArgumentCaptor<LoggingEvent> logCaptor = ArgumentCaptor.forClass(LoggingEvent.class); verify(mockAppender, atLeastOnce()).doAppend(logCaptor.capture()); List<LoggingEvent> allValues = logCaptor.getAllValues(); assertThat(allValues.stream() .filter(e -> e.getLevel() == Level.WARN) .filter(e -> e.getMessage().equals("Errors encountered during metadata rebuild:")) .count(), is(1L)); }
@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);  }