|
5 | 5 | */ |
6 | 6 | package org.elasticsearch.smoketest; |
7 | 7 |
|
| 8 | +import io.netty.util.ThreadDeathWatcher; |
| 9 | +import io.netty.util.concurrent.GlobalEventExecutor; |
8 | 10 | import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; |
9 | 11 | import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse; |
10 | 12 | import org.elasticsearch.common.network.NetworkAddress; |
|
19 | 21 | import org.elasticsearch.xpack.core.security.SecurityField; |
20 | 22 | import org.junit.After; |
21 | 23 | import org.junit.Before; |
| 24 | +import org.junit.ClassRule; |
| 25 | +import org.junit.rules.ExternalResource; |
22 | 26 |
|
23 | 27 | import java.net.InetSocketAddress; |
24 | 28 | import java.util.Collection; |
25 | 29 | import java.util.Collections; |
26 | 30 | import java.util.List; |
27 | 31 | import java.util.Optional; |
| 32 | +import java.util.concurrent.TimeUnit; |
28 | 33 |
|
29 | 34 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
30 | 35 | import static org.hamcrest.Matchers.equalTo; |
|
42 | 47 | * indexed in the cluster. |
43 | 48 | */ |
44 | 49 | public class SmokeTestMonitoringWithSecurityIT extends ESIntegTestCase { |
| 50 | + |
| 51 | + /** |
| 52 | + * A JUnit class level rule that runs after the AfterClass method in {@link ESIntegTestCase}, |
| 53 | + * which stops the cluster. After the cluster is stopped, there are a few netty threads that |
| 54 | + * can linger, so we wait for them to finish otherwise these lingering threads can intermittently |
| 55 | + * trigger the thread leak detector |
| 56 | + */ |
| 57 | + @ClassRule |
| 58 | + public static final ExternalResource STOP_NETTY_RESOURCE = new ExternalResource() { |
| 59 | + @Override |
| 60 | + protected void after() { |
| 61 | + try { |
| 62 | + GlobalEventExecutor.INSTANCE.awaitInactivity(5, TimeUnit.SECONDS); |
| 63 | + } catch (InterruptedException e) { |
| 64 | + Thread.currentThread().interrupt(); |
| 65 | + } catch (IllegalStateException e) { |
| 66 | + if (e.getMessage().equals("thread was not started") == false) { |
| 67 | + throw e; |
| 68 | + } |
| 69 | + // ignore since the thread was never started |
| 70 | + } |
| 71 | + |
| 72 | + try { |
| 73 | + ThreadDeathWatcher.awaitInactivity(5, TimeUnit.SECONDS); |
| 74 | + } catch (InterruptedException e) { |
| 75 | + Thread.currentThread().interrupt(); |
| 76 | + } |
| 77 | + } |
| 78 | + }; |
| 79 | + |
45 | 80 | private static final String USER = "test_user"; |
46 | 81 | private static final String PASS = "x-pack-test-password"; |
47 | 82 | private static final String MONITORING_PATTERN = ".monitoring-*"; |
|
0 commit comments