@Test void testStartupFailedIndexJobs() { when(indexService.hasIndex(attributeMetadata)).thenReturn(true); IndexJobExecution indexJobExecution = mock(IndexJobExecution.class); when(indexJobExecution.getIndexActionJobID()).thenReturn("id"); IndexAction action = mock(IndexAction.class); when(action.getEntityTypeId()).thenReturn("myEntityTypeName"); when(action.getEntityId()).thenReturn("1"); when(action.getId()).thenReturn("actionId"); EntityType entityType = mock(EntityType.class); when(dataService.findOneById( EntityTypeMetadata.ENTITY_TYPE_META_DATA, "myEntityTypeName", EntityType.class)) .thenReturn(entityType); Attribute idAttribute = mock(Attribute.class); when(idAttribute.getDataType()).thenReturn(AttributeType.INT); when(entityType.getIdAttribute()).thenReturn(idAttribute); when(dataService.findAll( IndexJobExecutionMetadata.INDEX_JOB_EXECUTION, new QueryImpl<IndexJobExecution>().eq(JobExecutionMetaData.STATUS, FAILED), IndexJobExecution.class)) .thenReturn(Stream.of(indexJobExecution)); when(dataService.findAll( IndexActionMetadata.INDEX_ACTION, new QueryImpl<IndexAction>().eq(IndexActionMetadata.INDEX_ACTION_GROUP_ATTR, "id"), IndexAction.class)) .thenReturn(Stream.of(action)); indexBootstrapper.bootstrap(); verify(metaDataService, never()).getRepositories(); verify(indexActionRegisterService).register(entityType, 1); verify(dataService).delete(IndexJobExecutionMetadata.INDEX_JOB_EXECUTION, indexJobExecution); ArgumentCaptor<Stream<Object>> captor = ArgumentCaptor.forClass(Stream.class); verify(dataService).deleteAll(eq(IndexActionMetadata.INDEX_ACTION), captor.capture()); assertEquals(singletonList("actionId"), captor.getValue().collect(toList())); verify(dataService).deleteById(IndexActionGroupMetadata.INDEX_ACTION_GROUP, "id"); }
public void bootstrap() { if (!indexService.hasIndex(attrMetadata)) { LOG.debug( "No index for Attribute found, asuming missing index, schedule (re)index for all entities"); metaDataService .getRepositories() .forEach(repo -> indexActionRegisterService.register(repo.getEntityType(), null)); LOG.debug("Done scheduling (re)index jobs for all entities"); } else { LOG.debug("Index for Attribute found, index is present, no (re)index needed"); List<IndexJobExecution> failedIndexJobs = dataService .findAll( IndexJobExecutionMetadata.INDEX_JOB_EXECUTION, new QueryImpl<IndexJobExecution>().eq(JobExecutionMetaData.STATUS, FAILED), IndexJobExecution.class) .collect(Collectors.toList()); failedIndexJobs.forEach(this::registerNewIndexActionForDirtyJobs); } }
IndexBootstrapper { public void bootstrap() { if (!indexService.hasIndex(attrMetadata)) { LOG.debug( "No index for Attribute found, asuming missing index, schedule (re)index for all entities"); metaDataService .getRepositories() .forEach(repo -> indexActionRegisterService.register(repo.getEntityType(), null)); LOG.debug("Done scheduling (re)index jobs for all entities"); } else { LOG.debug("Index for Attribute found, index is present, no (re)index needed"); List<IndexJobExecution> failedIndexJobs = dataService .findAll( IndexJobExecutionMetadata.INDEX_JOB_EXECUTION, new QueryImpl<IndexJobExecution>().eq(JobExecutionMetaData.STATUS, FAILED), IndexJobExecution.class) .collect(Collectors.toList()); failedIndexJobs.forEach(this::registerNewIndexActionForDirtyJobs); } } }
IndexBootstrapper { public void bootstrap() { if (!indexService.hasIndex(attrMetadata)) { LOG.debug( "No index for Attribute found, asuming missing index, schedule (re)index for all entities"); metaDataService .getRepositories() .forEach(repo -> indexActionRegisterService.register(repo.getEntityType(), null)); LOG.debug("Done scheduling (re)index jobs for all entities"); } else { LOG.debug("Index for Attribute found, index is present, no (re)index needed"); List<IndexJobExecution> failedIndexJobs = dataService .findAll( IndexJobExecutionMetadata.INDEX_JOB_EXECUTION, new QueryImpl<IndexJobExecution>().eq(JobExecutionMetaData.STATUS, FAILED), IndexJobExecution.class) .collect(Collectors.toList()); failedIndexJobs.forEach(this::registerNewIndexActionForDirtyJobs); } } IndexBootstrapper(
      MetaDataService metaDataService,
      IndexService indexService,
      IndexActionRegisterService indexActionRegisterService,
      DataService dataService,
      AttributeMetadata attrMetadata); }
IndexBootstrapper { public void bootstrap() { if (!indexService.hasIndex(attrMetadata)) { LOG.debug( "No index for Attribute found, asuming missing index, schedule (re)index for all entities"); metaDataService .getRepositories() .forEach(repo -> indexActionRegisterService.register(repo.getEntityType(), null)); LOG.debug("Done scheduling (re)index jobs for all entities"); } else { LOG.debug("Index for Attribute found, index is present, no (re)index needed"); List<IndexJobExecution> failedIndexJobs = dataService .findAll( IndexJobExecutionMetadata.INDEX_JOB_EXECUTION, new QueryImpl<IndexJobExecution>().eq(JobExecutionMetaData.STATUS, FAILED), IndexJobExecution.class) .collect(Collectors.toList()); failedIndexJobs.forEach(this::registerNewIndexActionForDirtyJobs); } } IndexBootstrapper(
      MetaDataService metaDataService,
      IndexService indexService,
      IndexActionRegisterService indexActionRegisterService,
      DataService dataService,
      AttributeMetadata attrMetadata); void bootstrap(); }
IndexBootstrapper { public void bootstrap() { if (!indexService.hasIndex(attrMetadata)) { LOG.debug( "No index for Attribute found, asuming missing index, schedule (re)index for all entities"); metaDataService .getRepositories() .forEach(repo -> indexActionRegisterService.register(repo.getEntityType(), null)); LOG.debug("Done scheduling (re)index jobs for all entities"); } else { LOG.debug("Index for Attribute found, index is present, no (re)index needed"); List<IndexJobExecution> failedIndexJobs = dataService .findAll( IndexJobExecutionMetadata.INDEX_JOB_EXECUTION, new QueryImpl<IndexJobExecution>().eq(JobExecutionMetaData.STATUS, FAILED), IndexJobExecution.class) .collect(Collectors.toList()); failedIndexJobs.forEach(this::registerNewIndexActionForDirtyJobs); } } IndexBootstrapper(
      MetaDataService metaDataService,
      IndexService indexService,
      IndexActionRegisterService indexActionRegisterService,
      DataService dataService,
      AttributeMetadata attrMetadata); void bootstrap();  }