Search in sources :

Example 1 with ReceivedLogRecord

use of alma.acs.logging.engine.LogReceiver.ReceivedLogRecord in project ACS by ACS-Community.

the class LogSeriesExpectant method awaitLogRecords.

/**
	 * Call this method after the logs that should be received have been produced.
	 * Then the call may take up to <code>logRoundtripTimeSeconds</code> seconds to return.  
	 * 
	 * @param loggerName  The name of the logger whose records are to be collected. 
	 *                    Filtering of arriving log records will be done for the {@link ILogEntry.Field#SOURCEOBJECT} field.
	 * @param logRoundtripTimeSeconds  Maximum roundtrip time of a log record 
	 *                                 (incl. caching by container, sending to Log service, processing by Log service, arrival at LogReceiver).
	 */
LogList awaitLogRecords(String loggerName, int logRoundtripTimeSeconds) {
    // doesn't look like we need a running time windows to sort log records as long as we sort the list in the end.
    int sortingTimeWindowSeconds = 0;
    long endTimeMillis = System.currentTimeMillis() + (logRoundtripTimeSeconds + sortingTimeWindowSeconds) * 1000;
    LogList logRecords = new LogList();
    logReceiver.setDelayMillis(sortingTimeWindowSeconds * 1000);
    BlockingQueue<DelayedLogEntry> queue = logReceiver.getLogQueue();
    long waitTimeMillis = -1;
    while ((waitTimeMillis = endTimeMillis - System.currentTimeMillis()) > 0) {
        DelayedLogEntry delayedLogEntry = null;
        try {
            delayedLogEntry = queue.poll(waitTimeMillis, TimeUnit.MILLISECONDS);
        } catch (InterruptedException ex) {
        // continue
        }
        if (delayedLogEntry != null) {
            // timeout yields a null
            ReceivedLogRecord logRecord = delayedLogEntry.getLogRecord();
            String sourceObjectName = logRecord.getSourceObject();
            if (sourceObjectName != null && sourceObjectName.equals(loggerName)) {
                // printing this could be useful for debugging the test
                System.out.println("TEST DEBUG: " + logRecord.getMessage());
                if (logRecord.getMessage() == null) {
                    System.out.println("BUG: got a null log-message from " + sourceObjectName);
                    continue;
                }
                // Filter out python trace-logs (which could make it or not, depending on timing)
                if (logRecord.getMessage().startsWith("initialize -") || logRecord.getMessage().startsWith("getLevels -") || logRecord.getMessage().startsWith("cleanUp -")) {
                    //System.out.println("Dropping this log: "+ logRecord.getMessage());
                    continue;
                }
                // Filter out messages which are a work-around for a python issue 
                if (!logRecord.getMessage().endsWith("===packet fill-up message===")) {
                    logRecords.add(logRecord);
                }
            } else {
            // printing this could be useful for debugging the test
            //System.out.println("Dropped log message from " + sourceObjectName + ": " + logRecord.getMessage());
            //System.out.println("Dropped log message from " + sourceObjectName + ": " + logEntry.getField(ILogEntry.Field.LOGMESSAGE));
            }
        }
    }
    // sort by timestamp
    Collections.sort(logRecords, new Comparator<ReceivedLogRecord>() {

        public int compare(ReceivedLogRecord o1, ReceivedLogRecord o2) {
            return o1.getTimestamp().compareTo(o2.getTimestamp());
        }
    });
    return logRecords;
}
Also used : DelayedLogEntry(alma.acs.logging.engine.LogReceiver.DelayedLogEntry) ReceivedLogRecord(alma.acs.logging.engine.LogReceiver.ReceivedLogRecord)

Aggregations

DelayedLogEntry (alma.acs.logging.engine.LogReceiver.DelayedLogEntry)1 ReceivedLogRecord (alma.acs.logging.engine.LogReceiver.ReceivedLogRecord)1