Search in sources :

Example 1 with DbAppenederException

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

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

the class ActiveDbAppender method waitForEventToBeExecuted.

/**
     * Here we block the test execution until this event gets executed.
     * If this event fail, we will abort the execution of the tests.
     *
     * @param packedEvent
     * @param event
     */
private void waitForEventToBeExecuted(LogEventRequest packedEvent, LoggingEvent event, boolean waitMoreTime) {
    synchronized (this) {
        //we need to wait for the event to be handled
        queue.add(packedEvent);
        try {
            // Start waiting and release the lock. The queue processing thread will notify us after the event is
            // handled or if an exception occurs. In case handling the event hangs - we put some timeout
            long startTime = System.currentTimeMillis();
            long timeout = EVENT_WAIT_TIMEOUT;
            if (waitMoreTime) {
                timeout = EVENT_WAIT_LONG_TIMEOUT;
            }
            wait(timeout);
            if (System.currentTimeMillis() - startTime > timeout - 100) {
                System.out.println(TimeUtils.getFormattedDateTillMilliseconds() + "*** ATS *** The expected " + event.getClass().getSimpleName() + " logging event did not complete in " + timeout + " ms");
            }
        } catch (InterruptedException ie) {
            throw new DbAppenederException(TimeUtils.getFormattedDateTillMilliseconds() + "*** ATS *** Main thread interrupted while waiting for event " + event.getClass().getSimpleName(), ie);
        }
    }
    //check for exceptions - if they are none, then we are good to go
    checkForExceptions();
    //this event has already been through the queue
    return;
}
Also used : DbAppenederException(com.axway.ats.log.autodb.exceptions.DbAppenederException)

Aggregations

DbAppenederException (com.axway.ats.log.autodb.exceptions.DbAppenederException)2 DbEventRequestProcessor (com.axway.ats.log.autodb.DbEventRequestProcessor)1 LogEventRequest (com.axway.ats.log.autodb.LogEventRequest)1 QueueLoggerThread (com.axway.ats.log.autodb.QueueLoggerThread)1 DatabaseAccessException (com.axway.ats.log.autodb.exceptions.DatabaseAccessException)1 InvalidAppenderConfigurationException (com.axway.ats.log.autodb.exceptions.InvalidAppenderConfigurationException)1