Skip to content

Commit

Permalink
Adding failure tests
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Palis <[email protected]>
  • Loading branch information
joshpalis committed Sep 22, 2023
1 parent be67209 commit ff889ed
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,48 @@ public void testCreateIngestPipelineStep() throws InterruptedException, Executio
assertEquals(outpuData.getContent(), future.get().getContent());
}

public void testCreateIngestPipelineStepFailure() {

CreateIngestPipelineStep createIngestPipelineStep = new CreateIngestPipelineStep(client);

ArgumentCaptor<ActionListener> actionListenerCaptor = ArgumentCaptor.forClass(ActionListener.class);
CompletableFuture<WorkflowData> future = createIngestPipelineStep.execute(List.of(inputData));

assertFalse(future.isDone());

// Mock put pipeline request execution and return false
verify(clusterAdminClient, times(1)).putPipeline(any(PutPipelineRequest.class), actionListenerCaptor.capture());
actionListenerCaptor.getValue().onFailure(new Exception());

assertTrue(future.isDone());
assertThrows(Exception.class, () -> future.get());
}

public void testMissingData() {
CreateIngestPipelineStep createIngestPipelineStep = new CreateIngestPipelineStep(client);

// Data with missing input and output fields
WorkflowData incorrectData = new WorkflowData() {

@Override
public Map<String, Object> getContent() {
return Map.of("id", "pipelineId", "description", "some description", "type", "text_embedding", "model_id", "model_id");
}

@Override
public Map<String, String> getParams() {
return Map.of();
}
};

CompletableFuture<WorkflowData> future = createIngestPipelineStep.execute(List.of(incorrectData));
assertTrue(future.isDone());

try {
future.get();
} catch (Exception e) {
assertTrue(e.getMessage().contains("Failed to create ingest pipeline, required inputs not found"));
}
}

}

0 comments on commit ff889ed

Please sign in to comment.