use of org.kie.kogito.explainability.api.CounterfactualExplainabilityResult in project kogito-apps by kiegroup.
the class CounterfactualExplainabilityResultsManagerDuplicatesTest method testPurgeWhenResultSetSizeIsGreaterThanMinimum_WithDuplicateInputs.
@Test
public void testPurgeWhenResultSetSizeIsGreaterThanMinimum_WithDuplicateInputs() {
CounterfactualExplainabilityResult result0 = makeResult(0, Collections.emptyList(), Collections.emptyList());
CounterfactualExplainabilityResult result1 = makeResult(1, Collections.emptyList(), Collections.emptyList());
CounterfactualExplainabilityResult result2 = makeResult(2, List.of(makeCounterfactualInput("a")), Collections.emptyList());
CounterfactualExplainabilityResult result3 = makeResult(3, List.of(makeCounterfactualInput("a")), Collections.emptyList());
when(query.execute()).thenReturn(List.of(result0, result1, result2, result3));
manager.purge(COUNTERFACTUAL_ID, storage);
verify(storage).remove(anyString());
verify(storage).remove(result3.getSolutionId());
}
use of org.kie.kogito.explainability.api.CounterfactualExplainabilityResult in project kogito-apps by kiegroup.
the class CounterfactualExplainabilityResultsManagerDuplicatesTest method testPurgeWhenResultSetSizeIsGreaterThanMinimum_WithDuplicateInputs_FinalPenultimate.
@Test
public void testPurgeWhenResultSetSizeIsGreaterThanMinimum_WithDuplicateInputs_FinalPenultimate() {
CounterfactualExplainabilityResult result0 = makeResult(0, Collections.emptyList(), Collections.emptyList());
CounterfactualExplainabilityResult result1 = makeResult(1, Collections.emptyList(), Collections.emptyList());
CounterfactualExplainabilityResult result2 = makeResult(2, CounterfactualExplainabilityResult.Stage.FINAL, List.of(makeCounterfactualInput("a")), Collections.emptyList());
CounterfactualExplainabilityResult result3 = makeResult(3, List.of(makeCounterfactualInput("a")), Collections.emptyList());
when(query.execute()).thenReturn(List.of(result0, result1, result2, result3));
manager.purge(COUNTERFACTUAL_ID, storage);
verify(storage).remove(anyString());
verify(storage).remove(result3.getSolutionId());
}
use of org.kie.kogito.explainability.api.CounterfactualExplainabilityResult in project kogito-apps by kiegroup.
the class ExplainerServiceHandlerRegistryTest method testCounterfactual_getExplainabilityResultByIdWithFinalResult.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testCounterfactual_getExplainabilityResultByIdWithFinalResult() {
Query query = mock(Query.class);
CounterfactualExplainabilityResult result = mock(CounterfactualExplainabilityResult.class);
when(result.getStage()).thenReturn(CounterfactualExplainabilityResult.Stage.FINAL);
when(storageCounterfactual.containsKey(eq(EXECUTION_ID))).thenReturn(true);
when(storageCounterfactual.query()).thenReturn(query);
when(query.filter(any())).thenReturn(query);
when(query.execute()).thenReturn(List.of(result));
CounterfactualExplainabilityResult actual = registry.getExplainabilityResultById(EXECUTION_ID, CounterfactualExplainabilityResult.class);
verify(counterfactualExplainerServiceHandler).getExplainabilityResultById(eq(EXECUTION_ID));
assertEquals(result, actual);
}
use of org.kie.kogito.explainability.api.CounterfactualExplainabilityResult in project kogito-apps by kiegroup.
the class ExplainerServiceHandlerRegistryTest method testCounterfactual_storeExplainabilityResult.
@Test
public void testCounterfactual_storeExplainabilityResult() {
when(storageCounterfactual.containsKey(eq(EXECUTION_ID))).thenReturn(false);
CounterfactualExplainabilityResult result = mock(CounterfactualExplainabilityResult.class);
registry.storeExplainabilityResult(EXECUTION_ID, result);
verify(counterfactualExplainerServiceHandler).storeExplainabilityResult(eq(EXECUTION_ID), eq(result));
}
use of org.kie.kogito.explainability.api.CounterfactualExplainabilityResult in project kogito-apps by kiegroup.
the class ExplanationServiceImplTest method testCounterfactualsxplainAsyncFailed.
@Test
@SuppressWarnings("unchecked")
void testCounterfactualsxplainAsyncFailed() {
String errorMessage = "Something bad happened";
RuntimeException exception = new RuntimeException(errorMessage);
when(instance.stream()).thenReturn(Stream.of(cfExplainerServiceHandlerMock));
when(cfExplainerMock.explainAsync(any(Prediction.class), eq(predictionProviderMock), any(Consumer.class))).thenThrow(exception);
BaseExplainabilityResult result = assertDoesNotThrow(() -> explanationService.explainAsync(COUNTERFACTUAL_REQUEST, callbackMock).toCompletableFuture().get(Config.INSTANCE.getAsyncTimeout(), Config.INSTANCE.getAsyncTimeUnit()));
assertNotNull(result);
assertTrue(result instanceof CounterfactualExplainabilityResult);
CounterfactualExplainabilityResult exceptionResult = (CounterfactualExplainabilityResult) result;
assertEquals(EXECUTION_ID, exceptionResult.getExecutionId());
assertSame(ExplainabilityStatus.FAILED, exceptionResult.getStatus());
assertEquals(errorMessage, exceptionResult.getStatusDetails());
}
Aggregations