Search in sources :

Example 1 with DirectoryService

use of org.elasticsearch.index.store.DirectoryService in project elasticsearch by elastic.

the class RefreshListenersTests method setupListeners.

@Before
public void setupListeners() throws Exception {
    // Setup dependencies of the listeners
    maxListeners = randomIntBetween(1, 1000);
    listeners = new RefreshListeners(() -> maxListeners, () -> engine.refresh("too-many-listeners"), // Immediately run listeners rather than adding them to the listener thread pool like IndexShard does to simplify the test.
    Runnable::run, logger);
    // Now setup the InternalEngine which is much more complicated because we aren't mocking anything
    threadPool = new TestThreadPool(getTestName());
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("index", Settings.EMPTY);
    ShardId shardId = new ShardId(new Index("index", "_na_"), 1);
    Directory directory = newDirectory();
    DirectoryService directoryService = new DirectoryService(shardId, indexSettings) {

        @Override
        public Directory newDirectory() throws IOException {
            return directory;
        }
    };
    store = new Store(shardId, indexSettings, directoryService, new DummyShardLock(shardId));
    IndexWriterConfig iwc = newIndexWriterConfig();
    TranslogConfig translogConfig = new TranslogConfig(shardId, createTempDir("translog"), indexSettings, BigArrays.NON_RECYCLING_INSTANCE);
    Engine.EventListener eventListener = new Engine.EventListener() {

        @Override
        public void onFailedEngine(String reason, @Nullable Exception e) {
        // we don't need to notify anybody in this test
        }
    };
    TranslogHandler translogHandler = new TranslogHandler(xContentRegistry(), shardId.getIndexName(), logger);
    EngineConfig config = new EngineConfig(EngineConfig.OpenMode.CREATE_INDEX_AND_TRANSLOG, shardId, threadPool, indexSettings, null, store, new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy()), newMergePolicy(), iwc.getAnalyzer(), iwc.getSimilarity(), new CodecService(null, logger), eventListener, translogHandler, IndexSearcher.getDefaultQueryCache(), IndexSearcher.getDefaultQueryCachingPolicy(), translogConfig, TimeValue.timeValueMinutes(5), listeners, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP);
    engine = new InternalEngine(config);
    listeners.setTranslog(engine.getTranslog());
}
Also used : KeepOnlyLastCommitDeletionPolicy(org.apache.lucene.index.KeepOnlyLastCommitDeletionPolicy) TranslogConfig(org.elasticsearch.index.translog.TranslogConfig) IndexSettings(org.elasticsearch.index.IndexSettings) Store(org.elasticsearch.index.store.Store) Index(org.elasticsearch.index.Index) DirectoryService(org.elasticsearch.index.store.DirectoryService) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) IOException(java.io.IOException) SnapshotDeletionPolicy(org.apache.lucene.index.SnapshotDeletionPolicy) InternalEngine(org.elasticsearch.index.engine.InternalEngine) TranslogHandler(org.elasticsearch.index.engine.InternalEngineTests.TranslogHandler) CodecService(org.elasticsearch.index.codec.CodecService) DummyShardLock(org.elasticsearch.test.DummyShardLock) EngineConfig(org.elasticsearch.index.engine.EngineConfig) Nullable(org.elasticsearch.common.Nullable) Engine(org.elasticsearch.index.engine.Engine) InternalEngine(org.elasticsearch.index.engine.InternalEngine) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Example 2 with DirectoryService

use of org.elasticsearch.index.store.DirectoryService in project elasticsearch by elastic.

the class ShadowEngineTests method createStore.

protected Store createStore(final Directory directory) throws IOException {
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(shardId.getIndex(), Settings.EMPTY);
    final DirectoryService directoryService = new DirectoryService(shardId, indexSettings) {

        @Override
        public Directory newDirectory() throws IOException {
            return directory;
        }
    };
    return new Store(shardId, indexSettings, directoryService, new DummyShardLock(shardId));
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Store(org.elasticsearch.index.store.Store) DirectoryService(org.elasticsearch.index.store.DirectoryService) DummyShardLock(org.elasticsearch.test.DummyShardLock)

Example 3 with DirectoryService

use of org.elasticsearch.index.store.DirectoryService in project elasticsearch by elastic.

the class IndexShardTestCase method createStore.

private Store createStore(IndexSettings indexSettings, ShardPath shardPath) throws IOException {
    final ShardId shardId = shardPath.getShardId();
    final DirectoryService directoryService = new DirectoryService(shardId, indexSettings) {

        @Override
        public Directory newDirectory() throws IOException {
            return newFSDirectory(shardPath.resolveIndex());
        }
    };
    return new Store(shardId, indexSettings, directoryService, new DummyShardLock(shardId));
}
Also used : Store(org.elasticsearch.index.store.Store) DirectoryService(org.elasticsearch.index.store.DirectoryService) DummyShardLock(org.elasticsearch.test.DummyShardLock)

Aggregations

DirectoryService (org.elasticsearch.index.store.DirectoryService)3 Store (org.elasticsearch.index.store.Store)3 DummyShardLock (org.elasticsearch.test.DummyShardLock)3 IndexSettings (org.elasticsearch.index.IndexSettings)2 IOException (java.io.IOException)1 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)1 KeepOnlyLastCommitDeletionPolicy (org.apache.lucene.index.KeepOnlyLastCommitDeletionPolicy)1 SnapshotDeletionPolicy (org.apache.lucene.index.SnapshotDeletionPolicy)1 Directory (org.apache.lucene.store.Directory)1 Nullable (org.elasticsearch.common.Nullable)1 Index (org.elasticsearch.index.Index)1 CodecService (org.elasticsearch.index.codec.CodecService)1 Engine (org.elasticsearch.index.engine.Engine)1 EngineConfig (org.elasticsearch.index.engine.EngineConfig)1 InternalEngine (org.elasticsearch.index.engine.InternalEngine)1 TranslogHandler (org.elasticsearch.index.engine.InternalEngineTests.TranslogHandler)1 TranslogConfig (org.elasticsearch.index.translog.TranslogConfig)1 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)1 Before (org.junit.Before)1