|
13 | 13 | import org.elasticsearch.common.util.concurrent.ConcurrentCollections; |
14 | 14 | import org.elasticsearch.common.util.concurrent.ConcurrentMapLong; |
15 | 15 | import org.elasticsearch.common.util.concurrent.ThreadContext; |
| 16 | +import org.elasticsearch.common.xcontent.support.XContentMapValues; |
16 | 17 | import org.elasticsearch.test.SecuritySettingsSourceField; |
17 | 18 | import org.elasticsearch.test.rest.ESRestTestCase; |
18 | 19 | import org.elasticsearch.xpack.core.ml.integration.MlRestTestStateCleaner; |
|
22 | 23 | import org.junit.After; |
23 | 24 |
|
24 | 25 | import java.io.IOException; |
| 26 | +import java.util.Collections; |
25 | 27 | import java.util.Locale; |
| 28 | +import java.util.Map; |
26 | 29 | import java.util.concurrent.atomic.AtomicInteger; |
27 | 30 | import java.util.concurrent.atomic.AtomicReference; |
28 | 31 | import java.util.regex.Matcher; |
@@ -111,6 +114,21 @@ public void testGetJobs_GivenMultipleJobs() throws Exception { |
111 | 114 | assertThat(implicitAll, containsString("\"job_id\":\"given-multiple-jobs-job-3\"")); |
112 | 115 | } |
113 | 116 |
|
| 117 | + // tests the _xpack/usage endpoint |
| 118 | + public void testUsage() throws IOException { |
| 119 | + createFarequoteJob("job-1"); |
| 120 | + createFarequoteJob("job-2"); |
| 121 | + Map<String, Object> usage = entityAsMap(client().performRequest(new Request("GET", "_xpack/usage"))); |
| 122 | + assertEquals(2, XContentMapValues.extractValue("ml.jobs._all.count", usage)); |
| 123 | + assertEquals(2, XContentMapValues.extractValue("ml.jobs.closed.count", usage)); |
| 124 | + Response openResponse = client().performRequest(new Request("POST", MachineLearning.BASE_PATH + "anomaly_detectors/job-1/_open")); |
| 125 | + assertEquals(Collections.singletonMap("opened", true), entityAsMap(openResponse)); |
| 126 | + usage = entityAsMap(client().performRequest(new Request("GET", "_xpack/usage"))); |
| 127 | + assertEquals(2, XContentMapValues.extractValue("ml.jobs._all.count", usage)); |
| 128 | + assertEquals(1, XContentMapValues.extractValue("ml.jobs.closed.count", usage)); |
| 129 | + assertEquals(1, XContentMapValues.extractValue("ml.jobs.opened.count", usage)); |
| 130 | + } |
| 131 | + |
114 | 132 | private Response createFarequoteJob(String jobId) throws IOException { |
115 | 133 | Request request = new Request("PUT", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId); |
116 | 134 | request.setJsonEntity( |
|
0 commit comments