Skip to content

Commit

Permalink
[Backport 2.17] Fix and Refactor Test with Builder Pattern for Issue …
Browse files Browse the repository at this point in the history
…#2825 (#861)

Fix and Refactor Test with Builder Pattern for Issue #2825 (#859)

* Fix: Use @builder for constructor in test



* Fix: change parameter for different test case



---------



(cherry picked from commit 1b055e8)

Signed-off-by: Junwei Dai <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Junwei Dai <[email protected]>
  • Loading branch information
3 people authored Sep 7, 2024
1 parent c850571 commit 68e8973
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,7 @@ public void testDeployModel() throws ExecutionException, InterruptedException, I
// Stub getTask for success case
doAnswer(invocation -> {
ActionListener<MLTask> actionListener = invocation.getArgument(1);
MLTask output = new MLTask(
taskId,
modelId,
null,
null,
MLTaskState.COMPLETED,
null,
null,
null,
null,
null,
null,
null,
null,
false
);
MLTask output = MLTask.builder().taskId(taskId).modelId(modelId).state(MLTaskState.COMPLETED).async(false).build();
actionListener.onResponse(output);
return null;
}).when(machineLearningNodeClient).getTask(any(), any());
Expand Down Expand Up @@ -215,22 +200,7 @@ public void testDeployModelTaskFailure() throws IOException, InterruptedExceptio
// Stub getTask for success case
doAnswer(invocation -> {
ActionListener<MLTask> actionListener = invocation.getArgument(1);
MLTask output = new MLTask(
taskId,
modelId,
null,
null,
MLTaskState.FAILED,
null,
null,
null,
null,
null,
null,
"error",
null,
false
);
MLTask output = MLTask.builder().taskId(taskId).modelId(modelId).state(MLTaskState.FAILED).async(false).error("error").build();
actionListener.onResponse(output);
return null;
}).when(machineLearningNodeClient).getTask(any(), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,7 @@ public void testRegisterLocalCustomModelSuccess() throws Exception {
// Stub getTask for success case
doAnswer(invocation -> {
ActionListener<MLTask> actionListener = invocation.getArgument(1);
MLTask output = new MLTask(
taskId,
modelId,
null,
null,
MLTaskState.COMPLETED,
null,
null,
null,
null,
null,
null,
null,
null,
false
);
MLTask output = MLTask.builder().taskId(taskId).modelId(modelId).state(MLTaskState.COMPLETED).async(false).build();
actionListener.onResponse(output);
return null;
}).when(machineLearningNodeClient).getTask(any(), any());
Expand Down Expand Up @@ -239,22 +224,7 @@ public void testRegisterLocalCustomModelDeployStateUpdateFail() throws Exception
// Stub getTask for success case
doAnswer(invocation -> {
ActionListener<MLTask> actionListener = invocation.getArgument(1);
MLTask output = new MLTask(
taskId,
modelId,
null,
null,
MLTaskState.COMPLETED,
null,
null,
null,
null,
null,
null,
null,
null,
false
);
MLTask output = MLTask.builder().taskId(taskId).modelId(modelId).state(MLTaskState.COMPLETED).async(false).build();
actionListener.onResponse(output);
return null;
}).when(machineLearningNodeClient).getTask(any(), any());
Expand Down Expand Up @@ -342,22 +312,13 @@ public void testRegisterLocalCustomModelTaskFailure() {
// Stub get ml task for failure case
doAnswer(invocation -> {
ActionListener<MLTask> actionListener = invocation.getArgument(1);
MLTask output = new MLTask(
taskId,
modelId,
null,
null,
MLTaskState.FAILED,
null,
null,
null,
null,
null,
null,
testErrorMessage,
null,
false
);
MLTask output = MLTask.builder()
.taskId(taskId)
.modelId(modelId)
.state(MLTaskState.FAILED)
.error(testErrorMessage)
.async(false)
.build();
actionListener.onResponse(output);
return null;
}).when(machineLearningNodeClient).getTask(any(), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,7 @@ public void testRegisterLocalPretrainedModelSuccess() throws Exception {
// Stub getTask for success case
doAnswer(invocation -> {
ActionListener<MLTask> actionListener = invocation.getArgument(1);
MLTask output = new MLTask(
taskId,
modelId,
null,
null,
MLTaskState.COMPLETED,
null,
null,
null,
null,
null,
null,
null,
null,
false
);
MLTask output = MLTask.builder().taskId(taskId).modelId(modelId).state(MLTaskState.COMPLETED).async(false).build();
actionListener.onResponse(output);
return null;
}).when(machineLearningNodeClient).getTask(any(), any());
Expand Down Expand Up @@ -247,22 +232,13 @@ public void testRegisterLocalPretrainedModelTaskFailure() {
// Stub get ml task for failure case
doAnswer(invocation -> {
ActionListener<MLTask> actionListener = invocation.getArgument(1);
MLTask output = new MLTask(
taskId,
modelId,
null,
null,
MLTaskState.FAILED,
null,
null,
null,
null,
null,
null,
testErrorMessage,
null,
false
);
MLTask output = MLTask.builder()
.taskId(taskId)
.modelId(modelId)
.state(MLTaskState.FAILED)
.error(testErrorMessage)
.async(false)
.build();
actionListener.onResponse(output);
return null;
}).when(machineLearningNodeClient).getTask(any(), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,7 @@ public void testRegisterLocalSparseEncodingModelSuccess() throws Exception {
// Stub getTask for success case
doAnswer(invocation -> {
ActionListener<MLTask> actionListener = invocation.getArgument(1);
MLTask output = new MLTask(
taskId,
modelId,
null,
null,
MLTaskState.COMPLETED,
null,
null,
null,
null,
null,
null,
null,
null,
false
);
MLTask output = MLTask.builder().taskId(taskId).modelId(modelId).state(MLTaskState.COMPLETED).async(false).build();
actionListener.onResponse(output);
return null;
}).when(machineLearningNodeClient).getTask(any(), any());
Expand Down Expand Up @@ -252,22 +237,13 @@ public void testRegisterLocalSparseEncodingModelTaskFailure() {
// Stub get ml task for failure case
doAnswer(invocation -> {
ActionListener<MLTask> actionListener = invocation.getArgument(1);
MLTask output = new MLTask(
taskId,
modelId,
null,
null,
MLTaskState.FAILED,
null,
null,
null,
null,
null,
null,
testErrorMessage,
null,
false
);
MLTask output = MLTask.builder()
.taskId(taskId)
.modelId(modelId)
.state(MLTaskState.FAILED)
.error(testErrorMessage)
.async(false)
.build();
actionListener.onResponse(output);
return null;
}).when(machineLearningNodeClient).getTask(any(), any());
Expand Down

0 comments on commit 68e8973

Please sign in to comment.