Class MockIssueIndexer

java.lang.Object
com.atlassian.jira.mock.issue.index.MockIssueIndexer
All Implemented Interfaces:
BackupContributor, IssueIndexer, UnmanagedIndexSearcherProvider

@ThreadSafe public class MockIssueIndexer extends Object implements IssueIndexer
Mock issue indexer that records calls indexing methods for verification.
Since:
v4.3
  • Field Details

    • indexWorkTime

      public final int indexWorkTime
    • optimizationWorkTime

      public final int optimizationWorkTime
    • indexedIssues

      public final Collection<Issue> indexedIssues
    • reIndexedIssues

      public final Collection<Issue> reIndexedIssues
    • optimizations

      public final AtomicInteger optimizations
  • Constructor Details

    • MockIssueIndexer

      public MockIssueIndexer()
    • MockIssueIndexer

      public MockIssueIndexer(int indexSleepTime, int optimizationSleepTime)
  • Method Details

    • deIndexProject

      public Index.Result deIndexProject(Project project, boolean shouldReplicate)
      Description copied from interface: IssueIndexer
      Remove all documents connected with given project
      Specified by:
      deIndexProject in interface IssueIndexer
      Parameters:
      project - project object
      shouldReplicate -
    • indexIssues

      public Index.Result indexIssues(@Nonnull EnclosedIterable<Issue> issues, @Nonnull Context context, @Nonnull IssueIndexingParams issueIndexingParams)
      Description copied from interface: IssueIndexer
      Add documents for the supplied issues.
      Specified by:
      indexIssues in interface IssueIndexer
      Parameters:
      issues - An iterable of issues to index.
      context - for showing the user the current status.
      issueIndexingParams - parameters describing what should be reindexed
    • getNumberOfIndexingThreads

      public int getNumberOfIndexingThreads()
      Description copied from interface: IssueIndexer
      Gets number of indexing threads.

      Configured by 'jira.index.issue.threads'.

      Specified by:
      getNumberOfIndexingThreads in interface IssueIndexer
      Returns:
      the number of indexing threads.
    • deindexIssues

      public Index.Result deindexIssues(@Nonnull Collection<? extends WithId> issues, @Nonnull Context context)
      Description copied from interface: IssueIndexer
      Delete any existing documents (in the issue index invalid input: '&' all related entity indexes) for the Issues represented by the supplied WithIds
      Specified by:
      deindexIssues in interface IssueIndexer
      Parameters:
      issues - An iterable of WithIds for the Issues to de-index.
      context - for showing the user the current status.
    • deindexIssues

      public Index.Result deindexIssues(@Nonnull Collection<? extends WithId> issues, @Nonnull Context context, boolean shouldReplicate)
      Description copied from interface: IssueIndexer
      Delete any existing documents (in the issue index invalid input: '&' all related entity indexes) for the Issues represented by the supplied WithIds
      Specified by:
      deindexIssues in interface IssueIndexer
      Parameters:
      issues - An iterable of WithIds for the Issues to de-index.
      context - for showing the user the current status.
      shouldReplicate - whether the index changes should be replicated to the other nodes in the cluster.
    • reindexIssuesBatchMode

      public AccumulatingResultBuilder reindexIssuesBatchMode(@Nonnull IssuesBatcher issuesBatcher, @Nonnull Context context, @Nonnull IssueIndexingParams issueIndexingParams)
      Description copied from interface: IssueIndexer
      Reindex issues from the given collection. As this method is not using conditional updates it must be executed under index write lock. It reindexes issues in multiple threads using the same parallelism mechanism as { @link IssueIndexer#indexIssuesBatchMode}
      Specified by:
      reindexIssuesBatchMode in interface IssueIndexer
      Parameters:
      issuesBatcher - an iterable over issue batches.
      context - for showing the user the current status.
      issueIndexingParams - parameters describing what should be reindexed
    • reindexIssues

      public Index.Result reindexIssues(@Nonnull EnclosedIterable<Issue> issues, @Nonnull Context context, IssueIndexingParams issueIndexingParams, boolean conditionalUpdate, boolean shouldReplicate)
      Description copied from interface: IssueIndexer
      Re-index the given issues, delete any existing documents and add new ones.
      Specified by:
      reindexIssues in interface IssueIndexer
      Parameters:
      issues - An iterable of issues to index.
      context - for showing the user the current status.
      issueIndexingParams - parameters describing what should be reindexed
      conditionalUpdate - set to true to use conditional updates when writing to the index
      shouldReplicate - whether or not the index changes should be replicated to the other nodes in the cluster.
    • reindexComments

      public Index.Result reindexComments(@Nonnull Collection<Comment> comments, @Nonnull Context context)
      Specified by:
      reindexComments in interface IssueIndexer
    • indexIssuesBatchMode

      public AccumulatingResultBuilder indexIssuesBatchMode(@Nonnull IssuesBatcher batcher, @Nonnull Context context, @Nonnull IssueIndexingParams issueIndexingParams)
      Description copied from interface: IssueIndexer
      Index all issues from the given batcher.
      Specified by:
      indexIssuesBatchMode in interface IssueIndexer
      Parameters:
      batcher - An iterable over issue batches.
      context - for showing the user the current status.
      issueIndexingParams - parameters describing what should be reindexed
    • reindexComments

      public Index.Result reindexComments(@Nonnull Collection<Comment> comments, @Nonnull Context context, boolean shouldReplicate)
      Description copied from interface: IssueIndexer
      Reindex a collection of issue comments.
      Specified by:
      reindexComments in interface IssueIndexer
      Parameters:
      comments - Comments to be reindexed.
      context - for showing the user the current status.
      shouldReplicate - whether or not the index changes should be replicated to the other nodes in the cluster.
    • reindexCommentsInParallel

      public Index.Result reindexCommentsInParallel(@Nonnull Collection<Comment> comments, @Nonnull Context context)
      Description copied from interface: IssueIndexer
      Reindex a collection of issue comments on multiple threads. This will not replicate the comments to the other nodes in cluster. As this method does not use conditional updates, it must be executed under index write lock.
      Specified by:
      reindexCommentsInParallel in interface IssueIndexer
      Parameters:
      comments - Comments to be reindexed.
      context - for showing the user the current status.
    • reindexWorklogsInParallel

      public Index.Result reindexWorklogsInParallel(@Nonnull Collection<Worklog> worklogs, @Nonnull Context context)
      Description copied from interface: IssueIndexer
      Reindex a collection of issue worklogs on multiple threads. This will not replicate the worklogs to the other nodes in cluster. As this method does not use conditional updates, it must be executed under index write lock.
      Specified by:
      reindexWorklogsInParallel in interface IssueIndexer
      Parameters:
      worklogs - Worklogs to be reindexed.
      context - for showing the user the current status.
    • reindexWorklogs

      public Index.Result reindexWorklogs(@Nonnull Collection<Worklog> worklogs, @Nonnull Context context, boolean shouldReplicate)
      Specified by:
      reindexWorklogs in interface IssueIndexer
    • deindexComments

      public Index.Result deindexComments(@Nonnull Collection<? extends WithId> comments, @Nonnull Context context, boolean shouldReplicate)
      Specified by:
      deindexComments in interface IssueIndexer
    • deindexWorklogs

      public Index.Result deindexWorklogs(@Nonnull Collection<? extends WithId> worklogs, @Nonnull Context context, boolean shouldReplicate)
      Specified by:
      deindexWorklogs in interface IssueIndexer
    • conditionalUpdateWithVersion

      public Index.Result conditionalUpdateWithVersion(IndexDirectoryFactory.Name indexName, org.apache.lucene.document.Document document)
      Description copied from interface: IssueIndexer
      Index a Document conditionally based on the entity id and the version which are resolved by IndexDirectoryFactory.Name.getEntityIdFromDocument(Document) and IndexDirectoryFactory.Name.getEntityVersionFromDocument(Document)
      Specified by:
      conditionalUpdateWithVersion in interface IssueIndexer
      Parameters:
      indexName - define the target index
      document - the document needs to be indexed
    • conditionalUpdateWithVersion

      public Index.Result conditionalUpdateWithVersion(org.apache.lucene.document.Document issueDocument, Collection<org.apache.lucene.document.Document> commentDocuments, Collection<org.apache.lucene.document.Document> changeHistoryDocuments, Collection<org.apache.lucene.document.Document> worklogDocuments)
      Description copied from interface: IssueIndexer
      Index an issue document with its related documents conditionally based on the entity ids and the versions which are resolved by IndexDirectoryFactory.Name.getEntityIdFromDocument(Document) and IndexDirectoryFactory.Name.getEntityVersionFromDocument(Document)
      Specified by:
      conditionalUpdateWithVersion in interface IssueIndexer
      Parameters:
      issueDocument - issue document needs to be indexed
      commentDocuments - issue's comment documents
      changeHistoryDocuments - issue's history change documents
      worklogDocuments - issue's worklog documents
    • indexDocument

      public Index.Result indexDocument(IndexRequest indexRequest)
      Description copied from interface: IssueIndexer
      Index a document using the provided IndexRequest.

      WARNING: This method bypasses the standard JIRA versioning flow and should be used with extreme caution. It does not automatically manage entity versions through the EntityVersioningManager, which can lead to version conflicts and inconsistent index state if the same entity is updated through normal JIRA operations.

      Recommended Usage: This method should only be used in controlled scenarios where:

      • The caller explicitly manages document versioning
      • Testing or development scenarios where version conflicts are acceptable

      Specified by:
      indexDocument in interface IssueIndexer
      Parameters:
      indexRequest - the request containing the document ID, optional version, document type, and field values to be indexed. Must not be null.
      Returns:
      the result of the indexing operation
    • optimize

      public Index.Result optimize()
      Specified by:
      optimize in interface IssueIndexer
    • deleteIndexes

      public void deleteIndexes()
      Description copied from interface: IssueIndexer
      Delete all indexes.
      Specified by:
      deleteIndexes in interface IssueIndexer
    • deleteIndexes

      public void deleteIndexes(IssueIndexingParams issueIndexingParams)
      Description copied from interface: IssueIndexer
      Delete selected indexes.
      Specified by:
      deleteIndexes in interface IssueIndexer
      Parameters:
      issueIndexingParams - parameters describing which indexes should be deleted.
    • shutdown

      public void shutdown()
      Specified by:
      shutdown in interface IssueIndexer
    • openEntitySearcher

      public UnmanagedIndexSearcher openEntitySearcher(IndexDirectoryFactory.Name index)
      Description copied from interface: UnmanagedIndexSearcherProvider
      Issue searcher has to be closed after doing stuff. Note: when doing this you need to have the index read lock, as this may trigger creating index when not there; See IndexManagerBase.indexLock. See IndexManagerBase.getEntitySearcher(IndexDirectoryFactory.Name) ()}.
      Specified by:
      openEntitySearcher in interface UnmanagedIndexSearcherProvider
    • getIndexPaths

      public List<String> getIndexPaths()
      Specified by:
      getIndexPaths in interface IssueIndexer
    • getIndexRootPath

      public String getIndexRootPath()
      Specified by:
      getIndexRootPath in interface IssueIndexer
    • contributeToBackup

      public void contributeToBackup(BackupBuilder backupBuilder)
      Description copied from interface: BackupContributor
      Contribute a set of files to the given backupBuilder to include them in the backup being created when this method was called.
      Specified by:
      contributeToBackup in interface BackupContributor
      Parameters:
      backupBuilder - builder of the backup being created at the time of call. All existing and nonempty files passed to its accept method will be included. The builder may not be reusable and the reference should not be stored outside the scope of this method