ReindexNpmRepositoryManager extends StateGuardLifecycleSupport { @Override protected void doStart() { if (!enabled) { return; } try { for (Repository repository : repositoryManager.browse()) { if (unprocessedRepositoryChecker.isUnprocessedNpmRepository(repository)) { boolean existingTask = taskScheduler.findAndSubmit(ReindexNpmRepositoryTaskDescriptor.TYPE_ID, ImmutableMap.of(REPOSITORY_NAME_FIELD_ID, repository.getName())); if (!existingTask) { runReindexTaskForRepository(repository); } } } } catch (Exception e) { log.error("Failed to determine if any npm repositories needed to be reindexed", e); } } @Inject  ReindexNpmRepositoryManager(final TaskScheduler taskScheduler,
                                     final RepositoryManager repositoryManager,
                                     final UnprocessedRepositoryChecker unprocessedRepositoryChecker,
                                     @Named("${nexus.npm.reindexOnStartup.enabled:-true}") final boolean enabled);   }
@Test public void exceptionDoesNotPreventStartup() { when(repositoryManager.browse()).thenThrow(new RuntimeException("exception")); try { underTest.doStart(); } catch (Exception e) { fail("expected startup to catch exceptions"); } }
@Test public void skipProcessingWhenNotEnabled() { underTest = new ReindexNpmRepositoryManager(taskScheduler, repositoryManager, new OrientUnprocessedRepositoryChecker(), false); underTest.doStart(); verifyNoMoreInteractions(repositoryManager); verifyNoMoreInteractions(taskScheduler); }
@Test public void skipRepositoryWithoutFlag() { when(repositoryAttributes.get(NPM_V1_SEARCH_UNSUPPORTED)).thenReturn(null); underTest.doStart(); verify(taskScheduler, never()).submit(any(TaskConfiguration.class)); }
@Test public void skipRepositoryWithFalseFlag() { when(repositoryAttributes.get(NPM_V1_SEARCH_UNSUPPORTED)).thenReturn(false); underTest.doStart(); verify(taskScheduler, never()).submit(any(TaskConfiguration.class)); }
@Test public void skipRepositoryWithRunningTask() { when(taskScheduler.findAndSubmit(TYPE_ID, ImmutableMap.of(REPOSITORY_NAME_FIELD_ID, REPOSITORY_NAME))) .thenReturn(true); underTest.doStart(); verify(taskScheduler, never()).submit(any(TaskConfiguration.class)); }
@Test public void processRepositoryWithoutRunningTaskBasedOnTypeId() { underTest.doStart(); verifySubmittedTaskConfiguration(); verify(taskScheduler).submit(submittedTaskConfiguration); }
@Test public void processRepositoryWithoutRunningTaskBasedOnRepositoryName() { underTest.doStart(); verifySubmittedTaskConfiguration(); verify(taskScheduler).submit(submittedTaskConfiguration); }
@Test public void processRepositoryWithoutRunningTaskBasedOnCurrentState() { underTest.doStart(); verifySubmittedTaskConfiguration(); verify(taskScheduler).submit(submittedTaskConfiguration); }