Search in sources :

Example 1 with LogEventRequest

use of com.axway.ats.log.autodb.LogEventRequest 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 2 with LogEventRequest

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

the class AbstractDbAppender method activateOptions.

/* (non-Javadoc)
     * @see org.apache.log4j.AppenderSkeleton#activateOptions()
     */
@Override
public void activateOptions() {
    //check whether the configuration is valid first
    try {
        appenderConfig.validate();
    } catch (InvalidAppenderConfigurationException iace) {
        throw new DbAppenederException(iace);
    }
    //set the threshold if there is such
    appenderConfig.setLoggingThreshold(getThreshold());
    //the logging queue
    queue = new ArrayBlockingQueue<LogEventRequest>(getMaxNumberLogEvents());
    // enable batch mode at ATS Agent side only
    boolean isWorkingAtAgentSide = this instanceof PassiveDbAppender;
    boolean isBatchMode = false;
    if (isWorkingAtAgentSide) {
        isBatchMode = isBatchMode();
    }
    //create new event processor
    try {
        eventProcessor = new DbEventRequestProcessor(appenderConfig, layout, getEventRequestProcessorListener(), isBatchMode);
    } catch (DatabaseAccessException e) {
        throw new RuntimeException("Unable to create DB event processor", e);
    }
    //start the logging thread
    queueLogger = new QueueLoggerThread(queue, eventProcessor, isBatchMode);
    queueLogger.setDaemon(true);
    queueLogger.start();
}
Also used : DbAppenederException(com.axway.ats.log.autodb.exceptions.DbAppenederException) DbEventRequestProcessor(com.axway.ats.log.autodb.DbEventRequestProcessor) QueueLoggerThread(com.axway.ats.log.autodb.QueueLoggerThread) InvalidAppenderConfigurationException(com.axway.ats.log.autodb.exceptions.InvalidAppenderConfigurationException) LogEventRequest(com.axway.ats.log.autodb.LogEventRequest) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 3 with LogEventRequest

use of com.axway.ats.log.autodb.LogEventRequest 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

LogEventRequest (com.axway.ats.log.autodb.LogEventRequest)3 AbstractLoggingEvent (com.axway.ats.log.autodb.model.AbstractLoggingEvent)2 DbEventRequestProcessor (com.axway.ats.log.autodb.DbEventRequestProcessor)1 QueueLoggerThread (com.axway.ats.log.autodb.QueueLoggerThread)1 DeleteTestCaseEvent (com.axway.ats.log.autodb.events.DeleteTestCaseEvent)1 DatabaseAccessException (com.axway.ats.log.autodb.exceptions.DatabaseAccessException)1 DbAppenederException (com.axway.ats.log.autodb.exceptions.DbAppenederException)1 InvalidAppenderConfigurationException (com.axway.ats.log.autodb.exceptions.InvalidAppenderConfigurationException)1