[TEST] fix a NPE in verifyThreadNames which may happen if thread finishes during sampling
This commit is contained in:
parent
0d66d3779e
commit
08ca51d7b6
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.threadpool;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.annotations.Repeat;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
|
||||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
|
||||
|
@ -33,29 +31,24 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
|
||||
import org.elasticsearch.test.InternalTestCluster;
|
||||
import org.elasticsearch.test.TestCluster;
|
||||
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
|
||||
import org.elasticsearch.threadpool.ThreadPool.Names;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadInfo;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.test.ElasticsearchIntegrationTest.*;
|
||||
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
|
@ -74,7 +67,10 @@ public class SimpleThreadPoolTests extends ElasticsearchIntegrationTest {
|
|||
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
|
||||
Set<String> preNodeStartThreadNames = Sets.newHashSet();
|
||||
for (long l : threadBean.getAllThreadIds()) {
|
||||
preNodeStartThreadNames.add(threadBean.getThreadInfo(l).getThreadName());
|
||||
ThreadInfo threadInfo = threadBean.getThreadInfo(l);
|
||||
if (threadInfo != null) {
|
||||
preNodeStartThreadNames.add(threadInfo.getThreadName());
|
||||
}
|
||||
}
|
||||
logger.info("pre node threads are {}", preNodeStartThreadNames);
|
||||
String node = internalCluster().startNode();
|
||||
|
@ -100,7 +96,10 @@ public class SimpleThreadPoolTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
Set<String> threadNames = Sets.newHashSet();
|
||||
for (long l : threadBean.getAllThreadIds()) {
|
||||
threadNames.add(threadBean.getThreadInfo(l).getThreadName());
|
||||
ThreadInfo threadInfo = threadBean.getThreadInfo(l);
|
||||
if (threadInfo != null) {
|
||||
threadNames.add(threadInfo.getThreadName());
|
||||
}
|
||||
}
|
||||
logger.info("post node threads are {}", threadNames);
|
||||
threadNames.removeAll(preNodeStartThreadNames);
|
||||
|
|
Loading…
Reference in New Issue