Skip to content

Commit

Permalink
Added another test for name check
Browse files Browse the repository at this point in the history
Signed-off-by: Owais Kazi <[email protected]>
  • Loading branch information
owaiskazi19 committed Oct 27, 2023
1 parent 864d0d7 commit a2eb324
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,25 @@ public void onFailure(Exception e) {
registerModelGroupFuture.completeExceptionally(
new FlowFrameworkException("Model group name is not provided", RestStatus.BAD_REQUEST)
);
}
} else {
MLRegisterModelGroupInputBuilder builder = MLRegisterModelGroupInput.builder();
builder.name(modelGroupName);
if (description != null) {
builder.description(description);
}
if (backendRoles != null && backendRoles.size() > 0) {
builder.backendRoles(backendRoles);
}
if (modelAccessMode != null) {
builder.modelAccessMode(modelAccessMode);
}
if (isAddAllBackendRoles != null) {
builder.isAddAllBackendRoles(isAddAllBackendRoles);
}
MLRegisterModelGroupInput mlInput = builder.build();

MLRegisterModelGroupInputBuilder builder = MLRegisterModelGroupInput.builder();
builder.name(modelGroupName);
if (description != null) {
builder.description(description);
mlClient.registerModelGroup(mlInput, actionListener);
}
if (backendRoles != null && backendRoles.size() > 0) {
builder.backendRoles(backendRoles);
}
if (modelAccessMode != null) {
builder.modelAccessMode(modelAccessMode);
}
if (isAddAllBackendRoles != null) {
builder.isAddAllBackendRoles(isAddAllBackendRoles);
}
MLRegisterModelGroupInput mlInput = builder.build();

mlClient.registerModelGroup(mlInput, actionListener);

return registerModelGroupFuture;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

public class ModelGroupStepTests extends OpenSearchTestCase {
private WorkflowData inputData = WorkflowData.EMPTY;
private WorkflowData inputDataWithNoName = WorkflowData.EMPTY;

@Mock
MachineLearningNodeClient machineLearningNodeClient;
Expand All @@ -54,6 +55,7 @@ public void setUp() throws Exception {
Map.entry("add_all_backend_roles", false)
)
);

}

public void testRegisterModelGroup() throws ExecutionException, InterruptedException, IOException {
Expand Down Expand Up @@ -103,4 +105,15 @@ public void testRegisterModelGroupFailure() throws ExecutionException, Interrupt

}

public void testRegisterModelGroupWithNoName() throws IOException {
ModelGroupStep modelGroupStep = new ModelGroupStep(machineLearningNodeClient);

CompletableFuture<WorkflowData> future = modelGroupStep.execute(List.of(inputDataWithNoName));

assertTrue(future.isCompletedExceptionally());
ExecutionException ex = assertThrows(ExecutionException.class, () -> future.get().getContent());
assertTrue(ex.getCause() instanceof FlowFrameworkException);
assertEquals("Model group name is not provided", ex.getCause().getMessage());
}

}

0 comments on commit a2eb324

Please sign in to comment.