Search in sources :

Example 6 with LogRecordCollectingLogger

use of alma.acs.testsupport.LogRecordCollectingLogger in project ACS by ACS-Community.

the class StopWatchTest method testWithSubtaskWithLogging.

@Test
public void testWithSubtaskWithLogging() throws Exception {
    LogRecordCollectingLogger logger = LogRecordCollectingLogger.getCollectingLogger("testWithSubtaskWithLogging");
    StopWatch sw_top = new StopWatch(logger);
    Thread.sleep(sleepMillis);
    StopWatch sw_sub_1 = sw_top.createStopWatchForSubtask("subtask-1");
    Thread.sleep(25);
    sw_sub_1.stop();
    StopWatch sw_sub_2 = sw_top.createStopWatchForSubtask("subtask-2");
    StopWatch sw_sub_2_1 = sw_sub_2.createStopWatchForSubtask("subtask-2-1");
    Thread.sleep(40);
    sw_sub_2_1.stop();
    StopWatch sw_sub_2_2 = sw_sub_2.createStopWatchForSubtask("subtask-2-2");
    Thread.sleep(35);
    sw_sub_2_2.stop();
    sw_sub_2.stop();
    StopWatch sw_sub_3 = sw_top.createStopWatchForSubtask("subtask-3");
    Thread.sleep(15);
    sw_sub_3.stop();
    sw_top.logLapTimeWithSubtaskDetails("sleep and perform subtasks", Level.INFO);
    LogRecord[] logRecords = logger.getCollectedLogRecords();
    assertThat(logRecords.length, equalTo(1));
    assertThat(logRecords[0].getLevel(), equalTo(Level.INFO));
    String msg = logRecords[0].getMessage();
    Map<String, Double> taskTimes = parseStopWatchTimes(msg);
    assertThat(taskTimes.get("total"), closeTo(215, timeGranularityMillis));
    assertThat(taskTimes.get("subtask-1"), closeTo(25, timeGranularityMillis));
    assertThat(taskTimes.get("subtask-2"), closeTo(75, timeGranularityMillis));
    assertThat(taskTimes.get("subtask-2-1"), closeTo(40, timeGranularityMillis));
    assertThat(taskTimes.get("subtask-2-2"), closeTo(35, timeGranularityMillis));
    assertThat(taskTimes.get("subtask-3"), closeTo(15, timeGranularityMillis));
    // Use a null logger (stdout). Currently we only verify there is no exception. Could inject stdout handler...
    sw_top = new StopWatch();
    Thread.sleep(sleepMillis);
    sw_sub_1 = sw_top.createStopWatchForSubtask("subtask-1");
    Thread.sleep(25);
    sw_top.logLapTimeWithSubtaskDetails("sleep and perform subtasks", Level.INFO);
}
Also used : LogRecord(java.util.logging.LogRecord) LogRecordCollectingLogger(alma.acs.testsupport.LogRecordCollectingLogger) Test(org.junit.Test)

Example 7 with LogRecordCollectingLogger

use of alma.acs.testsupport.LogRecordCollectingLogger in project ACS by ACS-Community.

the class StopWatchTest method testNoSubtaskWithLogging.

@Test
public void testNoSubtaskWithLogging() throws Exception {
    LogRecordCollectingLogger logger1 = LogRecordCollectingLogger.getCollectingLogger("testNoSubtaskWithLogging");
    StopWatch sw1 = new StopWatch(logger1);
    Thread.sleep(sleepMillis);
    sw1.logLapTime("sleep 100 ms");
    LogRecord[] logRecords = logger1.getCollectedLogRecords();
    assertThat(logRecords.length, equalTo(1));
    assertThat(logRecords[0].getLevel(), equalTo(Level.FINE));
    String msg = logRecords[0].getMessage();
    assertThat(msg, startsWith("elapsed time in ms to sleep 100 ms: "));
    String loggedTimeString = msg.split(":")[1].trim();
    double timeMillis = Double.parseDouble(loggedTimeString);
    assertThat(timeMillis, closeTo(sleepMillis, timeGranularityMillis));
}
Also used : LogRecord(java.util.logging.LogRecord) LogRecordCollectingLogger(alma.acs.testsupport.LogRecordCollectingLogger) Test(org.junit.Test)

