Search in sources :

Example 1 with TestThreadPool

use of org.opensearch.threadpool.TestThreadPool in project OpenSearch by opensearch-project.

the class NettyTransportMultiPortTests method testThatNettyCanBindToMultiplePorts.

public void testThatNettyCanBindToMultiplePorts() throws Exception {
    Settings settings = Settings.builder().put("network.host", host).put(TransportSettings.PORT.getKey(), // will not actually bind to this
    22).put("transport.profiles.default.port", 0).put("transport.profiles.client1.port", 0).build();
    ThreadPool threadPool = new TestThreadPool("tst");
    try (TcpTransport transport = startTransport(settings, threadPool)) {
        assertEquals(1, transport.profileBoundAddresses().size());
        assertEquals(1, transport.boundAddress().boundAddresses().length);
    } finally {
        terminate(threadPool);
    }
}
Also used : ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) TcpTransport(org.opensearch.transport.TcpTransport) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Settings(org.opensearch.common.settings.Settings) TransportSettings(org.opensearch.transport.TransportSettings)

Example 2 with TestThreadPool

use of org.opensearch.threadpool.TestThreadPool in project OpenSearch by opensearch-project.

the class NettyTransportMultiPortTests method testThatProfileWithoutPortSettingsFails.

public void testThatProfileWithoutPortSettingsFails() throws Exception {
    Settings settings = Settings.builder().put("network.host", host).put(TransportSettings.PORT.getKey(), 0).put("transport.profiles.client1.whatever", "foo").build();
    ThreadPool threadPool = new TestThreadPool("tst");
    try {
        IllegalStateException ex = expectThrows(IllegalStateException.class, () -> startTransport(settings, threadPool));
        assertEquals("profile [client1] has no port configured", ex.getMessage());
    } finally {
        terminate(threadPool);
    }
}
Also used : ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Settings(org.opensearch.common.settings.Settings) TransportSettings(org.opensearch.transport.TransportSettings)

Example 3 with TestThreadPool

use of org.opensearch.threadpool.TestThreadPool in project OpenSearch by opensearch-project.

the class Netty4HttpServerPipeliningTests method setup.

@Before
public void setup() throws Exception {
    networkService = new NetworkService(Collections.emptyList());
    threadPool = new TestThreadPool("test");
    bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
}
Also used : MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) NetworkService(org.opensearch.common.network.NetworkService) MockBigArrays(org.opensearch.common.util.MockBigArrays) TestThreadPool(org.opensearch.threadpool.TestThreadPool) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 4 with TestThreadPool

use of org.opensearch.threadpool.TestThreadPool in project OpenSearch by opensearch-project.

the class IndexFieldDataServiceTests method doTestRequireDocValues.

private void doTestRequireDocValues(MappedFieldType ft) {
    ThreadPool threadPool = new TestThreadPool("random_threadpool_name");
    try {
        IndicesFieldDataCache cache = new IndicesFieldDataCache(Settings.EMPTY, null);
        IndexFieldDataService ifds = new IndexFieldDataService(IndexSettingsModule.newIndexSettings("test", Settings.EMPTY), cache, null, null);
        if (ft.hasDocValues()) {
            // no exception
            ifds.getForField(ft, "test", () -> {
                throw new UnsupportedOperationException();
            });
        } else {
            IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> ifds.getForField(ft, "test", () -> {
                throw new UnsupportedOperationException();
            }));
            assertThat(e.getMessage(), containsString("doc values"));
        }
    } finally {
        threadPool.shutdown();
    }
}
Also used : IndicesFieldDataCache(org.opensearch.indices.fielddata.cache.IndicesFieldDataCache) ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool)

Example 5 with TestThreadPool

use of org.opensearch.threadpool.TestThreadPool in project OpenSearch by opensearch-project.

the class WorkerBulkByScrollTaskStateTests method testDelayNeverNegative.

public void testDelayNeverNegative() throws IOException {
    // Thread pool that returns a ScheduledFuture that claims to have a negative delay
    ThreadPool threadPool = new TestThreadPool("test") {

        public ScheduledCancellable schedule(Runnable command, TimeValue delay, String name) {
            return new ScheduledCancellable() {

                @Override
                public long getDelay(TimeUnit unit) {
                    return -1;
                }

                @Override
                public int compareTo(Delayed o) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public boolean cancel() {
                    throw new UnsupportedOperationException();
                }

                @Override
                public boolean isCancelled() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
    try {
        // Have the task use the thread pool to delay a task that does nothing
        workerState.delayPrepareBulkRequest(threadPool, 0, 1, new AbstractRunnable() {

            @Override
            protected void doRun() throws Exception {
            }

            @Override
            public void onFailure(Exception e) {
                throw new UnsupportedOperationException();
            }
        });
        // Even though the future returns a negative delay we just return 0 because the time is up.
        assertEquals(timeValueSeconds(0), task.getStatus().getThrottledUntil());
    } finally {
        threadPool.shutdown();
    }
}
Also used : AbstractRunnable(org.opensearch.common.util.concurrent.AbstractRunnable) Delayed(java.util.concurrent.Delayed) AbstractRunnable(org.opensearch.common.util.concurrent.AbstractRunnable) ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) TimeUnit(java.util.concurrent.TimeUnit) TestThreadPool(org.opensearch.threadpool.TestThreadPool) TimeValue(org.opensearch.common.unit.TimeValue) IOException(java.io.IOException)

Aggregations

TestThreadPool (org.opensearch.threadpool.TestThreadPool)94 ThreadPool (org.opensearch.threadpool.ThreadPool)37 Before (org.junit.Before)34 Settings (org.opensearch.common.settings.Settings)32 ClusterService (org.opensearch.cluster.service.ClusterService)19 ClusterSettings (org.opensearch.common.settings.ClusterSettings)17 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)16 ClusterState (org.opensearch.cluster.ClusterState)14 NoneCircuitBreakerService (org.opensearch.indices.breaker.NoneCircuitBreakerService)13 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)13 TimeValue (org.opensearch.common.unit.TimeValue)12 Index (org.opensearch.index.Index)12 ArrayList (java.util.ArrayList)11 ShardId (org.opensearch.index.shard.ShardId)11 TransportService (org.opensearch.transport.TransportService)11 IOException (java.io.IOException)10 Collections (java.util.Collections)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 TimeUnit (java.util.concurrent.TimeUnit)10 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)9