Search in sources :

Example 1 with StateError

use of de.prob.animator.domainobjects.StateError in project prob2 by bendisposto.

the class RulesMachineRun method start.

public void start() {
    logger.info("Starting rules machine run: {}", this.runnerFile.getAbsolutePath());
    stopWatch.start(Timer.PARSING);
    boolean hasParseErrors = parseAndTranslateRulesProject();
    logger.info("Time to parse rules project: {} ms", stopWatch.stop(Timer.PARSING));
    if (hasParseErrors) {
        logger.error("RULES_MACHINE has errors!");
        return;
    }
    this.executeRun = rulesMachineRunner.createRulesMachineExecuteRun(this.rulesProject, runnerFile, this.proBCorePreferences, continueAfterErrors, this.getStateSpace());
    try {
        stopWatch.start(Timer.EXECUTE_RUN);
        logger.info("Start execute ...");
        this.executeRun.start();
        logger.info("Execute run finished. Time: {} ms", stopWatch.stop(Timer.EXECUTE_RUN));
    } catch (ProBError e) {
        logger.error("ProBError: {}", e.getMessage());
        if (executeRun.getExecuteModelCommand() != null) {
            try {
                State finalState = executeRun.getExecuteModelCommand().getFinalState();
                // explores the final state and can throw a ProBError
                Collection<StateError> stateErrors = finalState.getStateErrors();
                for (StateError stateError : stateErrors) {
                    this.errors.add(new Error(ERROR_TYPES.PROB_ERROR, stateError.getLongDescription(), e));
                }
            } catch (ProBError e2) {
                // Enumeration errors
                this.errors.add(new Error(ERROR_TYPES.PROB_ERROR, e2.getMessage(), e2));
                return;
            }
        } else {
            /*- static errors such as type errors or errors while loading the  state space */
            this.errors.add(new Error(ERROR_TYPES.PROB_ERROR, e.getMessage(), e));
            /*- no final state is available and thus we can not create RuleResults */
            return;
        }
    } catch (Exception e) {
        logger.error("Unexpected error occured: {}", e.getMessage(), e);
        // storing all error messages
        this.errors.add(new Error(ERROR_TYPES.PROB_ERROR, e.getMessage(), e));
        return;
    } finally {
        if (executeRun.getUsedStateSpace() != null) {
            GetTotalNumberOfErrorsCommand totalNumberOfErrorsCommand = new GetTotalNumberOfErrorsCommand();
            executeRun.getUsedStateSpace().execute(totalNumberOfErrorsCommand);
            totalNumberOfProBCliErrors = totalNumberOfErrorsCommand.getTotalNumberOfErrors();
        }
    }
    this.stateSpace = this.executeRun.getUsedStateSpace();
    stopWatch.start(Timer.EXTRACT_RESULTS);
    this.ruleResults = new RuleResults(this.rulesProject, executeRun.getExecuteModelCommand().getFinalState(), maxNumberOfReportedCounterExamples);
    logger.info("Time to extract results from final state: {}", stopWatch.stop(Timer.EXTRACT_RESULTS));
}
Also used : StateError(de.prob.animator.domainobjects.StateError) State(de.prob.statespace.State) GetTotalNumberOfErrorsCommand(de.prob.animator.command.GetTotalNumberOfErrorsCommand) Collection(java.util.Collection) ProBError(de.prob.exception.ProBError) StateError(de.prob.animator.domainobjects.StateError) ProBError(de.prob.exception.ProBError) BException(de.be4.classicalb.core.parser.exceptions.BException)

Example 2 with StateError

use of de.prob.animator.domainobjects.StateError in project prob2 by bendisposto.

the class GetStateBasedErrorsCommandTest method testProcessResult.

@Test
public void testProcessResult() {
    @SuppressWarnings("unchecked") ISimplifiedROMap<String, PrologTerm> map = mock(ISimplifiedROMap.class);
    when(map.get("Errors")).thenReturn(new ListPrologTerm(new CompoundPrologTerm("error", new CompoundPrologTerm("foo"), new CompoundPrologTerm("bar"), new CompoundPrologTerm("baz"))));
    GetStateBasedErrorsCommand command = new GetStateBasedErrorsCommand("state");
    command.processResult(map);
    Collection<StateError> coll = command.getResult();
    StateError se = coll.iterator().next();
    assertEquals("foo", se.getEvent());
    assertEquals("bar", se.getShortDescription());
    assertEquals("baz", se.getLongDescription());
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) StateError(de.prob.animator.domainobjects.StateError) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) Test(org.junit.Test)

Example 3 with StateError

use of de.prob.animator.domainobjects.StateError in project prob2 by bendisposto.

the class GetStateBasedErrorsCommandTest method testProcessResultEmpty.

@Test
public void testProcessResultEmpty() {
    @SuppressWarnings("unchecked") ISimplifiedROMap<String, PrologTerm> map = mock(ISimplifiedROMap.class);
    when(map.get("Errors")).thenReturn(new ListPrologTerm());
    GetStateBasedErrorsCommand command = new GetStateBasedErrorsCommand("state");
    command.processResult(map);
    Collection<StateError> coll = command.getResult();
    assertEquals(Collections.emptyList(), coll);
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) StateError(de.prob.animator.domainobjects.StateError) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) Test(org.junit.Test)

Aggregations

StateError (de.prob.animator.domainobjects.StateError)3 CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)2 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)2 PrologTerm (de.prob.prolog.term.PrologTerm)2 Test (org.junit.Test)2 BException (de.be4.classicalb.core.parser.exceptions.BException)1 GetTotalNumberOfErrorsCommand (de.prob.animator.command.GetTotalNumberOfErrorsCommand)1 ProBError (de.prob.exception.ProBError)1 State (de.prob.statespace.State)1 Collection (java.util.Collection)1