Search in sources :

Example 1 with AbstractLoggingEvent

use of com.axway.ats.log.autodb.model.AbstractLoggingEvent in project ats-framework by Axway.

the class DbEventRequestProcessor method processEventRequest.

public void processEventRequest(LogEventRequest eventRequest) throws LoggingException {
    if (testcaseToDelete > 0) {
        /* Pause for a moment processing the current event.
             * This is (delete testcase)event is not coming from the FIFO queue, as we want to process it as
             * soon as possible, so any events related to this testcase are directly skipped.
             */
        deleteRequestedTestcase();
    // now resume the processing of the current event that came from the queue
    }
    if (isBatchMode && eventRequest == null) {
        // timeout waiting for next event - flush the current cache
        dbAccess.flushCache();
        return;
    }
    LoggingEvent event = eventRequest.getEvent();
    if (event instanceof AbstractLoggingEvent) {
        AbstractLoggingEvent dbAppenderEvent = (AbstractLoggingEvent) event;
        //first check if we can process the event at all
        dbAppenderEvent.checkIfCanBeProcessed(eventProcessorState);
        if (isBatchMode && !(event instanceof CacheableEvent) && eventProcessorState.getLifeCycleState() == LifeCycleState.TEST_CASE_STARTED) {
            // this event can not be cached - flush the current cache
            dbAccess.flushCache();
        }
        switch(dbAppenderEvent.getEventType()) {
            case START_RUN:
                startRun((StartRunEvent) event, eventRequest.getTimestamp());
                break;
            case END_RUN:
                endRun(eventRequest.getTimestamp());
                break;
            case UPDATE_RUN:
                updateRun((UpdateRunEvent) event);
                break;
            case ADD_RUN_METAINFO:
                addRunMetainfo((AddRunMetainfoEvent) event);
                break;
            case START_SUITE:
                startSuite((StartSuiteEvent) event, eventRequest.getTimestamp());
                break;
            case END_SUITE:
                endSuite(eventRequest.getTimestamp());
                break;
            case CLEAR_SCENARIO_METAINFO:
                clearScenarioMetainfo();
                break;
            case ADD_SCENARIO_METAINFO:
                addScenarioMetainfo((AddScenarioMetainfoEvent) event);
                break;
            case START_TEST_CASE:
                startTestCase((StartTestCaseEvent) event, eventRequest.getTimestamp());
                break;
            case END_TEST_CASE:
                endTestCase((EndTestCaseEvent) event, eventRequest.getTimestamp());
                break;
            case JOIN_TEST_CASE:
                joinTestCase((JoinTestCaseEvent) event);
                break;
            case LEAVE_TEST_CASE:
                leaveTestCase();
                break;
            case REMEMBER_LOADQUEUE_STATE:
                rememberLoadQueueState((RememberLoadQueueStateEvent) event);
                break;
            case CLEANUP_LOADQUEUE_STATE:
                cleanupLoadQueueState((CleanupLoadQueueStateEvent) event);
                break;
            case END_LOADQUEUE:
                endLoadQueue((EndLoadQueueEvent) event, eventRequest.getTimestamp());
                break;
            case REGISTER_THREAD_WITH_LOADQUEUE:
                registerThreadWithLoadQueue((RegisterThreadWithLoadQueueEvent) event);
                break;
            case START_CHECKPOINT:
                startCheckpoint((StartCheckpointEvent) event);
                break;
            case END_CHECKPOINT:
                endCheckpoint((EndCheckpointEvent) event);
                break;
            case INSERT_CHECKPOINT:
                insertCheckpoint((InsertCheckpointEvent) event);
                break;
            case INSERT_SYSTEM_STAT:
                insertSystemStatistics((InsertSystemStatisticEvent) event);
                break;
            case INSERT_MESSAGE:
                InsertMessageEvent insertMessageEvent = (InsertMessageEvent) event;
                insertMessage(eventRequest, insertMessageEvent.isEscapeHtml(), insertMessageEvent.isRunMessage());
                break;
            default:
                throw new LoggingException("Unsupported logging event of type: " + dbAppenderEvent.getEventType());
        }
    } else {
        insertMessage(eventRequest, false, false);
    }
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) AbstractLoggingEvent(com.axway.ats.log.autodb.model.AbstractLoggingEvent) AbstractLoggingEvent(com.axway.ats.log.autodb.model.AbstractLoggingEvent) LoggingException(com.axway.ats.log.autodb.exceptions.LoggingException) InsertMessageEvent(com.axway.ats.log.autodb.events.InsertMessageEvent) CacheableEvent(com.axway.ats.log.autodb.model.CacheableEvent)

