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);
}
}
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);
}
}
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());
}
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();
}
}
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();
}
}
Aggregations