|
6 | 6 | package org.elasticsearch.xpack.ml.integration;
|
7 | 7 |
|
8 | 8 | import org.elasticsearch.ResourceNotFoundException;
|
| 9 | +import org.elasticsearch.action.ActionFuture; |
9 | 10 | import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
10 | 11 | import org.elasticsearch.action.bulk.BulkResponse;
|
11 | 12 | import org.elasticsearch.action.index.IndexRequest;
|
12 | 13 | import org.elasticsearch.action.support.WriteRequest;
|
13 | 14 | import org.elasticsearch.common.unit.ByteSizeValue;
|
14 | 15 | import org.elasticsearch.index.query.QueryBuilders;
|
15 | 16 | import org.elasticsearch.xpack.core.ml.action.ExplainDataFrameAnalyticsAction;
|
| 17 | +import org.elasticsearch.xpack.core.ml.action.PutDataFrameAnalyticsAction; |
16 | 18 | import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsConfig;
|
17 | 19 | import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsSource;
|
18 | 20 | import org.elasticsearch.xpack.core.ml.dataframe.analyses.BoostedTreeParams;
|
|
22 | 24 | import org.elasticsearch.xpack.core.ml.utils.QueryProvider;
|
23 | 25 |
|
24 | 26 | import java.io.IOException;
|
| 27 | +import java.util.ArrayList; |
| 28 | +import java.util.List; |
25 | 29 |
|
26 | 30 | import static org.hamcrest.Matchers.equalTo;
|
27 | 31 | import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
@@ -127,6 +131,49 @@ public void testTrainingPercentageIsApplied() throws IOException {
|
127 | 131 | lessThanOrEqualTo(allDataUsedForTraining));
|
128 | 132 | }
|
129 | 133 |
|
| 134 | + public void testSimultaneousExplainSameConfig() throws IOException { |
| 135 | + |
| 136 | + final int simultaneousInvocationCount = 10; |
| 137 | + |
| 138 | + String sourceIndex = "test-simultaneous-explain"; |
| 139 | + RegressionIT.indexData(sourceIndex, 100, 0); |
| 140 | + |
| 141 | + DataFrameAnalyticsConfig config = new DataFrameAnalyticsConfig.Builder() |
| 142 | + .setId("dfa-simultaneous-explain-" + sourceIndex) |
| 143 | + .setSource(new DataFrameAnalyticsSource(new String[]{sourceIndex}, |
| 144 | + QueryProvider.fromParsedQuery(QueryBuilders.matchAllQuery()), |
| 145 | + null)) |
| 146 | + .setAnalysis(new Regression(RegressionIT.DEPENDENT_VARIABLE_FIELD, |
| 147 | + BoostedTreeParams.builder().build(), |
| 148 | + null, |
| 149 | + 100.0, |
| 150 | + null, |
| 151 | + null, |
| 152 | + null)) |
| 153 | + .buildForExplain(); |
| 154 | + |
| 155 | + List<ActionFuture<ExplainDataFrameAnalyticsAction.Response>> futures = new ArrayList<>(); |
| 156 | + |
| 157 | + for (int i = 0; i < simultaneousInvocationCount; ++i) { |
| 158 | + futures.add(client().execute(ExplainDataFrameAnalyticsAction.INSTANCE, new PutDataFrameAnalyticsAction.Request(config))); |
| 159 | + } |
| 160 | + |
| 161 | + ExplainDataFrameAnalyticsAction.Response previous = null; |
| 162 | + for (ActionFuture<ExplainDataFrameAnalyticsAction.Response> future : futures) { |
| 163 | + // The main purpose of this test is that actionGet() here will throw an exception |
| 164 | + // if any of the simultaneous calls returns an error due to interaction between |
| 165 | + // the many estimation processes that get run |
| 166 | + ExplainDataFrameAnalyticsAction.Response current = future.actionGet(10000); |
| 167 | + if (previous != null) { |
| 168 | + // A secondary check the test can perform is that the multiple invocations |
| 169 | + // return the same result (but it was failures due to unwanted interactions |
| 170 | + // that caused this test to be written) |
| 171 | + assertEquals(previous, current); |
| 172 | + } |
| 173 | + previous = current; |
| 174 | + } |
| 175 | + } |
| 176 | + |
130 | 177 | @Override
|
131 | 178 | boolean supportsInference() {
|
132 | 179 | return false;
|
|
0 commit comments