|
37 | 37 | import org.elasticsearch.inference.ModelConfigurations;
|
38 | 38 | import org.elasticsearch.inference.SimilarityMeasure;
|
39 | 39 | import org.elasticsearch.inference.TaskType;
|
| 40 | +import org.elasticsearch.rest.RestStatus; |
40 | 41 | import org.elasticsearch.test.ESTestCase;
|
41 | 42 | import org.elasticsearch.threadpool.ThreadPool;
|
42 | 43 | import org.elasticsearch.xcontent.ParseField;
|
|
48 | 49 | import org.elasticsearch.xpack.core.inference.results.InferenceChunkedSparseEmbeddingResults;
|
49 | 50 | import org.elasticsearch.xpack.core.inference.results.InferenceChunkedTextEmbeddingFloatResults;
|
50 | 51 | import org.elasticsearch.xpack.core.ml.MachineLearningField;
|
| 52 | +import org.elasticsearch.xpack.core.ml.action.CreateTrainedModelAssignmentAction; |
51 | 53 | import org.elasticsearch.xpack.core.ml.action.GetDeploymentStatsAction;
|
52 | 54 | import org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction;
|
53 | 55 | import org.elasticsearch.xpack.core.ml.action.InferModelAction;
|
54 | 56 | import org.elasticsearch.xpack.core.ml.action.InferTrainedModelDeploymentAction;
|
55 | 57 | import org.elasticsearch.xpack.core.ml.action.PutTrainedModelAction;
|
| 58 | +import org.elasticsearch.xpack.core.ml.action.StartTrainedModelDeploymentAction; |
56 | 59 | import org.elasticsearch.xpack.core.ml.inference.TrainedModelConfig;
|
57 | 60 | import org.elasticsearch.xpack.core.ml.inference.TrainedModelPrefixStrings;
|
| 61 | +import org.elasticsearch.xpack.core.ml.inference.assignment.AdaptiveAllocationsSettings; |
58 | 62 | import org.elasticsearch.xpack.core.ml.inference.assignment.AssignmentStats;
|
59 | 63 | import org.elasticsearch.xpack.core.ml.inference.results.ErrorInferenceResults;
|
60 | 64 | import org.elasticsearch.xpack.core.ml.inference.results.MlTextEmbeddingResults;
|
@@ -1792,6 +1796,49 @@ public void testUpdateWithMlEnabled() throws IOException, InterruptedException {
|
1792 | 1796 | }
|
1793 | 1797 | }
|
1794 | 1798 |
|
| 1799 | + public void testStart_OnFailure_WhenTimeoutOccurs() throws IOException { |
| 1800 | + var model = new ElserInternalModel( |
| 1801 | + "inference_id", |
| 1802 | + TaskType.SPARSE_EMBEDDING, |
| 1803 | + "elasticsearch", |
| 1804 | + new ElserInternalServiceSettings( |
| 1805 | + new ElasticsearchInternalServiceSettings(1, 1, "id", new AdaptiveAllocationsSettings(false, 0, 0), null) |
| 1806 | + ), |
| 1807 | + new ElserMlNodeTaskSettings(), |
| 1808 | + null |
| 1809 | + ); |
| 1810 | + |
| 1811 | + var client = mock(Client.class); |
| 1812 | + when(client.threadPool()).thenReturn(threadPool); |
| 1813 | + |
| 1814 | + doAnswer(invocationOnMock -> { |
| 1815 | + ActionListener<GetTrainedModelsAction.Response> listener = invocationOnMock.getArgument(2); |
| 1816 | + var builder = GetTrainedModelsAction.Response.builder(); |
| 1817 | + builder.setModels(List.of(mock(TrainedModelConfig.class))); |
| 1818 | + builder.setTotalCount(1); |
| 1819 | + |
| 1820 | + listener.onResponse(builder.build()); |
| 1821 | + return Void.TYPE; |
| 1822 | + }).when(client).execute(eq(GetTrainedModelsAction.INSTANCE), any(), any()); |
| 1823 | + |
| 1824 | + doAnswer(invocationOnMock -> { |
| 1825 | + ActionListener<CreateTrainedModelAssignmentAction.Response> listener = invocationOnMock.getArgument(2); |
| 1826 | + listener.onFailure(new ElasticsearchStatusException("failed", RestStatus.GATEWAY_TIMEOUT)); |
| 1827 | + return Void.TYPE; |
| 1828 | + }).when(client).execute(eq(StartTrainedModelDeploymentAction.INSTANCE), any(), any()); |
| 1829 | + |
| 1830 | + try (var service = createService(client)) { |
| 1831 | + var actionListener = new PlainActionFuture<Boolean>(); |
| 1832 | + service.start(model, TimeValue.timeValueSeconds(30), actionListener); |
| 1833 | + var exception = expectThrows( |
| 1834 | + ElasticsearchStatusException.class, |
| 1835 | + () -> actionListener.actionGet(TimeValue.timeValueSeconds(30)) |
| 1836 | + ); |
| 1837 | + |
| 1838 | + assertThat(exception.getMessage(), is("failed")); |
| 1839 | + } |
| 1840 | + } |
| 1841 | + |
1795 | 1842 | private ElasticsearchInternalService createService(Client client) {
|
1796 | 1843 | var cs = mock(ClusterService.class);
|
1797 | 1844 | var cSettings = new ClusterSettings(Settings.EMPTY, Set.of(MachineLearningField.MAX_LAZY_ML_NODES));
|
|
0 commit comments