Example 2 with AbstractLoggingEvent

use of com.axway.ats.log.autodb.model.AbstractLoggingEvent in project ats-framework by Axway.

the class PassiveDbAppender method append.

/* (non-Javadoc)
     * @see org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent)
     */
@Override
protected void append(LoggingEvent event) {
    if (!doWeServiceThisCaller()) {
        return;
    }
    if (event instanceof AbstractLoggingEvent) {
        AbstractLoggingEvent dbLoggingEvent = (AbstractLoggingEvent) event;
        switch(dbLoggingEvent.getEventType()) {
            case JOIN_TEST_CASE:
                {
                    // remember test case id
                    testCaseState.setTestcaseId(((JoinTestCaseEvent) event).getTestCaseState().getTestcaseId());
                    break;
                }
            case LEAVE_TEST_CASE:
                {
                    // clear test case id
                    testCaseState.clearTestcaseId();
                    break;
                }
            default:
                // do nothing about this event
                break;
        }
    }
    // All events from all threads come into here
    long eventTimestamp;
    if (event instanceof AbstractLoggingEvent) {
        eventTimestamp = ((AbstractLoggingEvent) event).getTimestamp();
    } else {
        eventTimestamp = System.currentTimeMillis();
    }
    LogEventRequest packedEvent = new // Remember which thread this event belongs to
    LogEventRequest(// Remember which thread this event belongs to
    Thread.currentThread().getName(), event, // Remember the event time
    eventTimestamp);
    passEventToLoggerQueue(packedEvent);
}
Also used : AbstractLoggingEvent(com.axway.ats.log.autodb.model.AbstractLoggingEvent) LogEventRequest(com.axway.ats.log.autodb.LogEventRequest)

Example 3 with AbstractLoggingEvent

use of com.axway.ats.log.autodb.model.AbstractLoggingEvent in project ats-framework by Axway.

the class ReportAppender method append.

/* (non-Javadoc)
     * @see org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent)
     */
