Class IndexShardTestCase

java.lang.Object
org.junit.Assert
org.apache.lucene.tests.util.LuceneTestCase
org.opensearch.test.OpenSearchTestCase
org.opensearch.index.shard.IndexShardTestCase
Direct Known Subclasses:
OpenSearchIndexLevelReplicationTestCase

public abstract class IndexShardTestCase extends OpenSearchTestCase
A base class for unit tests that need to create and shutdown IndexShard instances easily, containing utilities for shard creation and recoveries. See {newShard(boolean)} and newStartedShard() for a good starting points
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.apache.lucene.tests.util.LuceneTestCase

    org.apache.lucene.tests.util.LuceneTestCase.AwaitsFix, org.apache.lucene.tests.util.LuceneTestCase.Concurrency, org.apache.lucene.tests.util.LuceneTestCase.Monster, org.apache.lucene.tests.util.LuceneTestCase.Nightly, org.apache.lucene.tests.util.LuceneTestCase.SuppressCodecs, org.apache.lucene.tests.util.LuceneTestCase.SuppressFileSystems, org.apache.lucene.tests.util.LuceneTestCase.SuppressFsync, org.apache.lucene.tests.util.LuceneTestCase.SuppressReproduceLine, org.apache.lucene.tests.util.LuceneTestCase.SuppressSysoutChecks, org.apache.lucene.tests.util.LuceneTestCase.SuppressTempFileChecks, org.apache.lucene.tests.util.LuceneTestCase.ThrowingConsumer<T>, org.apache.lucene.tests.util.LuceneTestCase.ThrowingRunnable, org.apache.lucene.tests.util.LuceneTestCase.Weekly
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.opensearch.cluster.service.ClusterService
     
    protected static AtomicLong
     
    static final org.opensearch.index.shard.IndexEventListener
     
    protected long
     
    protected static final org.opensearch.indices.replication.common.ReplicationListener
     
    protected org.opensearch.threadpool.ThreadPool
     

    Fields inherited from class org.apache.lucene.tests.util.LuceneTestCase

    assertsAreEnabled, classRules, DEFAULT_LINE_DOCS_FILE, INFOSTREAM, JENKINS_LARGE_LINE_DOCS_FILE, LEAVE_TEMPORARY, MAYBE_CACHE_POLICY, RANDOM_MULTIPLIER, ruleChain, suiteFailureMarker, SYSPROP_AWAITSFIX, SYSPROP_FAILFAST, SYSPROP_MAXFAILURES, SYSPROP_MONSTER, SYSPROP_NIGHTLY, SYSPROP_WEEKLY, TEST_ASSERTS_ENABLED, TEST_AWAITSFIX, TEST_CODEC, TEST_DIRECTORY, TEST_DOCVALUESFORMAT, TEST_LINE_DOCS_FILE, TEST_MONSTER, TEST_NIGHTLY, TEST_POSTINGSFORMAT, TEST_THROTTLING, TEST_WEEKLY, VERBOSE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.opensearch.common.lease.Releasable
    acquirePrimaryOperationPermitBlockingly(org.opensearch.index.shard.IndexShard indexShard)
     
    protected void
    by default, tests will fail if any shard created by this class fails.
    static void
    assertConsistentHistoryBetweenTranslogAndLucene(org.opensearch.index.shard.IndexShard shard)
     
    protected void
    assertDocCount(org.opensearch.index.shard.IndexShard shard, int docDount)
     
    protected void
    assertDocs(org.opensearch.index.shard.IndexShard shard, String... ids)
     
    protected void
    closeShard(org.opensearch.index.shard.IndexShard shard, boolean assertConsistencyBetweenTranslogAndLucene)
     
    protected void
    closeShards(Iterable<org.opensearch.index.shard.IndexShard> shards)
     
    protected void
    closeShards(org.opensearch.index.shard.IndexShard... shards)
     
    protected org.opensearch.index.store.RemoteSegmentStoreDirectory
    createRemoteSegmentStoreDirectory(org.opensearch.core.index.shard.ShardId shardId, Path path)
     
    protected org.opensearch.index.store.Store
    createRemoteStore(Path path, org.opensearch.cluster.routing.ShardRouting shardRouting, org.opensearch.cluster.metadata.IndexMetadata metadata, org.opensearch.index.shard.ShardPath shardPath)
     
    protected org.opensearch.repositories.RepositoriesService
     
    protected org.opensearch.index.store.Store
    createStore(org.opensearch.core.index.shard.ShardId shardId, org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.store.Directory directory, org.opensearch.index.shard.ShardPath shardPath)
     
    protected org.opensearch.index.store.Store
    createStore(org.opensearch.index.IndexSettings indexSettings, org.opensearch.index.shard.ShardPath shardPath)
     
    static org.opensearch.index.engine.Engine.Warmer
    createTestWarmer(org.opensearch.index.IndexSettings indexSettings)
     
    protected org.opensearch.index.engine.Engine.DeleteResult
    deleteDoc(org.opensearch.index.shard.IndexShard shard, String id)
     
    protected void
     
    protected void
    flushShard(org.opensearch.index.shard.IndexShard shard)
     
    protected void
    flushShard(org.opensearch.index.shard.IndexShard shard, boolean force)
     
    protected org.opensearch.common.blobstore.BlobContainer
     
    getDocIdAndSeqNos(org.opensearch.index.shard.IndexShard shard)
     
    static org.opensearch.index.engine.Engine
    getEngine(org.opensearch.index.shard.IndexShard indexShard)
    Helper method to access (package-protected) engine from tests
    org.opensearch.indices.replication.SegmentReplicationTargetService.SegmentReplicationListener
    getMergedSegmentTargetListener(org.opensearch.index.shard.IndexShard primaryShard, org.opensearch.index.shard.IndexShard replicaShard, Map<String, org.opensearch.index.store.StoreFileMetadata> primaryMetadata, CountDownLatch latch)
    Get listener on started merged segment replication event which verifies replica shard store with primary's after completion
    Function<List<org.opensearch.index.shard.IndexShard>, List<org.opensearch.indices.replication.SegmentReplicationTarget>>
    getReplicationFunc(org.opensearch.index.shard.IndexShard target)
     
    static org.opensearch.index.seqno.ReplicationTracker
    getReplicationTracker(org.opensearch.index.shard.IndexShard indexShard)
     
    org.opensearch.indices.replication.SegmentReplicationSource
    getSegmentReplicationSource(org.opensearch.index.shard.IndexShard primaryShard, Function<Long, org.opensearch.indices.replication.common.ReplicationCollection.ReplicationRef<org.opensearch.indices.replication.SegmentReplicationTarget>> getTargetFunc, Function<Long, org.opensearch.indices.replication.common.ReplicationCollection.ReplicationRef<org.opensearch.indices.replication.MergedSegmentReplicationTarget>> getMergedSegmentTargetFunc, Consumer<org.opensearch.index.shard.IndexShard> postGetFilesRunnable)
    Utility method which creates a segment replication source, which copies files from primary shard to target shard
    static Set<String>
    getShardDocUIDs(org.opensearch.index.shard.IndexShard shard)
     
    org.opensearch.indices.replication.SegmentReplicationTargetService.SegmentReplicationListener
    getTargetListener(org.opensearch.index.shard.IndexShard primaryShard, org.opensearch.index.shard.IndexShard replicaShard, Map<String, org.opensearch.index.store.StoreFileMetadata> primaryMetadata, CountDownLatch latch)
    Get listener on started segment replication event which verifies replica shard store with primary's after completion
    static org.opensearch.index.translog.Translog
    getTranslog(org.opensearch.index.shard.IndexShard shard)
     
    protected org.opensearch.index.engine.Engine.IndexResult
    indexDoc(org.opensearch.index.shard.IndexShard shard, String type, String id)
     
    protected org.opensearch.index.engine.Engine.IndexResult
    indexDoc(org.opensearch.index.shard.IndexShard shard, String type, String id, String source)
     
    protected org.opensearch.index.engine.Engine.IndexResult
    indexDoc(org.opensearch.index.shard.IndexShard shard, String id, String source, org.opensearch.core.xcontent.MediaType mediaType, String routing)
     
    protected org.opensearch.index.shard.IndexShard
    newShard(boolean primary)
    Creates a new initializing shard.
    protected org.opensearch.index.shard.IndexShard
    newShard(boolean primary, org.opensearch.common.settings.Settings settings)
    Creates a new initializing shard.
    protected org.opensearch.index.shard.IndexShard
    newShard(boolean primary, org.opensearch.common.settings.Settings settings, org.opensearch.index.engine.EngineFactory engineFactory)
    Creates a new initializing shard.
    protected org.opensearch.index.shard.IndexShard
    newShard(boolean primary, org.opensearch.indices.replication.checkpoint.SegmentReplicationCheckpointPublisher checkpointPublisher)
     
    protected org.opensearch.index.shard.IndexShard
    newShard(boolean primary, org.opensearch.indices.replication.checkpoint.SegmentReplicationCheckpointPublisher checkpointPublisher, org.opensearch.common.settings.Settings settings)
    creates a new initializing shard.
    protected org.opensearch.index.shard.IndexShard
    newShard(org.opensearch.cluster.routing.ShardRouting routing, org.opensearch.cluster.metadata.IndexMetadata indexMetadata, org.opensearch.common.CheckedFunction<org.apache.lucene.index.DirectoryReader, org.apache.lucene.index.DirectoryReader, IOException> indexReaderWrapper, org.opensearch.index.engine.EngineFactory engineFactory, Runnable globalCheckpointSyncer, org.opensearch.index.seqno.RetentionLeaseSyncer retentionLeaseSyncer, Path path, org.opensearch.index.shard.IndexingOperationListener... listeners)
    creates a new initializing shard.
    protected org.opensearch.index.shard.IndexShard
    newShard(org.opensearch.cluster.routing.ShardRouting routing, org.opensearch.cluster.metadata.IndexMetadata indexMetadata, org.opensearch.common.CheckedFunction<org.apache.lucene.index.DirectoryReader, org.apache.lucene.index.DirectoryReader, IOException> indexReaderWrapper, org.opensearch.index.engine.EngineFactory engineFactory, org.opensearch.index.shard.IndexingOperationListener... listeners)
    creates a new initializing shard.
    protected org.opensearch.index.shard.IndexShard
    newShard(org.opensearch.cluster.routing.ShardRouting shardRouting, org.opensearch.common.settings.Settings settings, org.opensearch.index.engine.EngineFactory engineFactory, org.opensearch.index.shard.IndexingOperationListener... listeners)
    Creates a new initializing shard.
    protected org.opensearch.index.shard.IndexShard
    newShard(org.opensearch.cluster.routing.ShardRouting shardRouting, org.opensearch.common.settings.Settings settings, org.opensearch.index.shard.IndexingOperationListener... listeners)
     
    protected org.opensearch.index.shard.IndexShard
    newShard(org.opensearch.cluster.routing.ShardRouting shardRouting, org.opensearch.index.shard.IndexingOperationListener... listeners)
     
    protected org.opensearch.index.shard.IndexShard
    newShard(org.opensearch.cluster.routing.ShardRouting routing, org.opensearch.index.shard.ShardPath shardPath, org.opensearch.cluster.metadata.IndexMetadata indexMetadata, org.opensearch.common.CheckedFunction<org.opensearch.index.IndexSettings, org.opensearch.index.store.Store, IOException> storeProvider, org.opensearch.common.CheckedFunction<org.apache.lucene.index.DirectoryReader, org.apache.lucene.index.DirectoryReader, IOException> indexReaderWrapper, org.opensearch.index.engine.EngineFactory engineFactory, org.opensearch.index.engine.EngineConfigFactory engineConfigFactory, Runnable globalCheckpointSyncer, org.opensearch.index.seqno.RetentionLeaseSyncer retentionLeaseSyncer, org.opensearch.index.shard.IndexEventListener indexEventListener, Path remotePath, org.opensearch.index.shard.IndexingOperationListener... listeners)
    creates a new initializing shard.
    protected org.opensearch.index.shard.IndexShard
    newShard(org.opensearch.cluster.routing.ShardRouting routing, org.opensearch.index.shard.ShardPath shardPath, org.opensearch.cluster.metadata.IndexMetadata indexMetadata, org.opensearch.common.CheckedFunction<org.opensearch.index.IndexSettings, org.opensearch.index.store.Store, IOException> storeProvider, org.opensearch.common.CheckedFunction<org.apache.lucene.index.DirectoryReader, org.apache.lucene.index.DirectoryReader, IOException> indexReaderWrapper, org.opensearch.index.engine.EngineFactory engineFactory, org.opensearch.index.engine.EngineConfigFactory engineConfigFactory, Runnable globalCheckpointSyncer, org.opensearch.index.seqno.RetentionLeaseSyncer retentionLeaseSyncer, org.opensearch.index.shard.IndexEventListener indexEventListener, org.opensearch.indices.replication.checkpoint.SegmentReplicationCheckpointPublisher checkpointPublisher, Path remotePath, org.opensearch.index.shard.IndexingOperationListener... listeners)
    creates a new initializing shard.
    protected org.opensearch.index.shard.IndexShard
    newShard(org.opensearch.core.index.shard.ShardId shardId, boolean primary, String nodeId, org.opensearch.cluster.metadata.IndexMetadata indexMetadata, org.opensearch.common.CheckedFunction<org.apache.lucene.index.DirectoryReader, org.apache.lucene.index.DirectoryReader, IOException> readerWrapper)
    creates a new initializing shard.
    protected org.opensearch.index.shard.IndexShard
    newShard(org.opensearch.core.index.shard.ShardId shardId, boolean primary, String nodeId, org.opensearch.cluster.metadata.IndexMetadata indexMetadata, org.opensearch.common.CheckedFunction<org.apache.lucene.index.DirectoryReader, org.apache.lucene.index.DirectoryReader, IOException> readerWrapper, Runnable globalCheckpointSyncer)
    creates a new initializing shard.
    protected org.opensearch.index.shard.IndexShard
    newShard(org.opensearch.core.index.shard.ShardId shardId, boolean primary, org.opensearch.index.shard.IndexingOperationListener... listeners)
    creates a new initializing shard.
    protected org.opensearch.index.shard.IndexShard
    Creates a new empty shard and starts it.
    protected org.opensearch.index.shard.IndexShard
    newStartedShard(boolean primary)
    Creates a new empty shard and starts it.
    protected org.opensearch.index.shard.IndexShard
    newStartedShard(boolean primary, org.opensearch.common.settings.Settings settings)
    Creates a new empty shard and starts it.
    protected org.opensearch.index.shard.IndexShard
    newStartedShard(boolean primary, org.opensearch.common.settings.Settings settings, org.opensearch.index.engine.EngineFactory engineFactory)
    Creates a new empty shard with the specified settings and engine factory and starts it.
    protected org.opensearch.index.shard.IndexShard
    newStartedShard(org.opensearch.common.CheckedFunction<Boolean, org.opensearch.index.shard.IndexShard, IOException> shardFunction, boolean primary)
    creates a new empty shard and starts it.
    protected org.opensearch.index.shard.IndexShard
    newStartedShard(org.opensearch.common.settings.Settings settings)
    Creates a new empty shard and starts it
    final org.opensearch.indices.replication.SegmentReplicationTargetService
    prepareForReplication(org.opensearch.index.shard.IndexShard primaryShard, org.opensearch.index.shard.IndexShard target)
    Segment Replication specific test method - Creates a SegmentReplicationTargetService to perform replications that has been configured to return the given primaryShard's current segments.
    final org.opensearch.indices.replication.SegmentReplicationTargetService
    prepareForReplication(org.opensearch.index.shard.IndexShard primaryShard, org.opensearch.index.shard.IndexShard target, org.opensearch.transport.TransportService transportService, org.opensearch.indices.IndicesService indicesService, org.opensearch.cluster.service.ClusterService clusterService)
     
    protected void
    promoteReplica(org.opensearch.index.shard.IndexShard replica, Set<String> inSyncIds, org.opensearch.cluster.routing.IndexShardRoutingTable routingTable)
    promotes a replica to primary, incrementing it's term and starting it if needed
    static boolean
    recoverFromStore(org.opensearch.index.shard.IndexShard newShard)
     
    protected void
    recoverReplica(org.opensearch.index.shard.IndexShard replica, org.opensearch.index.shard.IndexShard primary, boolean startReplica)
     
    protected void
    recoverReplica(org.opensearch.index.shard.IndexShard replica, org.opensearch.index.shard.IndexShard primary, boolean startReplica, Function<List<org.opensearch.index.shard.IndexShard>, List<org.opensearch.indices.replication.SegmentReplicationTarget>> replicatePrimaryFunction)
    recovers a replica from the given primary
    protected void
    recoverReplica(org.opensearch.index.shard.IndexShard replica, org.opensearch.index.shard.IndexShard primary, BiFunction<org.opensearch.index.shard.IndexShard, org.opensearch.cluster.node.DiscoveryNode, org.opensearch.indices.recovery.RecoveryTarget> targetSupplier, boolean markAsRecovering, boolean markAsStarted)
     
    protected void
    recoverReplica(org.opensearch.index.shard.IndexShard replica, org.opensearch.index.shard.IndexShard primary, BiFunction<org.opensearch.index.shard.IndexShard, org.opensearch.cluster.node.DiscoveryNode, org.opensearch.indices.recovery.RecoveryTarget> targetSupplier, boolean markAsRecovering, boolean markAsStarted, Function<List<org.opensearch.index.shard.IndexShard>, List<org.opensearch.indices.replication.SegmentReplicationTarget>> replicatePrimaryFunction)
    recovers a replica from the given primary
    protected void
    recoverShardFromSnapshot(org.opensearch.index.shard.IndexShard shard, org.opensearch.snapshots.Snapshot snapshot, org.opensearch.repositories.Repository repository)
    Recover a shard from a snapshot using a given repository
    protected void
    recoverShardFromStore(org.opensearch.index.shard.IndexShard primary)
     
    final void
    recoverUnstartedReplica(org.opensearch.index.shard.IndexShard replica, org.opensearch.index.shard.IndexShard primary, BiFunction<org.opensearch.index.shard.IndexShard, org.opensearch.cluster.node.DiscoveryNode, org.opensearch.indices.recovery.RecoveryTarget> targetSupplier, boolean markAsRecovering, Set<String> inSyncIds, org.opensearch.cluster.routing.IndexShardRoutingTable routingTable, Function<List<org.opensearch.index.shard.IndexShard>, List<org.opensearch.indices.replication.SegmentReplicationTarget>> replicatePrimaryFunction)
    Recovers a replica from the give primary, allow the user to supply a custom recovery target.
    protected void
    recoveryEmptyReplica(org.opensearch.index.shard.IndexShard replica, boolean startReplica)
     
    protected org.opensearch.index.shard.IndexShard
    reinitShard(org.opensearch.index.shard.IndexShard current, Path remotePath, org.opensearch.index.shard.IndexingOperationListener... listeners)
    Takes an existing shard, closes it and starts a new initialing shard at the same location
    protected org.opensearch.index.shard.IndexShard
    reinitShard(org.opensearch.index.shard.IndexShard current, org.opensearch.cluster.routing.ShardRouting routing, Path remotePath, org.opensearch.index.shard.IndexingOperationListener... listeners)
     
    protected org.opensearch.index.shard.IndexShard
    reinitShard(org.opensearch.index.shard.IndexShard current, org.opensearch.cluster.routing.ShardRouting routing, org.opensearch.cluster.metadata.IndexMetadata indexMetadata, org.opensearch.index.engine.EngineFactory engineFactory, org.opensearch.index.engine.EngineConfigFactory engineConfigFactory, Path remotePath, org.opensearch.index.shard.IndexingOperationListener... listeners)
    Takes an existing shard, closes it and starts a new initialing shard at the same location
    protected org.opensearch.index.shard.IndexShard
    reinitShard(org.opensearch.index.shard.IndexShard current, org.opensearch.cluster.routing.ShardRouting routing, org.opensearch.index.shard.IndexingOperationListener... listeners)
    Takes an existing shard, closes it and starts a new initialing shard at the same location
    protected org.opensearch.index.shard.IndexShard
    reinitShard(org.opensearch.index.shard.IndexShard current, org.opensearch.index.shard.IndexingOperationListener... listeners)
     
    protected final void
    replicateMergedSegments(org.opensearch.index.shard.IndexShard primaryShard, List<org.opensearch.index.shard.IndexShard> replicaShards)
    Segment Replication specific test method - Replicate merged segments to a list of replicas from a given primary.
    protected final List<org.opensearch.indices.replication.SegmentReplicationTarget>
    replicateSegments(org.opensearch.index.shard.IndexShard primaryShard, List<org.opensearch.index.shard.IndexShard> replicaShards)
    Segment Replication specific test method - Replicate segments to a list of replicas from a given primary.
    void
     
    protected org.opensearch.threadpool.ThreadPool
     
    protected String
    snapshotShard(org.opensearch.index.shard.IndexShard shard, org.opensearch.snapshots.Snapshot snapshot, org.opensearch.repositories.Repository repository)
    Snapshot a shard using a given repository.
    protected void
    startReplicaAfterRecovery(org.opensearch.index.shard.IndexShard replica, org.opensearch.index.shard.IndexShard primary, Set<String> inSyncIds, org.opensearch.cluster.routing.IndexShardRoutingTable routingTable)
     
    void
     
    protected void
     
    org.opensearch.common.settings.Settings
     
    protected void
    updateMappings(org.opensearch.index.shard.IndexShard shard, org.opensearch.cluster.metadata.IndexMetadata indexMetadata)
     
    static void
    updateRoutingEntry(org.opensearch.index.shard.IndexShard shard, org.opensearch.cluster.routing.ShardRouting shardRouting)
     

    Methods inherited from class org.opensearch.test.OpenSearchTestCase

    after, afterIfFailed, afterIfSuccessful, allowedWarnings, assertArrayEquals, assertBusy, assertBusy, assertBusyWithFixedSleepTime, assertEquals, assertNoDeprecationWarnings, assertSettingDeprecationsAndWarnings, assertSettingDeprecationsAndWarnings, assertWarnings, assertWarnings, before, between, buildEnvSettings, buildNewFakeTransportAddress, checkStaticState, clearAdditionalRoles, copyInstance, copyNamedWriteable, copyNamedWriteable, copyWriteable, copyWriteable, createDefaultIndexAnalyzers, createParser, createParser, createParser, createParser, createParser, createParser, createTestAnalysis, createTestAnalysis, createTestAnalysis, enableJodaDeprecationWarningsCheck, enableWarningsCheck, ensureAllSearchContextsReleased, ensureCheckIndexPassed, ensureSupportedLocale, frequently, generateRandomStringArray, generateRandomStringArray, getBasePort, getBasePort, getDataPath, getPortRange, getShardLevelBlobPath, getSuiteFailureMarker, getTestTransportPlugin, getTestTransportType, inFipsJvm, iterations, maybeSet, mockScript, newNodeEnvironment, newNodeEnvironment, persistedStateRegistry, randomAlphaOfLength, randomAlphaOfLengthBetween, randomArray, randomArray, randomBigInteger, randomBoolean, randomByte, randomByteArrayOfLength, randomDateFormatterPattern, randomDateTimeZone, randomDouble, randomDoubleBetween, randomFloat, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomGeohash, randomInt, randomInt, randomIntBetween, randomIp, randomList, randomList, randomLong, randomLongBetween, randomNonNegativeInt, randomNonNegativeLong, randomPositiveTimeValue, randomRealisticUnicodeOfCodepointLength, randomRealisticUnicodeOfCodepointLengthBetween, randomRealisticUnicodeOfLength, randomRealisticUnicodeOfLengthBetween, randomShort, randomSubsetOf, randomSubsetOf, randomSubsetOf, randomTimeValue, randomTimeValue, randomTimeValue, randomTimeZone, randomUnicodeOfCodepointLength, randomUnicodeOfCodepointLengthBetween, randomUnicodeOfLength, randomUnicodeOfLengthBetween, randomUnique, randomUnsignedLong, randomValueOtherThan, randomValueOtherThanMany, randomZone, remoteIndexSettings, removeHeaderWarningAppender, replaceUnicodeControlCharacters, replaceUnicodeControlCharacters, resetCheckIndexStatus, resetPortCounter, restoreContentType, restoreFileSystem, scaledRandomIntBetween, setContentType, setFileSystem, setHeaderWarningAppender, settings, shuffleMap, shuffleXContent, shuffleXContent, spinForAtLeastNMilliseconds, spinForAtLeastOneMillisecond, terminate, terminate, tmpPaths, toShuffledXContent, toShuffledXContent, waitUntil, waitUntil, warmIndexSettings, writableRegistry, xContentRegistry

    Methods inherited from class org.apache.lucene.tests.util.LuceneTestCase

    addVirusChecker, assertDeletedDocsEquals, assertDocsAndPositionsEnumEquals, assertDocsEnumEquals, assertDocsSkippingEquals, assertDocValuesEquals, assertDocValuesEquals, assertDoubleUlpEquals, assertFieldInfosEquals, assertFloatUlpEquals, assertNormsEquals, assertPointsEquals, assertPositionsSkippingEquals, assertReaderEquals, assertReaderStatisticsEquals, assertStoredFieldEquals, assertStoredFieldsEquals, assertTermsEnumEquals, assertTermsEquals, assertTermsEquals, assertTermsStatisticsEquals, assertTermStatsEquals, assertTermVectorsEquals, assertThat, assertThat, asSet, assumeFalse, assumeNoException, assumeTrue, atLeast, atLeast, callStackContains, callStackContains, callStackContainsAnyOf, closeAfterSuite, closeAfterTest, collate, createTempDir, createTempDir, createTempFile, createTempFile, dumpArray, dumpIterator, ensureSaneIWCOnNightly, expectThrows, expectThrows, expectThrows, expectThrowsAnyOf, expectThrowsAnyOf, getDataInputStream, getJvmForkArguments, getOnlyLeafReader, getTestClass, getTestName, isTestThread, localeForLanguageTag, maybeChangeLiveIndexWriterConfig, maybeWrapReader, newAlcoholicMergePolicy, newAlcoholicMergePolicy, newBytesRef, newBytesRef, newBytesRef, newBytesRef, newBytesRef, newBytesRef, newDirectory, newDirectory, newDirectory, newDirectory, newDirectory, newField, newField, newFSDirectory, newFSDirectory, newIndexWriterConfig, newIndexWriterConfig, newIndexWriterConfig, newIOContext, newIOContext, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newMaybeVirusCheckingDirectory, newMaybeVirusCheckingFSDirectory, newMergePolicy, newMergePolicy, newMergePolicy, newMockDirectory, newMockDirectory, newMockDirectory, newMockFSDirectory, newMockFSDirectory, newSearcher, newSearcher, newSearcher, newSearcher, newSearcher, newSnapshotIndexWriterConfig, newStringField, newStringField, newStringField, newStringField, newTextField, newTextField, newTieredMergePolicy, newTieredMergePolicy, overrideDefaultQueryCache, overrideTestDefaultQueryCache, random, randomLocale, randomTimeZone, randomVectorFormat, rarely, rarely, replaceMaxFailureRule, resetDefaultQueryCache, restoreCPUCoreCount, restoreIndexWriterMaxDocs, runWithRestrictedPermissions, setIndexWriterMaxDocs, setupCPUCoreCount, setUpExecutorService, shutdownExecutorService, slowFileExists, usually, usually, wrapReader

    Methods inherited from class org.junit.Assert

    assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThrows, assertThrows, assertTrue, assertTrue, fail, fail

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EMPTY_EVENT_LISTENER

      public static final org.opensearch.index.shard.IndexEventListener EMPTY_EVENT_LISTENER
    • recoveryListener

      protected static final org.opensearch.indices.replication.common.ReplicationListener recoveryListener
    • threadPool

      protected org.opensearch.threadpool.ThreadPool threadPool
    • primaryTerm

      protected long primaryTerm
    • clusterService

      protected org.opensearch.cluster.service.ClusterService clusterService
    • currentClusterStateVersion

      protected static AtomicLong currentClusterStateVersion
  • Constructor Details

    • IndexShardTestCase

      public IndexShardTestCase()
  • Method Details

    • setUp

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

      protected org.opensearch.threadpool.ThreadPool setUpThreadPool()
    • tearDown

      public void tearDown() throws Exception
      Overrides:
      tearDown in class OpenSearchTestCase
      Throws:
      Exception
    • tearDownThreadPool

      protected void tearDownThreadPool()
    • allowShardFailures

      protected void allowShardFailures()
      by default, tests will fail if any shard created by this class fails. Tests that cause failures by design can call this method to ignore those failures
    • failOnShardFailures

      protected void failOnShardFailures()
    • threadPoolSettings

      public org.opensearch.common.settings.Settings threadPoolSettings()
    • createStore

      protected org.opensearch.index.store.Store createStore(org.opensearch.index.IndexSettings indexSettings, org.opensearch.index.shard.ShardPath shardPath) throws IOException
      Throws:
      IOException
    • createStore

      protected org.opensearch.index.store.Store createStore(org.opensearch.core.index.shard.ShardId shardId, org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.store.Directory directory, org.opensearch.index.shard.ShardPath shardPath) throws IOException
      Throws:
      IOException
    • acquirePrimaryOperationPermitBlockingly

      protected org.opensearch.common.lease.Releasable acquirePrimaryOperationPermitBlockingly(org.opensearch.index.shard.IndexShard indexShard) throws ExecutionException, InterruptedException
      Throws:
      ExecutionException
      InterruptedException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(boolean primary) throws IOException
      Creates a new initializing shard. The shard will have its own unique data path.
      Parameters:
      primary - indicates whether to a primary shard (ready to recover from an empty store) or a replica (ready to recover from another shard)
      Throws:
      IOException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(boolean primary, org.opensearch.common.settings.Settings settings) throws IOException
      Creates a new initializing shard. The shard will have its own unique data path.
      Parameters:
      primary - indicates whether to a primary shard (ready to recover from an empty store) or a replica (ready to recover from another shard)
      Throws:
      IOException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(boolean primary, org.opensearch.common.settings.Settings settings, org.opensearch.index.engine.EngineFactory engineFactory) throws IOException
      Creates a new initializing shard. The shard will have its own unique data path.
      Parameters:
      primary - indicates whether to a primary shard (ready to recover from an empty store) or a replica (ready to recover from another shard)
      settings - the settings to use for this shard
      engineFactory - the engine factory to use for this shard
      Throws:
      IOException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(org.opensearch.cluster.routing.ShardRouting shardRouting, org.opensearch.index.shard.IndexingOperationListener... listeners) throws IOException
      Throws:
      IOException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(org.opensearch.cluster.routing.ShardRouting shardRouting, org.opensearch.common.settings.Settings settings, org.opensearch.index.shard.IndexingOperationListener... listeners) throws IOException
      Throws:
      IOException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(org.opensearch.cluster.routing.ShardRouting shardRouting, org.opensearch.common.settings.Settings settings, org.opensearch.index.engine.EngineFactory engineFactory, org.opensearch.index.shard.IndexingOperationListener... listeners) throws IOException
      Creates a new initializing shard. The shard will have its own unique data path.
      Parameters:
      shardRouting - the ShardRouting to use for this shard
      settings - the settings to use for this shard
      engineFactory - the engine factory to use for this shard
      listeners - an optional set of listeners to add to the shard
      Throws:
      IOException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(org.opensearch.core.index.shard.ShardId shardId, boolean primary, org.opensearch.index.shard.IndexingOperationListener... listeners) throws IOException
      creates a new initializing shard. The shard will have its own unique data path.
      Parameters:
      shardId - the shard id to use
      primary - indicates whether to a primary shard (ready to recover from an empty store) or a replica (ready to recover from another shard)
      listeners - an optional set of listeners to add to the shard
      Throws:
      IOException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(org.opensearch.core.index.shard.ShardId shardId, boolean primary, String nodeId, org.opensearch.cluster.metadata.IndexMetadata indexMetadata, @Nullable org.opensearch.common.CheckedFunction<org.apache.lucene.index.DirectoryReader, org.apache.lucene.index.DirectoryReader, IOException> readerWrapper) throws IOException
      creates a new initializing shard. The shard will be put in its proper path under the supplied node id.
      Parameters:
      shardId - the shard id to use
      primary - indicates whether to a primary shard (ready to recover from an empty store) or a replica (ready to recover from another shard)
      Throws:
      IOException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(org.opensearch.core.index.shard.ShardId shardId, boolean primary, String nodeId, org.opensearch.cluster.metadata.IndexMetadata indexMetadata, @Nullable org.opensearch.common.CheckedFunction<org.apache.lucene.index.DirectoryReader, org.apache.lucene.index.DirectoryReader, IOException> readerWrapper, Runnable globalCheckpointSyncer) throws IOException
      creates a new initializing shard. The shard will be put in its proper path under the supplied node id.
      Parameters:
      shardId - the shard id to use
      primary - indicates whether to a primary shard (ready to recover from an empty store) or a replica (ready to recover from another shard)
      Throws:
      IOException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(org.opensearch.cluster.routing.ShardRouting routing, org.opensearch.cluster.metadata.IndexMetadata indexMetadata, @Nullable org.opensearch.common.CheckedFunction<org.apache.lucene.index.DirectoryReader, org.apache.lucene.index.DirectoryReader, IOException> indexReaderWrapper, org.opensearch.index.engine.EngineFactory engineFactory, org.opensearch.index.shard.IndexingOperationListener... listeners) throws IOException
      creates a new initializing shard. The shard will be put in its proper path under the current node id the shard is assigned to.
      Parameters:
      routing - shard routing to use
      indexMetadata - indexMetadata for the shard, including any mapping
      listeners - an optional set of listeners to add to the shard
      Throws:
      IOException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(org.opensearch.cluster.routing.ShardRouting routing, org.opensearch.cluster.metadata.IndexMetadata indexMetadata, @Nullable org.opensearch.common.CheckedFunction<org.apache.lucene.index.DirectoryReader, org.apache.lucene.index.DirectoryReader, IOException> indexReaderWrapper, @Nullable org.opensearch.index.engine.EngineFactory engineFactory, Runnable globalCheckpointSyncer, org.opensearch.index.seqno.RetentionLeaseSyncer retentionLeaseSyncer, Path path, org.opensearch.index.shard.IndexingOperationListener... listeners) throws IOException
      creates a new initializing shard. The shard will be put in its proper path under the current node id the shard is assigned to.
      Parameters:
      routing - shard routing to use
      indexMetadata - indexMetadata for the shard, including any mapping
      indexReaderWrapper - an optional wrapper to be used during search
      globalCheckpointSyncer - callback for syncing global checkpoints
      listeners - an optional set of listeners to add to the shard
      Throws:
      IOException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(org.opensearch.cluster.routing.ShardRouting routing, org.opensearch.index.shard.ShardPath shardPath, org.opensearch.cluster.metadata.IndexMetadata indexMetadata, @Nullable org.opensearch.common.CheckedFunction<org.opensearch.index.IndexSettings, org.opensearch.index.store.Store, IOException> storeProvider, @Nullable org.opensearch.common.CheckedFunction<org.apache.lucene.index.DirectoryReader, org.apache.lucene.index.DirectoryReader, IOException> indexReaderWrapper, @Nullable org.opensearch.index.engine.EngineFactory engineFactory, @Nullable org.opensearch.index.engine.EngineConfigFactory engineConfigFactory, Runnable globalCheckpointSyncer, org.opensearch.index.seqno.RetentionLeaseSyncer retentionLeaseSyncer, org.opensearch.index.shard.IndexEventListener indexEventListener, Path remotePath, org.opensearch.index.shard.IndexingOperationListener... listeners) throws IOException
      creates a new initializing shard. The shard will be put in its proper path under the current node id the shard is assigned to.
      Parameters:
      routing - shard routing to use
      shardPath - path to use for shard data
      indexMetadata - indexMetadata for the shard, including any mapping
      storeProvider - an optional custom store provider to use. If null a default file based store will be created
      indexReaderWrapper - an optional wrapper to be used during search
      globalCheckpointSyncer - callback for syncing global checkpoints
      indexEventListener - index event listener
      listeners - an optional set of listeners to add to the shard
      Throws:
      IOException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(boolean primary, org.opensearch.indices.replication.checkpoint.SegmentReplicationCheckpointPublisher checkpointPublisher) throws IOException
      Throws:
      IOException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(boolean primary, org.opensearch.indices.replication.checkpoint.SegmentReplicationCheckpointPublisher checkpointPublisher, org.opensearch.common.settings.Settings settings) throws IOException
      creates a new initializing shard. The shard will be put in its proper path under the current node id the shard is assigned to.
      Parameters:
      checkpointPublisher - Segment Replication Checkpoint Publisher to publish checkpoint
      Throws:
      IOException
    • newShard

      protected org.opensearch.index.shard.IndexShard newShard(org.opensearch.cluster.routing.ShardRouting routing, org.opensearch.index.shard.ShardPath shardPath, org.opensearch.cluster.metadata.IndexMetadata indexMetadata, @Nullable org.opensearch.common.CheckedFunction<org.opensearch.index.IndexSettings, org.opensearch.index.store.Store, IOException> storeProvider, @Nullable org.opensearch.common.CheckedFunction<org.apache.lucene.index.DirectoryReader, org.apache.lucene.index.DirectoryReader, IOException> indexReaderWrapper, @Nullable org.opensearch.index.engine.EngineFactory engineFactory, @Nullable org.opensearch.index.engine.EngineConfigFactory engineConfigFactory, Runnable globalCheckpointSyncer, org.opensearch.index.seqno.RetentionLeaseSyncer retentionLeaseSyncer, org.opensearch.index.shard.IndexEventListener indexEventListener, org.opensearch.indices.replication.checkpoint.SegmentReplicationCheckpointPublisher checkpointPublisher, @Nullable Path remotePath, org.opensearch.index.shard.IndexingOperationListener... listeners) throws IOException
      creates a new initializing shard.
      Parameters:
      routing - shard routing to use
      shardPath - path to use for shard data
      indexMetadata - indexMetadata for the shard, including any mapping
      storeProvider - an optional custom store provider to use. If null a default file based store will be created
      indexReaderWrapper - an optional wrapper to be used during search
      globalCheckpointSyncer - callback for syncing global checkpoints
      indexEventListener - index event listener
      checkpointPublisher - segment Replication Checkpoint Publisher to publish checkpoint
      listeners - an optional set of listeners to add to the shard
      Throws:
      IOException
    • createRepositoriesService

      protected org.opensearch.repositories.RepositoriesService createRepositoriesService()
    • createRemoteStore

      protected org.opensearch.index.store.Store createRemoteStore(Path path, org.opensearch.cluster.routing.ShardRouting shardRouting, org.opensearch.cluster.metadata.IndexMetadata metadata, org.opensearch.index.shard.ShardPath shardPath) throws IOException
      Throws:
      IOException
    • createRemoteSegmentStoreDirectory

      protected org.opensearch.index.store.RemoteSegmentStoreDirectory createRemoteSegmentStoreDirectory(org.opensearch.core.index.shard.ShardId shardId, Path path) throws IOException
      Throws:
      IOException
    • getBlobContainer

      protected org.opensearch.common.blobstore.BlobContainer getBlobContainer(Path f) throws IOException
      Throws:
      IOException
    • reinitShard

      protected org.opensearch.index.shard.IndexShard reinitShard(org.opensearch.index.shard.IndexShard current, org.opensearch.index.shard.IndexingOperationListener... listeners) throws IOException
      Throws:
      IOException
    • reinitShard

      protected org.opensearch.index.shard.IndexShard reinitShard(org.opensearch.index.shard.IndexShard current, Path remotePath, org.opensearch.index.shard.IndexingOperationListener... listeners) throws IOException
      Takes an existing shard, closes it and starts a new initialing shard at the same location
      Parameters:
      current - The current shard to reinit
      remotePath - Remote path to recover from if remote storage is used
      listeners - new listerns to use for the newly created shard
      Throws:
      IOException
    • reinitShard

      protected org.opensearch.index.shard.IndexShard reinitShard(org.opensearch.index.shard.IndexShard current, org.opensearch.cluster.routing.ShardRouting routing, org.opensearch.index.shard.IndexingOperationListener... listeners) throws IOException
      Takes an existing shard, closes it and starts a new initialing shard at the same location
      Parameters:
      routing - the shard routing to use for the newly created shard.
      listeners - new listerns to use for the newly created shard
      Throws:
      IOException
    • reinitShard

      protected org.opensearch.index.shard.IndexShard reinitShard(org.opensearch.index.shard.IndexShard current, org.opensearch.cluster.routing.ShardRouting routing, Path remotePath, org.opensearch.index.shard.IndexingOperationListener... listeners) throws IOException
      Throws:
      IOException
    • reinitShard

      protected org.opensearch.index.shard.IndexShard reinitShard(org.opensearch.index.shard.IndexShard current, org.opensearch.cluster.routing.ShardRouting routing, org.opensearch.cluster.metadata.IndexMetadata indexMetadata, org.opensearch.index.engine.EngineFactory engineFactory, org.opensearch.index.engine.EngineConfigFactory engineConfigFactory, Path remotePath, org.opensearch.index.shard.IndexingOperationListener... listeners) throws IOException
      Takes an existing shard, closes it and starts a new initialing shard at the same location
      Parameters:
      routing - the shard routing to use for the newly created shard.
      indexMetadata - the index metadata to use for the newly created shard
      engineFactory - the engine factory for the new shard
      listeners - new listerns to use for the newly created shard
      Throws:
      IOException
    • newStartedShard

      protected org.opensearch.index.shard.IndexShard newStartedShard() throws IOException
      Creates a new empty shard and starts it. The shard will randomly be a replica or a primary.
      Throws:
      IOException
    • newStartedShard

      protected org.opensearch.index.shard.IndexShard newStartedShard(org.opensearch.common.settings.Settings settings) throws IOException
      Creates a new empty shard and starts it
      Parameters:
      settings - the settings to use for this shard
      Throws:
      IOException
    • newStartedShard

      protected org.opensearch.index.shard.IndexShard newStartedShard(boolean primary) throws IOException
      Creates a new empty shard and starts it.
      Parameters:
      primary - controls whether the shard will be a primary or a replica.
      Throws:
      IOException
    • newStartedShard

      protected org.opensearch.index.shard.IndexShard newStartedShard(boolean primary, org.opensearch.common.settings.Settings settings) throws IOException
      Creates a new empty shard and starts it.
      Parameters:
      primary - controls whether the shard will be a primary or a replica.
      settings - the settings to use for this shard
      Throws:
      IOException
    • newStartedShard

      protected org.opensearch.index.shard.IndexShard newStartedShard(boolean primary, org.opensearch.common.settings.Settings settings, org.opensearch.index.engine.EngineFactory engineFactory) throws IOException
      Creates a new empty shard with the specified settings and engine factory and starts it.
      Parameters:
      primary - controls whether the shard will be a primary or a replica.
      settings - the settings to use for this shard
      engineFactory - the engine factory to use for this shard
      Throws:
      IOException
    • newStartedShard

      protected org.opensearch.index.shard.IndexShard newStartedShard(org.opensearch.common.CheckedFunction<Boolean, org.opensearch.index.shard.IndexShard, IOException> shardFunction, boolean primary) throws IOException
      creates a new empty shard and starts it.
      Parameters:
      shardFunction - shard factory function
      primary - controls whether the shard will be a primary or a replica.
      Throws:
      IOException
    • closeShards

      protected void closeShards(org.opensearch.index.shard.IndexShard... shards) throws IOException
      Throws:
      IOException
    • closeShard

      protected void closeShard(org.opensearch.index.shard.IndexShard shard, boolean assertConsistencyBetweenTranslogAndLucene) throws IOException
      Throws:
      IOException
    • closeShards

      protected void closeShards(Iterable<org.opensearch.index.shard.IndexShard> shards) throws IOException
      Throws:
      IOException
    • recoverShardFromStore

      protected void recoverShardFromStore(org.opensearch.index.shard.IndexShard primary) throws IOException
      Throws:
      IOException
    • updateRoutingEntry

      public static void updateRoutingEntry(org.opensearch.index.shard.IndexShard shard, org.opensearch.cluster.routing.ShardRouting shardRouting) throws IOException
      Throws:
      IOException
    • recoveryEmptyReplica

      protected void recoveryEmptyReplica(org.opensearch.index.shard.IndexShard replica, boolean startReplica) throws IOException
      Throws:
      IOException
    • recoverReplica

      protected void recoverReplica(org.opensearch.index.shard.IndexShard replica, org.opensearch.index.shard.IndexShard primary, boolean startReplica) throws IOException
      Throws:
      IOException
    • recoverReplica

      protected void recoverReplica(org.opensearch.index.shard.IndexShard replica, org.opensearch.index.shard.IndexShard primary, boolean startReplica, Function<List<org.opensearch.index.shard.IndexShard>, List<org.opensearch.indices.replication.SegmentReplicationTarget>> replicatePrimaryFunction) throws IOException
      recovers a replica from the given primary
      Throws:
      IOException
    • recoverReplica

      protected void recoverReplica(org.opensearch.index.shard.IndexShard replica, org.opensearch.index.shard.IndexShard primary, BiFunction<org.opensearch.index.shard.IndexShard, org.opensearch.cluster.node.DiscoveryNode, org.opensearch.indices.recovery.RecoveryTarget> targetSupplier, boolean markAsRecovering, boolean markAsStarted) throws IOException
      Throws:
      IOException
    • getReplicationFunc

      public Function<List<org.opensearch.index.shard.IndexShard>, List<org.opensearch.indices.replication.SegmentReplicationTarget>> getReplicationFunc(org.opensearch.index.shard.IndexShard target)
    • recoverReplica

      protected void recoverReplica(org.opensearch.index.shard.IndexShard replica, org.opensearch.index.shard.IndexShard primary, BiFunction<org.opensearch.index.shard.IndexShard, org.opensearch.cluster.node.DiscoveryNode, org.opensearch.indices.recovery.RecoveryTarget> targetSupplier, boolean markAsRecovering, boolean markAsStarted, Function<List<org.opensearch.index.shard.IndexShard>, List<org.opensearch.indices.replication.SegmentReplicationTarget>> replicatePrimaryFunction) throws IOException
      recovers a replica from the given primary
      Throws:
      IOException
    • recoverUnstartedReplica

      public final void recoverUnstartedReplica(org.opensearch.index.shard.IndexShard replica, org.opensearch.index.shard.IndexShard primary, BiFunction<org.opensearch.index.shard.IndexShard, org.opensearch.cluster.node.DiscoveryNode, org.opensearch.indices.recovery.RecoveryTarget> targetSupplier, boolean markAsRecovering, Set<String> inSyncIds, org.opensearch.cluster.routing.IndexShardRoutingTable routingTable, Function<List<org.opensearch.index.shard.IndexShard>, List<org.opensearch.indices.replication.SegmentReplicationTarget>> replicatePrimaryFunction) throws IOException
      Recovers a replica from the give primary, allow the user to supply a custom recovery target. A typical usage of a custom recovery target is to assert things in the various stages of recovery.

      Note: this method keeps the shard in IndexShardState.POST_RECOVERY and doesn't start it.

      Parameters:
      replica - the recovery target shard
      primary - the recovery source shard
      targetSupplier - supplies an instance of RecoveryTarget
      markAsRecovering - set to false if the replica is marked as recovering
      Throws:
      IOException
    • startReplicaAfterRecovery

      protected void startReplicaAfterRecovery(org.opensearch.index.shard.IndexShard replica, org.opensearch.index.shard.IndexShard primary, Set<String> inSyncIds, org.opensearch.cluster.routing.IndexShardRoutingTable routingTable) throws IOException
      Throws:
      IOException
    • promoteReplica

      protected void promoteReplica(org.opensearch.index.shard.IndexShard replica, Set<String> inSyncIds, org.opensearch.cluster.routing.IndexShardRoutingTable routingTable) throws IOException
      promotes a replica to primary, incrementing it's term and starting it if needed
      Throws:
      IOException
    • getShardDocUIDs

      public static Set<String> getShardDocUIDs(org.opensearch.index.shard.IndexShard shard) throws IOException
      Throws:
      IOException
    • getDocIdAndSeqNos

      public static List<DocIdSeqNoAndSource> getDocIdAndSeqNos(org.opensearch.index.shard.IndexShard shard) throws IOException
      Throws:
      IOException
    • assertDocCount

      protected void assertDocCount(org.opensearch.index.shard.IndexShard shard, int docDount) throws IOException
      Throws:
      IOException
    • assertDocs

      protected void assertDocs(org.opensearch.index.shard.IndexShard shard, String... ids) throws IOException
      Throws:
      IOException
    • assertConsistentHistoryBetweenTranslogAndLucene

      public static void assertConsistentHistoryBetweenTranslogAndLucene(org.opensearch.index.shard.IndexShard shard) throws IOException
      Throws:
      IOException
    • indexDoc

      protected org.opensearch.index.engine.Engine.IndexResult indexDoc(org.opensearch.index.shard.IndexShard shard, String type, String id) throws IOException
      Throws:
      IOException
    • indexDoc

      protected org.opensearch.index.engine.Engine.IndexResult indexDoc(org.opensearch.index.shard.IndexShard shard, String type, String id, String source) throws IOException
      Throws:
      IOException
    • indexDoc

      protected org.opensearch.index.engine.Engine.IndexResult indexDoc(org.opensearch.index.shard.IndexShard shard, String id, String source, org.opensearch.core.xcontent.MediaType mediaType, String routing) throws IOException
      Throws:
      IOException
    • updateMappings

      protected void updateMappings(org.opensearch.index.shard.IndexShard shard, org.opensearch.cluster.metadata.IndexMetadata indexMetadata)
    • deleteDoc

      protected org.opensearch.index.engine.Engine.DeleteResult deleteDoc(org.opensearch.index.shard.IndexShard shard, String id) throws IOException
      Throws:
      IOException
    • flushShard

      protected void flushShard(org.opensearch.index.shard.IndexShard shard)
    • flushShard

      protected void flushShard(org.opensearch.index.shard.IndexShard shard, boolean force)
    • recoverFromStore

      public static boolean recoverFromStore(org.opensearch.index.shard.IndexShard newShard)
    • recoverShardFromSnapshot

      protected void recoverShardFromSnapshot(org.opensearch.index.shard.IndexShard shard, org.opensearch.snapshots.Snapshot snapshot, org.opensearch.repositories.Repository repository)
      Recover a shard from a snapshot using a given repository
    • snapshotShard

      protected String snapshotShard(org.opensearch.index.shard.IndexShard shard, org.opensearch.snapshots.Snapshot snapshot, org.opensearch.repositories.Repository repository) throws IOException
      Snapshot a shard using a given repository.
      Returns:
      new shard generation
      Throws:
      IOException
    • getEngine

      public static org.opensearch.index.engine.Engine getEngine(org.opensearch.index.shard.IndexShard indexShard)
      Helper method to access (package-protected) engine from tests
    • getTranslog

      public static org.opensearch.index.translog.Translog getTranslog(org.opensearch.index.shard.IndexShard shard)
    • getReplicationTracker

      public static org.opensearch.index.seqno.ReplicationTracker getReplicationTracker(org.opensearch.index.shard.IndexShard indexShard)
    • createTestWarmer

      public static org.opensearch.index.engine.Engine.Warmer createTestWarmer(org.opensearch.index.IndexSettings indexSettings)
    • prepareForReplication

      public final org.opensearch.indices.replication.SegmentReplicationTargetService prepareForReplication(org.opensearch.index.shard.IndexShard primaryShard, org.opensearch.index.shard.IndexShard target)
      Segment Replication specific test method - Creates a SegmentReplicationTargetService to perform replications that has been configured to return the given primaryShard's current segments.
      Parameters:
      primaryShard - IndexShard - The primary shard to replicate from.
      target - IndexShard - The target replica shard.
      Returns:
      Returns SegmentReplicationTargetService
    • prepareForReplication

      public final org.opensearch.indices.replication.SegmentReplicationTargetService prepareForReplication(org.opensearch.index.shard.IndexShard primaryShard, org.opensearch.index.shard.IndexShard target, org.opensearch.transport.TransportService transportService, org.opensearch.indices.IndicesService indicesService, org.opensearch.cluster.service.ClusterService clusterService)
    • getTargetListener

      public org.opensearch.indices.replication.SegmentReplicationTargetService.SegmentReplicationListener getTargetListener(org.opensearch.index.shard.IndexShard primaryShard, org.opensearch.index.shard.IndexShard replicaShard, Map<String, org.opensearch.index.store.StoreFileMetadata> primaryMetadata, CountDownLatch latch)
      Get listener on started segment replication event which verifies replica shard store with primary's after completion
      Parameters:
      primaryShard - - source of segment replication
      replicaShard - - target of segment replication
      primaryMetadata - - primary shard metadata before start of segment replication
      latch - - Latch which allows consumers of this utility to ensure segment replication completed successfully
      Returns:
      Returns SegmentReplicationTargetService.SegmentReplicationListener
    • getMergedSegmentTargetListener

      public org.opensearch.indices.replication.SegmentReplicationTargetService.SegmentReplicationListener getMergedSegmentTargetListener(org.opensearch.index.shard.IndexShard primaryShard, org.opensearch.index.shard.IndexShard replicaShard, Map<String, org.opensearch.index.store.StoreFileMetadata> primaryMetadata, CountDownLatch latch)
      Get listener on started merged segment replication event which verifies replica shard store with primary's after completion
      Parameters:
      primaryShard - - source of segment replication
      replicaShard - - target of segment replication
      primaryMetadata - - primary shard metadata before start of segment replication
      latch - - Latch which allows consumers of this utility to ensure segment replication completed successfully
      Returns:
      Returns SegmentReplicationTargetService.SegmentReplicationListener
    • getSegmentReplicationSource

      public org.opensearch.indices.replication.SegmentReplicationSource getSegmentReplicationSource(org.opensearch.index.shard.IndexShard primaryShard, Function<Long, org.opensearch.indices.replication.common.ReplicationCollection.ReplicationRef<org.opensearch.indices.replication.SegmentReplicationTarget>> getTargetFunc, Function<Long, org.opensearch.indices.replication.common.ReplicationCollection.ReplicationRef<org.opensearch.indices.replication.MergedSegmentReplicationTarget>> getMergedSegmentTargetFunc, Consumer<org.opensearch.index.shard.IndexShard> postGetFilesRunnable)
      Utility method which creates a segment replication source, which copies files from primary shard to target shard
      Parameters:
      primaryShard - Primary IndexShard - source of segment replication
      getTargetFunc - - provides replication target from target service using replication id
      getMergedSegmentTargetFunc - - provides merged segment replication target from target service using replication id
      postGetFilesRunnable - - Consumer which is executed after file copy operation. This can be used to stub operations which are desired right after files are copied. e.g. To work with temp files
      Returns:
      Return SegmentReplicationSource
    • replicateSegments

      protected final List<org.opensearch.indices.replication.SegmentReplicationTarget> replicateSegments(org.opensearch.index.shard.IndexShard primaryShard, List<org.opensearch.index.shard.IndexShard> replicaShards) throws IOException, InterruptedException
      Segment Replication specific test method - Replicate segments to a list of replicas from a given primary. This test will use a real SegmentReplicationTarget for each replica with a mock SegmentReplicationSource that writes all segments directly to the target.
      Parameters:
      primaryShard - - IndexShard The current primary shard.
      replicaShards - - Replicas that will be updated.
      Returns:
      List List of target components orchestrating replication.
      Throws:
      IOException
      InterruptedException
    • replicateMergedSegments

      protected final void replicateMergedSegments(org.opensearch.index.shard.IndexShard primaryShard, List<org.opensearch.index.shard.IndexShard> replicaShards) throws IOException, InterruptedException
      Segment Replication specific test method - Replicate merged segments to a list of replicas from a given primary. This test will use a real SegmentReplicationTarget for each replica with a mock SegmentReplicationSource that writes all segments directly to the target.
      Parameters:
      primaryShard - - IndexShard The current primary shard.
      replicaShards - - Replicas that will be updated.
      Throws:
      IOException
      InterruptedException