Class EngineTestCase

java.lang.Object
org.junit.Assert
org.apache.lucene.util.LuceneTestCase
org.elasticsearch.test.ESTestCase
org.elasticsearch.index.engine.EngineTestCase

public abstract class EngineTestCase extends ESTestCase
  • Field Details

    • shardId

      protected final org.elasticsearch.index.shard.ShardId shardId
    • allocationId

      protected final org.elasticsearch.cluster.routing.AllocationId allocationId
    • INDEX_SETTINGS

      protected static final org.elasticsearch.index.IndexSettings INDEX_SETTINGS
    • threadPool

      protected org.elasticsearch.threadpool.ThreadPool threadPool
    • translogHandler

      protected TranslogHandler translogHandler
    • store

      protected org.elasticsearch.index.store.Store store
    • storeReplica

      protected org.elasticsearch.index.store.Store storeReplica
    • engine

      protected org.elasticsearch.index.engine.InternalEngine engine
    • replicaEngine

      protected org.elasticsearch.index.engine.InternalEngine replicaEngine
    • defaultSettings

      protected org.elasticsearch.index.IndexSettings defaultSettings
    • codecName

      protected String codecName
    • primaryTranslogDir

      protected Path primaryTranslogDir
    • replicaTranslogDir

      protected Path replicaTranslogDir
    • primaryTerm

      protected final EngineTestCase.PrimaryTermSupplier primaryTerm
    • B_1

      protected static final org.elasticsearch.common.bytes.BytesReference B_1
    • B_2

      protected static final org.elasticsearch.common.bytes.BytesReference B_2
    • B_3

      protected static final org.elasticsearch.common.bytes.BytesReference B_3
    • SOURCE

      protected static final org.elasticsearch.common.bytes.BytesArray SOURCE
  • Constructor Details

    • EngineTestCase

      public EngineTestCase()
  • Method Details

    • assertVisibleCount

      protected static void assertVisibleCount(org.elasticsearch.index.engine.Engine engine, int numDocs) throws IOException
      Throws:
      IOException
    • assertVisibleCount

      protected static void assertVisibleCount(org.elasticsearch.index.engine.Engine engine, int numDocs, boolean refresh) throws IOException
      Throws:
      IOException
    • indexSettings

      protected org.elasticsearch.common.settings.Settings indexSettings()
    • setUp

      public void setUp() throws Exception
      Overrides:
      setUp in class org.apache.lucene.util.LuceneTestCase
      Throws:
      Exception
    • copy

      public org.elasticsearch.index.engine.EngineConfig copy(org.elasticsearch.index.engine.EngineConfig config, LongSupplier globalCheckpointSupplier)
    • copy

      public org.elasticsearch.index.engine.EngineConfig copy(org.elasticsearch.index.engine.EngineConfig config, org.apache.lucene.analysis.Analyzer analyzer)
    • copy

      public org.elasticsearch.index.engine.EngineConfig copy(org.elasticsearch.index.engine.EngineConfig config, org.apache.lucene.index.MergePolicy mergePolicy)
    • tearDown

      public void tearDown() throws Exception
      Overrides:
      tearDown in class org.apache.lucene.util.LuceneTestCase
      Throws:
      Exception
    • testDocumentWithTextField

      protected static org.elasticsearch.index.mapper.LuceneDocument testDocumentWithTextField()
    • testDocumentWithTextField

      protected static org.elasticsearch.index.mapper.LuceneDocument testDocumentWithTextField(String value)
    • testDocument

      protected static org.elasticsearch.index.mapper.LuceneDocument testDocument()
    • createParsedDoc

      public static org.elasticsearch.index.mapper.ParsedDocument createParsedDoc(String id, String routing)
    • createParsedDoc

      public static org.elasticsearch.index.mapper.ParsedDocument createParsedDoc(String id, String routing, boolean recoverySource)
    • testParsedDocument

      protected static org.elasticsearch.index.mapper.ParsedDocument testParsedDocument(String id, String routing, org.elasticsearch.index.mapper.LuceneDocument document, org.elasticsearch.common.bytes.BytesReference source, org.elasticsearch.index.mapper.Mapping mappingUpdate)
    • testParsedDocument

      protected static org.elasticsearch.index.mapper.ParsedDocument testParsedDocument(String id, String routing, org.elasticsearch.index.mapper.LuceneDocument document, org.elasticsearch.common.bytes.BytesReference source, org.elasticsearch.index.mapper.Mapping mappingUpdate, boolean recoverySource)
    • nestedParsedDocFactory

      public static org.elasticsearch.common.CheckedBiFunction<String,Integer,org.elasticsearch.index.mapper.ParsedDocument,IOException> nestedParsedDocFactory() throws Exception
      Throws:
      Exception
    • createStore

      protected org.elasticsearch.index.store.Store createStore() throws IOException
      Throws:
      IOException
    • createStore

      protected org.elasticsearch.index.store.Store createStore(org.apache.lucene.store.Directory directory) throws IOException
      Throws:
      IOException
    • createStore

      protected org.elasticsearch.index.store.Store createStore(org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.store.Directory directory) throws IOException
      Throws:
      IOException
    • createTranslog

      protected org.elasticsearch.index.translog.Translog createTranslog(LongSupplier primaryTermSupplier) throws IOException
      Throws:
      IOException
    • createTranslog

      protected org.elasticsearch.index.translog.Translog createTranslog(Path translogPath, LongSupplier primaryTermSupplier) throws IOException
      Throws:
      IOException
    • createTranslogHandler

      protected TranslogHandler createTranslogHandler(org.elasticsearch.index.IndexSettings indexSettings)
    • createEngine

      protected org.elasticsearch.index.engine.InternalEngine createEngine(org.elasticsearch.index.store.Store store, Path translogPath) throws IOException
      Throws:
      IOException
    • createEngine

      protected org.elasticsearch.index.engine.InternalEngine createEngine(org.elasticsearch.index.store.Store store, Path translogPath, LongSupplier globalCheckpointSupplier) throws IOException
      Throws:
      IOException
    • createEngine

      protected org.elasticsearch.index.engine.InternalEngine createEngine(org.elasticsearch.index.store.Store store, Path translogPath, BiFunction<Long,Long,org.elasticsearch.index.seqno.LocalCheckpointTracker> localCheckpointTrackerSupplier) throws IOException
      Throws:
      IOException
    • createEngine

      protected org.elasticsearch.index.engine.InternalEngine createEngine(org.elasticsearch.index.store.Store store, Path translogPath, BiFunction<Long,Long,org.elasticsearch.index.seqno.LocalCheckpointTracker> localCheckpointTrackerSupplier, ToLongBiFunction<org.elasticsearch.index.engine.Engine,org.elasticsearch.index.engine.Engine.Operation> seqNoForOperation) throws IOException
      Throws:
      IOException
    • createEngine

      protected org.elasticsearch.index.engine.InternalEngine createEngine(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.store.Store store, Path translogPath, org.apache.lucene.index.MergePolicy mergePolicy) throws IOException
      Throws:
      IOException
    • createEngine

      protected org.elasticsearch.index.engine.InternalEngine createEngine(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.store.Store store, Path translogPath, org.apache.lucene.index.MergePolicy mergePolicy, @Nullable EngineTestCase.IndexWriterFactory indexWriterFactory) throws IOException
      Throws:
      IOException
    • createEngine

      protected org.elasticsearch.index.engine.InternalEngine createEngine(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.store.Store store, Path translogPath, org.apache.lucene.index.MergePolicy mergePolicy, @Nullable EngineTestCase.IndexWriterFactory indexWriterFactory, @Nullable BiFunction<Long,Long,org.elasticsearch.index.seqno.LocalCheckpointTracker> localCheckpointTrackerSupplier, @Nullable LongSupplier globalCheckpointSupplier) throws IOException
      Throws:
      IOException
    • createEngine

      protected org.elasticsearch.index.engine.InternalEngine createEngine(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.store.Store store, Path translogPath, org.apache.lucene.index.MergePolicy mergePolicy, @Nullable EngineTestCase.IndexWriterFactory indexWriterFactory, @Nullable BiFunction<Long,Long,org.elasticsearch.index.seqno.LocalCheckpointTracker> localCheckpointTrackerSupplier, @Nullable LongSupplier globalCheckpointSupplier, @Nullable ToLongBiFunction<org.elasticsearch.index.engine.Engine,org.elasticsearch.index.engine.Engine.Operation> seqNoForOperation) throws IOException
      Throws:
      IOException
    • createEngine

      protected org.elasticsearch.index.engine.InternalEngine createEngine(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.store.Store store, Path translogPath, org.apache.lucene.index.MergePolicy mergePolicy, @Nullable EngineTestCase.IndexWriterFactory indexWriterFactory, @Nullable BiFunction<Long,Long,org.elasticsearch.index.seqno.LocalCheckpointTracker> localCheckpointTrackerSupplier, @Nullable ToLongBiFunction<org.elasticsearch.index.engine.Engine,org.elasticsearch.index.engine.Engine.Operation> seqNoForOperation, @Nullable org.apache.lucene.search.Sort indexSort, @Nullable LongSupplier globalCheckpointSupplier) throws IOException
      Throws:
      IOException
    • createEngine

      protected org.elasticsearch.index.engine.InternalEngine createEngine(org.elasticsearch.index.engine.EngineConfig config) throws IOException
      Throws:
      IOException
    • createEngine

      protected org.elasticsearch.index.engine.InternalEngine createEngine(@Nullable EngineTestCase.IndexWriterFactory indexWriterFactory, @Nullable BiFunction<Long,Long,org.elasticsearch.index.seqno.LocalCheckpointTracker> localCheckpointTrackerSupplier, @Nullable ToLongBiFunction<org.elasticsearch.index.engine.Engine,org.elasticsearch.index.engine.Engine.Operation> seqNoForOperation, org.elasticsearch.index.engine.EngineConfig config) throws IOException
      Throws:
      IOException
    • createEngine

      public static org.elasticsearch.index.engine.InternalEngine createEngine(org.elasticsearch.index.engine.EngineConfig engineConfig, int maxDocs)
    • generateNewSeqNo

      public static long generateNewSeqNo(org.elasticsearch.index.engine.Engine engine)
      Generate a new sequence number and return it. Only works on InternalEngines
    • createInternalEngine

      public static org.elasticsearch.index.engine.InternalEngine createInternalEngine(@Nullable EngineTestCase.IndexWriterFactory indexWriterFactory, @Nullable BiFunction<Long,Long,org.elasticsearch.index.seqno.LocalCheckpointTracker> localCheckpointTrackerSupplier, @Nullable ToLongBiFunction<org.elasticsearch.index.engine.Engine,org.elasticsearch.index.engine.Engine.Operation> seqNoForOperation, org.elasticsearch.index.engine.EngineConfig config)
    • config

      public org.elasticsearch.index.engine.EngineConfig config(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.store.Store store, Path translogPath, org.apache.lucene.index.MergePolicy mergePolicy, org.apache.lucene.search.ReferenceManager.RefreshListener refreshListener)
    • config

      public org.elasticsearch.index.engine.EngineConfig config(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.store.Store store, Path translogPath, org.apache.lucene.index.MergePolicy mergePolicy, org.apache.lucene.search.ReferenceManager.RefreshListener refreshListener, org.apache.lucene.search.Sort indexSort, LongSupplier globalCheckpointSupplier)
    • config

      public org.elasticsearch.index.engine.EngineConfig config(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.store.Store store, Path translogPath, org.apache.lucene.index.MergePolicy mergePolicy, org.apache.lucene.search.ReferenceManager.RefreshListener refreshListener, org.apache.lucene.search.Sort indexSort, LongSupplier globalCheckpointSupplier, Supplier<org.elasticsearch.index.seqno.RetentionLeases> retentionLeasesSupplier)
    • config

      public org.elasticsearch.index.engine.EngineConfig config(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.store.Store store, Path translogPath, org.apache.lucene.index.MergePolicy mergePolicy, org.apache.lucene.search.ReferenceManager.RefreshListener externalRefreshListener, org.apache.lucene.search.ReferenceManager.RefreshListener internalRefreshListener, org.apache.lucene.search.Sort indexSort, @Nullable LongSupplier maybeGlobalCheckpointSupplier, org.elasticsearch.indices.breaker.CircuitBreakerService breakerService)
    • config

      public org.elasticsearch.index.engine.EngineConfig config(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.store.Store store, Path translogPath, org.apache.lucene.index.MergePolicy mergePolicy, org.apache.lucene.search.ReferenceManager.RefreshListener externalRefreshListener, org.apache.lucene.search.ReferenceManager.RefreshListener internalRefreshListener, org.apache.lucene.search.Sort indexSort, @Nullable LongSupplier maybeGlobalCheckpointSupplier, @Nullable Supplier<org.elasticsearch.index.seqno.RetentionLeases> maybeRetentionLeasesSupplier, org.elasticsearch.indices.breaker.CircuitBreakerService breakerService)
    • config

      protected org.elasticsearch.index.engine.EngineConfig config(org.elasticsearch.index.engine.EngineConfig config, org.elasticsearch.index.store.Store store, Path translogPath)
    • noOpConfig

      protected org.elasticsearch.index.engine.EngineConfig noOpConfig(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.store.Store store, Path translogPath)
    • noOpConfig

      protected org.elasticsearch.index.engine.EngineConfig noOpConfig(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.store.Store store, Path translogPath, LongSupplier globalCheckpointSupplier)
    • bytesArray

      protected static org.elasticsearch.common.bytes.BytesArray bytesArray(String string)
    • newUid

      public static org.apache.lucene.index.Term newUid(String id)
    • newUid

      public static org.apache.lucene.index.Term newUid(org.elasticsearch.index.mapper.ParsedDocument doc)
    • newGet

      protected org.elasticsearch.index.engine.Engine.Get newGet(boolean realtime, org.elasticsearch.index.mapper.ParsedDocument doc)
    • indexForDoc

      protected org.elasticsearch.index.engine.Engine.Index indexForDoc(org.elasticsearch.index.mapper.ParsedDocument doc)
    • replicaIndexForDoc

      protected org.elasticsearch.index.engine.Engine.Index replicaIndexForDoc(org.elasticsearch.index.mapper.ParsedDocument doc, long version, long seqNo, boolean isRetry)
    • replicaDeleteForDoc

      protected org.elasticsearch.index.engine.Engine.Delete replicaDeleteForDoc(String id, long version, long seqNo, long startTime)
    • assertVisibleCount

      protected static void assertVisibleCount(org.elasticsearch.index.engine.InternalEngine engine, int numDocs) throws IOException
      Throws:
      IOException
    • assertVisibleCount

      protected static void assertVisibleCount(org.elasticsearch.index.engine.InternalEngine engine, int numDocs, boolean refresh) throws IOException
      Throws:
      IOException
    • generateSingleDocHistory

      public static List<org.elasticsearch.index.engine.Engine.Operation> generateSingleDocHistory(boolean forReplica, org.elasticsearch.index.VersionType versionType, long primaryTerm, int minOpCount, int maxOpCount, String docId)
    • generateHistoryOnReplica

      public List<org.elasticsearch.index.engine.Engine.Operation> generateHistoryOnReplica(int numOps, boolean allowGapInSeqNo, boolean allowDuplicate, boolean includeNestedDocs) throws Exception
      Throws:
      Exception
    • generateHistoryOnReplica

      public List<org.elasticsearch.index.engine.Engine.Operation> generateHistoryOnReplica(int numOps, long startingSeqNo, boolean allowGapInSeqNo, boolean allowDuplicate, boolean includeNestedDocs) throws Exception
      Throws:
      Exception
    • assertOpsOnReplica

      public static void assertOpsOnReplica(List<org.elasticsearch.index.engine.Engine.Operation> ops, org.elasticsearch.index.engine.InternalEngine replicaEngine, boolean shuffleOps, org.apache.logging.log4j.Logger logger) throws IOException
      Throws:
      IOException
    • concurrentlyApplyOps

      public static void concurrentlyApplyOps(List<org.elasticsearch.index.engine.Engine.Operation> ops, org.elasticsearch.index.engine.InternalEngine engine) throws InterruptedException
      Throws:
      InterruptedException
    • applyOperations

      public static void applyOperations(org.elasticsearch.index.engine.Engine engine, List<org.elasticsearch.index.engine.Engine.Operation> operations) throws IOException
      Throws:
      IOException
    • applyOperation

      public static org.elasticsearch.index.engine.Engine.Result applyOperation(org.elasticsearch.index.engine.Engine engine, org.elasticsearch.index.engine.Engine.Operation operation) throws IOException
      Throws:
      IOException
    • getDocIds

      public static List<DocIdSeqNoAndSource> getDocIds(org.elasticsearch.index.engine.Engine engine, boolean refresh) throws IOException
      Gets a collection of tuples of docId, sequence number, and primary term of all live documents in the provided engine.
      Throws:
      IOException
    • readAllOperationsInLucene

      public static List<org.elasticsearch.index.translog.Translog.Operation> readAllOperationsInLucene(org.elasticsearch.index.engine.Engine engine) throws IOException
      Reads all engine operations that have been processed by the engine from Lucene index. The returned operations are sorted and de-duplicated, thus each sequence number will be have at most one operation.
      Throws:
      IOException
    • assertConsistentHistoryBetweenTranslogAndLuceneIndex

      public static void assertConsistentHistoryBetweenTranslogAndLuceneIndex(org.elasticsearch.index.engine.Engine engine) throws IOException
      Asserts the provided engine has a consistent document history between translog and Lucene index.
      Throws:
      IOException
    • assertMaxSeqNoInCommitUserData

      public static void assertMaxSeqNoInCommitUserData(org.elasticsearch.index.engine.Engine engine) throws Exception
      Asserts that the max_seq_no stored in the commit's user_data is never smaller than seq_no of any document in the commit.
      Throws:
      Exception
    • assertAtMostOneLuceneDocumentPerSequenceNumber

      public static void assertAtMostOneLuceneDocumentPerSequenceNumber(org.elasticsearch.index.engine.Engine engine) throws IOException
      Throws:
      IOException
    • assertAtMostOneLuceneDocumentPerSequenceNumber

      public static void assertAtMostOneLuceneDocumentPerSequenceNumber(org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.index.DirectoryReader reader) throws IOException
      Throws:
      IOException
    • createMapperService

      public static org.elasticsearch.index.mapper.MapperService createMapperService() throws IOException
      Throws:
      IOException
    • mappingLookup

      public static org.elasticsearch.index.mapper.MappingLookup mappingLookup()
    • getTranslog

      public static org.elasticsearch.index.translog.Translog getTranslog(org.elasticsearch.index.engine.Engine engine)
      Exposes a translog associated with the given engine for testing purpose.
    • waitForOpsToComplete

      public static void waitForOpsToComplete(org.elasticsearch.index.engine.InternalEngine engine, long seqNo) throws Exception
      Waits for all operations up to the provided sequence number to complete in the given internal engine.
      Parameters:
      seqNo - the sequence number that the checkpoint must advance to before this method returns
      Throws:
      InterruptedException - if the thread was interrupted while blocking on the condition
      Exception
    • hasSnapshottedCommits

      public static boolean hasSnapshottedCommits(org.elasticsearch.index.engine.Engine engine)
    • getNumVersionLookups

      public static long getNumVersionLookups(org.elasticsearch.index.engine.Engine engine)
      Returns the number of times a version was looked up either from version map or from the index.
    • getInFlightDocCount

      public static long getInFlightDocCount(org.elasticsearch.index.engine.Engine engine)
    • assertNoInFlightDocuments

      public static void assertNoInFlightDocuments(org.elasticsearch.index.engine.Engine engine) throws Exception
      Throws:
      Exception
    • randomReaderWrapper

      public static org.elasticsearch.core.CheckedFunction<org.apache.lucene.index.DirectoryReader,org.apache.lucene.index.DirectoryReader,IOException> randomReaderWrapper()
    • randomSearcherWrapper

      public static Function<org.elasticsearch.index.engine.Engine.Searcher,org.elasticsearch.index.engine.Engine.Searcher> randomSearcherWrapper()
    • checkNoSoftDeletesLoaded

      public static void checkNoSoftDeletesLoaded(org.elasticsearch.index.engine.ReadOnlyEngine readOnlyEngine)