@Override
protected void append(LoggingEvent event) {
    // All events from all threads come into here.
    if (event instanceof AbstractLoggingEvent) {
        AbstractLoggingEvent dbLoggingEvent = (AbstractLoggingEvent) event;
        switch(dbLoggingEvent.getEventType()) {
            case START_RUN:
                run = new RunWrapper();
                suitesMap = new HashMap<String, SuiteWrapper>();
                StartRunEvent startRunEvent = (StartRunEvent) event;
                run.productName = startRunEvent.getProductName();
                run.versionName = startRunEvent.getVersionName();
                run.buildName = startRunEvent.getBuildName();
                run.os = startRunEvent.getOsName();
                run.runName = startRunEvent.getRunName();
                run.dateStart = AbstractDbAccess.DATE_FORMAT_NO_YEAR.format(startRunEvent.getTimeStamp());
                break;
            case START_SUITE:
                StartSuiteEvent startSuiteEvent = (StartSuiteEvent) event;
                lastPlayedSuite = startSuiteEvent.getSuiteName();
                if (!suitesMap.containsKey(lastPlayedSuite)) {
                    SuiteWrapper newSuite = new SuiteWrapper();
                    newSuite.name = startSuiteEvent.getSuiteName();
                    newSuite.packageName = startSuiteEvent.getPackage();
                    newSuite.dateStart = AbstractDbAccess.DATE_FORMAT_NO_YEAR.format(startSuiteEvent.getTimeStamp());
                    suitesMap.put(newSuite.packageName + "." + newSuite.name, newSuite);
                    run.addSuite(newSuite);
                }
                break;
            case START_TEST_CASE:
                StartTestCaseEvent startTestcaseEvent = (StartTestCaseEvent) dbLoggingEvent;
                startTestcaseEvent.getSuiteFullName();
                Testcase newTestcase = new Testcase();
                newTestcase.scenarioName = startTestcaseEvent.getScenarioName();
                newTestcase.name = startTestcaseEvent.getTestcaseName();
                suitesMap.get(startTestcaseEvent.getSuiteFullName()).addTestcase(newTestcase);
                /*
                     * There are very rare cases when the test harness system does not execute all tests from
                     * same suite one after another, but there will be some tests from another suite executed
                     * in between.
                     *
                     * That is why the next line navigates to the right suite when starting the test scenario
                     */
                lastPlayedSuite = startTestcaseEvent.getSuiteFullName();
                break;
            case END_TEST_CASE:
                EndTestCaseEvent endTestCaseEvent = (EndTestCaseEvent) event;
                // update the result of the current testcase
                suitesMap.get(lastPlayedSuite).getLastTestcase().result = endTestCaseEvent.getTestCaseResult().toInt();
                break;
            case END_SUITE:
                EndSuiteEvent endSuiteEvent = (EndSuiteEvent) event;
                SuiteWrapper currentSuite = getCurrentSuite();
                if (currentSuite != null) {
                    currentSuite.calculateFinalStatistics();
                    currentSuite.dateEnd = AbstractDbAccess.DATE_FORMAT_NO_YEAR.format(endSuiteEvent.getTimeStamp());
                    currentSuite.duration = calculateDuration(currentSuite.dateStart, currentSuite.dateEnd);
                    currentSuite.testcasesPassedPercent = "0";
                    if (currentSuite.testcasesTotal > 0) {
                        currentSuite.testcasesPassedPercent = String.valueOf((currentSuite.testcasesTotal - currentSuite.testcasesFailed - currentSuite.testcasesSkipped) * 100 / currentSuite.testcasesTotal);
                    }
                }
                // we cleanup here in case first Scenario of next Suite has same name
                // as last Scenario of current Suite
                lastPlayedSuite = "";
                break;
            case END_RUN:
                // The run is over, we want to mail a report about this run
                EndRunEvent endRunEvent = (EndRunEvent) event;
                run.calculateFinalStatistics();
                run.dateEnd = AbstractDbAccess.DATE_FORMAT_NO_YEAR.format(endRunEvent.getTimeStamp());
                run.duration = calculateDuration(run.dateStart, run.dateEnd);
                run.testcasesPassedPercent = "0";
                if (run.testcasesTotal > 0) {
                    run.testcasesPassedPercent = String.valueOf((run.testcasesTotal - run.testcasesFailed - run.testcasesSkipped) * 100 / run.testcasesTotal);
                    try {
                        // format the report
                        ReportFormatter reportFormatter = new ReportFormatter(run);
                        // so, just add the test data to the map
                        if (!combinedHtmlMailReport) {
                            // send report by mail
                            MailReportSender mailReportSender = new MailReportSender(generateMailSubject(run, reportFormatter.getRunsState()), reportFormatter.toHtml());
                            mailReportSender.send();
                        } else {
                            // delay report to collect data for all runs
                            htmlReportsList.add(run);
                        }
                    } catch (Exception e) {
                        errorHandler.error("Error processing/mailing log report", e, ErrorCode.GENERIC_FAILURE);
                    }
                }
                break;
        }
    }
}
Also used : EndSuiteEvent(com.axway.ats.log.autodb.events.EndSuiteEvent) StartSuiteEvent(com.axway.ats.log.autodb.events.StartSuiteEvent) AbstractLoggingEvent(com.axway.ats.log.autodb.model.AbstractLoggingEvent) Testcase(com.axway.ats.log.autodb.entities.Testcase) RunWrapper(com.axway.ats.log.report.model.RunWrapper) EndTestCaseEvent(com.axway.ats.log.autodb.events.EndTestCaseEvent) EndRunEvent(com.axway.ats.log.autodb.events.EndRunEvent) StartTestCaseEvent(com.axway.ats.log.autodb.events.StartTestCaseEvent) MailReportSender(com.axway.ats.log.report.model.MailReportSender) ParseException(java.text.ParseException) SuiteWrapper(com.axway.ats.log.report.model.SuiteWrapper) StartRunEvent(com.axway.ats.log.autodb.events.StartRunEvent) ReportFormatter(com.axway.ats.log.report.model.ReportFormatter)

Example 4 with AbstractLoggingEvent

use of com.axway.ats.log.autodb.model.AbstractLoggingEvent in project ats-framework by Axway.

the class ActiveDbAppender method append.

/* (non-Javadoc)
     * @see org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent)
     */