Example 8 with LogRecordCollectingLogger

use of alma.acs.testsupport.LogRecordCollectingLogger in project ACS by ACS-Community.

the class RepeatGuardLoggerTest method testRepeatGuardLogger.

/**
	 * @TODO test more, also factory methods and deprecated methods
	 */
public void testRepeatGuardLogger() throws Exception {
    // our AcsLogger (that is to be guarded by the tested RepeatGuardLogger) 
    // we construct around a LogRecordCollectingLogger, so that we can verify the detected 
    // class name, line-of-code etc directly inside this test
    LogRecordCollectingLogger logger0 = LogRecordCollectingLogger.getCollectingLogger(getClass().getName());
    AcsLogger logger1 = AcsLogger.fromJdkLogger(logger0, null);
    RepeatGuardLogger logger2 = new RepeatGuardLogger(logger1, 1, TimeUnit.SECONDS, 10);
    logger2.log(Level.INFO, "Simple test.");
    LogRecord[] records = logger0.getCollectedLogRecords();
    assertEquals(1, records.length);
    assertEquals("RepeatGuardLoggerTest.java", records[0].getSourceClassName());
    assertEquals("testRepeatGuardLogger", records[0].getSourceMethodName());
//		for (int i = 0; i < 50; i++) {
//			guardbl.log(logger, Level.INFO, "Log A without incrementing");
//			guardbl.log(logger, Level.INFO, "Log B without incrementing");
//			guardbl.logAndIncrement(logger, Level.INFO, "Log C with incrementing");
//		}
}
Also used : LogRecord(java.util.logging.LogRecord) LogRecordCollectingLogger(alma.acs.testsupport.LogRecordCollectingLogger)

Example 9 with LogRecordCollectingLogger

use of alma.acs.testsupport.LogRecordCollectingLogger in project ACS by ACS-Community.

the class CleaningThreadFactoryTest method testThreadStackDebugMessages.

public void testThreadStackDebugMessages() {
    LogRecordCollectingLogger collectingLogger = LogRecordCollectingLogger.getCollectingLogger("testThreadStackDebugMessages_CollectingLogger");
    System.setProperty(CleaningDaemonThreadFactory.LOG_THREAD_CREATION_CALLSTACK_PROPERTYNAME, "true");
    CleaningDaemonThreadFactory tf = new CleaningDaemonThreadFactory("factoryWithStackTrace", collectingLogger);
    Runnable dummyRunnable = new Runnable() {

        public void run() {
        }
    };
    tf.newThread(dummyRunnable);
    LogRecord[] records = collectingLogger.getCollectedLogRecords();
    assertEquals(1, records.length);
    assertTrue(records[0].getMessage().startsWith("Created thread 'factoryWithStackTrace-1'. Call stack: alma.acs.container.CleaningThreadFactoryTest.testThreadStackDebugMessages(CleaningThreadFactoryTest.java:202) <- "));
    System.setProperty(CleaningDaemonThreadFactory.LOG_THREAD_CREATION_CALLSTACK_PROPERTYNAME, "false");
}
Also used : LogRecord(java.util.logging.LogRecord) LogRecordCollectingLogger(alma.acs.testsupport.LogRecordCollectingLogger)

Aggregations

LogRecordCollectingLogger (alma.acs.testsupport.LogRecordCollectingLogger)9 LogRecord (java.util.logging.LogRecord)9 Test (org.junit.Test)2 AcsJACSErrTest0Ex (alma.ACSErrTypeTest.wrappers.AcsJACSErrTest0Ex)1 ComponentWithBadNullsImpl (alma.jconttest.ComponentWithBadNullsImpl.ComponentWithBadNullsImpl)1 ComponentWithBadNullsOperations (alma.jconttest.ComponentWithBadNullsOperations)1 Struct1 (alma.jconttest.ComponentWithBadNullsPackage.Struct1)1 Struct1Holder (alma.jconttest.ComponentWithBadNullsPackage.Struct1Holder)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 StringHolder (org.omg.CORBA.StringHolder)1