|
@@ -16,6 +16,10 @@ import org.elasticsearch.health.node.DiskHealthInfo;
|
|
|
import org.elasticsearch.health.node.FetchHealthInfoCacheAction;
|
|
|
import org.elasticsearch.health.node.HealthInfo;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
+import org.elasticsearch.threadpool.TestThreadPool;
|
|
|
+import org.elasticsearch.threadpool.ThreadPool;
|
|
|
+import org.junit.After;
|
|
|
+import org.junit.Before;
|
|
|
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
@@ -38,6 +42,19 @@ import static org.mockito.Mockito.mock;
|
|
|
|
|
|
public class HealthServiceTests extends ESTestCase {
|
|
|
|
|
|
+ private ThreadPool threadPool;
|
|
|
+
|
|
|
+ @Before
|
|
|
+ public void setupThreadpool() {
|
|
|
+ threadPool = new TestThreadPool(HealthServiceTests.class.getSimpleName());
|
|
|
+ }
|
|
|
+
|
|
|
+ @After
|
|
|
+ public void tearDown() throws Exception {
|
|
|
+ super.tearDown();
|
|
|
+ threadPool.shutdownNow();
|
|
|
+ }
|
|
|
+
|
|
|
public void testShouldReturnGroupedIndicators() throws Exception {
|
|
|
|
|
|
var networkLatency = new HealthIndicatorResult("network_latency", GREEN, null, null, null, null);
|
|
@@ -50,7 +67,8 @@ public class HealthServiceTests extends ESTestCase {
|
|
|
createMockHealthIndicatorService(networkLatency),
|
|
|
createMockHealthIndicatorService(slowTasks),
|
|
|
createMockHealthIndicatorService(shardsAvailable)
|
|
|
- )
|
|
|
+ ),
|
|
|
+ threadPool
|
|
|
);
|
|
|
|
|
|
NodeClient client = getTestClient(HealthInfo.EMPTY_HEALTH_INFO);
|
|
@@ -94,30 +112,6 @@ public class HealthServiceTests extends ESTestCase {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- public void testDuplicateIndicatorNames() throws Exception {
|
|
|
- // Same indicator name, should throw exception:
|
|
|
- var networkLatency = new HealthIndicatorResult(
|
|
|
- "network_latency",
|
|
|
- GREEN,
|
|
|
- null,
|
|
|
- null,
|
|
|
- Collections.emptyList(),
|
|
|
- Collections.emptyList()
|
|
|
- );
|
|
|
- var slowTasks = new HealthIndicatorResult("network_latency", YELLOW, null, null, Collections.emptyList(), Collections.emptyList());
|
|
|
- var service = new HealthService(
|
|
|
- Collections.emptyList(),
|
|
|
- List.of(
|
|
|
- createMockHealthIndicatorService(networkLatency),
|
|
|
- createMockHealthIndicatorService(slowTasks),
|
|
|
- createMockHealthIndicatorService(networkLatency)
|
|
|
- )
|
|
|
- );
|
|
|
- NodeClient client = getTestClient(HealthInfo.EMPTY_HEALTH_INFO);
|
|
|
- // This is testing an assertion, so we expect it to blow up in place rather than calling onFailure:
|
|
|
- assertGetHealthThrowsException(service, client, null, true, AssertionError.class, null, false);
|
|
|
- }
|
|
|
-
|
|
|
public void testMissingIndicator() throws Exception {
|
|
|
var networkLatency = new HealthIndicatorResult("network_latency", GREEN, null, null, null, null);
|
|
|
var slowTasks = new HealthIndicatorResult("slow_task_assignment", YELLOW, null, null, null, null);
|
|
@@ -129,7 +123,8 @@ public class HealthServiceTests extends ESTestCase {
|
|
|
createMockHealthIndicatorService(networkLatency),
|
|
|
createMockHealthIndicatorService(slowTasks),
|
|
|
createMockHealthIndicatorService(shardsAvailable)
|
|
|
- )
|
|
|
+ ),
|
|
|
+ threadPool
|
|
|
);
|
|
|
NodeClient client = getTestClient(HealthInfo.EMPTY_HEALTH_INFO);
|
|
|
assertGetHealthThrowsException(
|
|
@@ -216,7 +211,8 @@ public class HealthServiceTests extends ESTestCase {
|
|
|
createMockHealthIndicatorService(networkLatency),
|
|
|
createMockHealthIndicatorService(slowTasks),
|
|
|
createMockHealthIndicatorService(shardsAvailable)
|
|
|
- )
|
|
|
+ ),
|
|
|
+ threadPool
|
|
|
);
|
|
|
NodeClient client = getTestClient(HealthInfo.EMPTY_HEALTH_INFO);
|
|
|
|
|
@@ -255,7 +251,8 @@ public class HealthServiceTests extends ESTestCase {
|
|
|
createMockHealthIndicatorService(networkLatency, healthInfo),
|
|
|
createMockHealthIndicatorService(slowTasks, healthInfo),
|
|
|
createMockHealthIndicatorService(shardsAvailable, healthInfo)
|
|
|
- )
|
|
|
+ ),
|
|
|
+ threadPool
|
|
|
);
|
|
|
NodeClient client = getTestClient(healthInfo);
|
|
|
|
|
@@ -283,7 +280,8 @@ public class HealthServiceTests extends ESTestCase {
|
|
|
createMockHealthIndicatorService(networkLatency),
|
|
|
createMockHealthIndicatorService(slowTasks),
|
|
|
createMockHealthIndicatorService(shardsAvailable)
|
|
|
- )
|
|
|
+ ),
|
|
|
+ threadPool
|
|
|
);
|
|
|
NodeClient client = getTestClient(HealthInfo.EMPTY_HEALTH_INFO);
|
|
|
{
|