@Override
protected void append(LoggingEvent event) {
    // All events from all threads come into here
    long eventTimestamp;
    if (event instanceof AbstractLoggingEvent) {
        eventTimestamp = ((AbstractLoggingEvent) event).getTimestamp();
    } else {
        eventTimestamp = System.currentTimeMillis();
    }
    LogEventRequest packedEvent = new // Remember which thread this event belongs to
    LogEventRequest(// Remember which thread this event belongs to
    Thread.currentThread().getName(), event, // Remember the event time
    eventTimestamp);
    if (event instanceof AbstractLoggingEvent) {
        AbstractLoggingEvent dbLoggingEvent = (AbstractLoggingEvent) event;
        switch(dbLoggingEvent.getEventType()) {
            case START_TEST_CASE:
                {
                    // on Test Executor side we block until the test case start is committed in the DB
                    waitForEventToBeExecuted(packedEvent, dbLoggingEvent, true);
                    // remember the test case id, which we will later pass to ATS agent
                    testCaseState.setTestcaseId(eventProcessor.getTestCaseId());
                    //this event has already been through the queue
                    return;
                }
            case END_TEST_CASE:
                {
                    // clear test case id
                    testCaseState.clearTestcaseId();
                    // now pass the event to the queue
                    break;
                }
            case GET_CURRENT_TEST_CASE_STATE:
                {
                    // get current test case id which will be passed to ATS agent
                    ((GetCurrentTestCaseEvent) event).setTestCaseState(testCaseState);
                    //this event should not go through the queue
                    return;
                }
            case START_RUN:
                /* We synchronize the run start:
                     *      Here we make sure we are able to connect to the log DB.
                     *      We also check the integrity of the DB schema.
                     * If we fail here, it does not make sense to run tests at all
                     */
                System.out.println(TimeUtils.getFormattedDateTillMilliseconds() + "*** ATS *** Waiting for " + event.getClass().getSimpleName() + " event completion");
                waitForEventToBeExecuted(packedEvent, dbLoggingEvent, false);
                //this event has already been through the queue
                return;
            case END_RUN:
                {
                    /* We synchronize the run end.
                     * This way if there are remaining log events in the Test Executor's queue,
                     * the JVM will not be shutdown prior to committing all events in the DB, as
                     * the END_RUN event is the last one in the queue
                     */
                    System.out.println(TimeUtils.getFormattedDateTillMilliseconds() + "*** ATS *** Waiting for " + event.getClass().getSimpleName() + " event completion");
                    waitForEventToBeExecuted(packedEvent, dbLoggingEvent, true);
                    //this event has already been through the queue
                    return;
                }
            case DELETE_TEST_CASE:
                {
                    // tell the thread on the other side of the queue, that this test case is to be deleted
                    // on first chance
                    eventProcessor.requestTestcaseDeletion(((DeleteTestCaseEvent) dbLoggingEvent).getTestCaseId());
                    // this event is not going through the queue
                    return;
                }
            default:
                // do nothing about this event
                break;
        }
    }
    passEventToLoggerQueue(packedEvent);
}
Also used : DeleteTestCaseEvent(com.axway.ats.log.autodb.events.DeleteTestCaseEvent) AbstractLoggingEvent(com.axway.ats.log.autodb.model.AbstractLoggingEvent) LogEventRequest(com.axway.ats.log.autodb.LogEventRequest)

Aggregations

AbstractLoggingEvent (com.axway.ats.log.autodb.model.AbstractLoggingEvent)4 LogEventRequest (com.axway.ats.log.autodb.LogEventRequest)2 Testcase (com.axway.ats.log.autodb.entities.Testcase)1 DeleteTestCaseEvent (com.axway.ats.log.autodb.events.DeleteTestCaseEvent)1 EndRunEvent (com.axway.ats.log.autodb.events.EndRunEvent)1 EndSuiteEvent (com.axway.ats.log.autodb.events.EndSuiteEvent)1 EndTestCaseEvent (com.axway.ats.log.autodb.events.EndTestCaseEvent)1 InsertMessageEvent (com.axway.ats.log.autodb.events.InsertMessageEvent)1 StartRunEvent (com.axway.ats.log.autodb.events.StartRunEvent)1 StartSuiteEvent (com.axway.ats.log.autodb.events.StartSuiteEvent)1 StartTestCaseEvent (com.axway.ats.log.autodb.events.StartTestCaseEvent)1 LoggingException (com.axway.ats.log.autodb.exceptions.LoggingException)1 CacheableEvent (com.axway.ats.log.autodb.model.CacheableEvent)1 MailReportSender (com.axway.ats.log.report.model.MailReportSender)1 ReportFormatter (com.axway.ats.log.report.model.ReportFormatter)1 RunWrapper (com.axway.ats.log.report.model.RunWrapper)1 SuiteWrapper (com.axway.ats.log.report.model.SuiteWrapper)1 ParseException (java.text.ParseException)1 LoggingEvent (org.apache.log4j.spi.LoggingEvent)1