Search in sources :

Example 41 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool in project elasticsearch by elastic.

the class AsyncShardFetchTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    this.threadPool = new TestThreadPool(getTestName());
    this.test = new TestFetch(threadPool);
}
Also used : TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 42 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool 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 43 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool in project elasticsearch by elastic.

the class ShadowEngineTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    CodecService codecService = new CodecService(null, logger);
    String name = Codec.getDefault().getName();
    if (Arrays.asList(codecService.availableCodecs()).contains(name)) {
        // some codecs are read only so we only take the ones that we have in the service and randomly
        // selected by lucene test case.
        codecName = name;
    } else {
        codecName = "default";
    }
    defaultSettings = IndexSettingsModule.newIndexSettings("test", Settings.builder().put(IndexSettings.INDEX_GC_DELETES_SETTING, // make sure this doesn't kick in on us
    "1h").put(EngineConfig.INDEX_CODEC_SETTING.getKey(), codecName).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build());
    threadPool = new TestThreadPool(getClass().getName());
    dirPath = createTempDir();
    store = createStore(dirPath);
    storeReplica = createStore(dirPath);
    Lucene.cleanLuceneIndex(store.directory());
    Lucene.cleanLuceneIndex(storeReplica.directory());
    primaryEngine = createInternalEngine(store, createTempDir("translog-primary"));
    LiveIndexWriterConfig currentIndexWriterConfig = ((InternalEngine) primaryEngine).getCurrentIndexWriterConfig();
    assertEquals(primaryEngine.config().getCodec().getName(), codecService.codec(codecName).getName());
    assertEquals(currentIndexWriterConfig.getCodec().getName(), codecService.codec(codecName).getName());
    if (randomBoolean()) {
        primaryEngine.config().setEnableGcDeletes(false);
    }
    replicaEngine = createShadowEngine(storeReplica);
    assertEquals(replicaEngine.config().getCodec().getName(), codecService.codec(codecName).getName());
    if (randomBoolean()) {
        replicaEngine.config().setEnableGcDeletes(false);
    }
}
Also used : LiveIndexWriterConfig(org.apache.lucene.index.LiveIndexWriterConfig) CodecService(org.elasticsearch.index.codec.CodecService) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 44 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool in project elasticsearch by elastic.

the class IndicesClusterStateServiceRandomUpdatesTests method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    threadPool = new TestThreadPool(getClass().getName());
    cluster = new ClusterStateChanges(xContentRegistry(), threadPool);
}
Also used : TestThreadPool(org.elasticsearch.threadpool.TestThreadPool)

Example 45 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool in project elasticsearch by elastic.

the class ResourceWatcherServiceTests method testHandle.

public void testHandle() throws Exception {
    ThreadPool threadPool = new TestThreadPool("test");
    Settings settings = Settings.builder().build();
    ResourceWatcherService service = new ResourceWatcherService(settings, threadPool);
    ResourceWatcher watcher = new ResourceWatcher() {

        @Override
        public void init() {
        }

        @Override
        public void checkAndNotify() {
        }
    };
    // checking default freq
    WatcherHandle handle = service.add(watcher);
    assertThat(handle, notNullValue());
    assertThat(handle.frequency(), equalTo(ResourceWatcherService.Frequency.MEDIUM));
    assertThat(service.lowMonitor.watchers.size(), is(0));
    assertThat(service.highMonitor.watchers.size(), is(0));
    assertThat(service.mediumMonitor.watchers.size(), is(1));
    handle.stop();
    assertThat(service.mediumMonitor.watchers.size(), is(0));
    handle.resume();
    assertThat(service.mediumMonitor.watchers.size(), is(1));
    handle.stop();
    // checking custom freq
    handle = service.add(watcher, ResourceWatcherService.Frequency.HIGH);
    assertThat(handle, notNullValue());
    assertThat(handle.frequency(), equalTo(ResourceWatcherService.Frequency.HIGH));
    assertThat(service.lowMonitor.watchers.size(), is(0));
    assertThat(service.mediumMonitor.watchers.size(), is(0));
    assertThat(service.highMonitor.watchers.size(), is(1));
    handle.stop();
    assertThat(service.highMonitor.watchers.size(), is(0));
    handle.resume();
    assertThat(service.highMonitor.watchers.size(), is(1));
    terminate(threadPool);
}
Also used : TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)48 ThreadPool (org.elasticsearch.threadpool.ThreadPool)21 Before (org.junit.Before)18 Settings (org.elasticsearch.common.settings.Settings)15 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)8 IOException (java.io.IOException)7 TimeValue (org.elasticsearch.common.unit.TimeValue)7 ClusterService (org.elasticsearch.cluster.service.ClusterService)6 AbstractRunnable (org.elasticsearch.common.util.concurrent.AbstractRunnable)6 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)6 TransportSettings (org.elasticsearch.transport.TransportSettings)6 ScheduledFuture (java.util.concurrent.ScheduledFuture)5 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 NetworkService (org.elasticsearch.common.network.NetworkService)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ExecutionException (java.util.concurrent.ExecutionException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3