-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fcdc8a
commit 8fa8129
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...org/elasticsearch/xpack/ml/rest/inference/RestStartTrainedModelDeploymentActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.ml.rest.inference; | ||
|
||
import org.apache.lucene.util.SetOnce; | ||
import org.elasticsearch.common.unit.ByteSizeValue; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.test.rest.FakeRestRequest; | ||
import org.elasticsearch.test.rest.RestActionTestCase; | ||
import org.elasticsearch.xpack.core.ml.action.CreateTrainedModelAssignmentAction; | ||
import org.elasticsearch.xpack.core.ml.action.StartTrainedModelDeploymentAction; | ||
import org.elasticsearch.xpack.core.ml.inference.assignment.TrainedModelAssignment; | ||
import org.junit.Before; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.instanceOf; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class RestStartTrainedModelDeploymentActionTests extends RestActionTestCase { | ||
|
||
boolean disableInferenceProcessCache = randomBoolean(); | ||
|
||
@Before | ||
public void setUpAction() { | ||
controller().registerHandler(new RestStartTrainedModelDeploymentAction(disableInferenceProcessCache)); | ||
} | ||
|
||
public void testUsesDefaultTimeout() { | ||
SetOnce<Boolean> executeCalled = new SetOnce<>(); | ||
verifyingClient.setExecuteVerifier(((actionType, actionRequest) -> { | ||
assertThat(actionRequest, instanceOf(StartTrainedModelDeploymentAction.Request.class)); | ||
|
||
var request = (StartTrainedModelDeploymentAction.Request) actionRequest; | ||
if (disableInferenceProcessCache) { | ||
assertThat(request.getCacheSize(), is(ByteSizeValue.ZERO)); | ||
} else { | ||
assertNull(request.getCacheSize()); | ||
} | ||
|
||
executeCalled.set(true); | ||
return createResponse(); | ||
})); | ||
|
||
RestRequest inferenceRequest = new FakeRestRequest.Builder(xContentRegistry()).withMethod(RestRequest.Method.POST) | ||
.withPath("_ml/trained_models/test_id/deployment/_start") | ||
.build(); | ||
dispatchRequest(inferenceRequest); | ||
assertThat(executeCalled.get(), equalTo(true)); | ||
} | ||
|
||
private static CreateTrainedModelAssignmentAction.Response createResponse() { | ||
return new CreateTrainedModelAssignmentAction.Response(mock(TrainedModelAssignment.class)); | ||
} | ||
} |