-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17017 from jasontedor/generic-thread-pool
Actually bound the generic thread pool
- Loading branch information
Showing
9 changed files
with
492 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 108 additions & 72 deletions
180
core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
core/src/test/java/org/elasticsearch/threadpool/ESThreadPoolTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.threadpool; | ||
|
||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public abstract class ESThreadPoolTestCase extends ESTestCase { | ||
|
||
protected final ThreadPool.Info info(final ThreadPool threadPool, final String name) { | ||
for (final ThreadPool.Info info : threadPool.info()) { | ||
if (info.getName().equals(name)) { | ||
return info; | ||
} | ||
} | ||
throw new IllegalArgumentException(name); | ||
} | ||
|
||
protected final ThreadPoolStats.Stats stats(final ThreadPool threadPool, final String name) { | ||
for (final ThreadPoolStats.Stats stats : threadPool.stats()) { | ||
if (name.equals(stats.getName())) { | ||
return stats; | ||
} | ||
} | ||
throw new IllegalArgumentException(name); | ||
} | ||
|
||
protected final void terminateThreadPoolIfNeeded(final ThreadPool threadPool) throws InterruptedException { | ||
if (threadPool != null) { | ||
terminate(threadPool); | ||
} | ||
} | ||
|
||
static String randomThreadPool(final ThreadPool.ThreadPoolType type) { | ||
return randomFrom( | ||
ThreadPool.THREAD_POOL_TYPES | ||
.entrySet().stream() | ||
.filter(t -> t.getValue().equals(type)) | ||
.map(Map.Entry::getKey) | ||
.collect(Collectors.toList())); | ||
} | ||
|
||
} |
Oops, something went wrong.