Search in sources :

Example 1 with AcsJACSErrTest0Ex

use of alma.ACSErrTypeTest.wrappers.AcsJACSErrTest0Ex in project ACS by ACS-Community.

the class AcsJExceptionTest method testLogAcsJException.

/**
	 * Checks if logging of ACS exceptions (including caused-by exceptions) works.
	 * Here "logging" refers to special logging via
	 * {@link AcsJException#log(java.util.logging.Logger)}.
	 * <p>
	 * See also <code>alma.demo.client.XmlComponentClient#testException()</code> in module jcontexmpl.
	 */
public void testLogAcsJException() {
    LogRecordCollectingLogger logger = LogRecordCollectingLogger.getCollectingLogger("AcsJExceptionTest-Logger");
    long timeBefore = System.currentTimeMillis();
    try {
        exSystem.throwWrapperAcsJACSErrTest0Ex(true);
    } catch (AcsJACSErrTest0Ex e) {
        long timeAfter = System.currentTimeMillis();
        assertEquals(3, e.getTraceDepth());
        String firstLogMsg = "Will log exception coming from throwWrapperAcsJACSErrTest0Ex";
        logger.info(firstLogMsg);
        e.log(logger);
        LogRecord[] logRecords = logger.getCollectedLogRecords();
        assertNotNull(logRecords);
        assertEquals(4, logRecords.length);
        assertEquals(firstLogMsg, logRecords[0].getMessage());
        // The top-level exception is logged first, with stack level = 2
        LogRecord lr2 = logRecords[1];
        assertEquals("Test error 0 (type=" + ACSErrTypeTest.value + ", code=" + ACSErrTest0.value + ") :: remote call failed", lr2.getMessage());
        assertTrue(lr2.getMillis() >= timeBefore);
        assertTrue(lr2.getMillis() <= timeAfter);
        Map logProperties = (Map) lr2.getParameters()[0];
        assertTrue(logProperties.containsKey("Line"));
        assertTrue(logProperties.containsKey("ThreadName"));
        assertEquals(hostName, logProperties.get("HostName"));
        assertEquals("throwWrapperAcsJACSErrTest0Ex", lr2.getSourceMethodName());
        final String stackId = (String) logProperties.get("StackId");
        assertNotNull(stackId);
        assertEquals(2, ((Long) logProperties.get("StackLevel")).intValue());
        Map userProps2 = (Map) lr2.getParameters()[1];
        assertEquals(0, userProps2.size());
        // The causing exception is logged next, with stack level = 1
        LogRecord lr1 = logRecords[2];
        String msg1 = lr1.getMessage();
        assertEquals("Test error 0 (type=" + ACSErrTypeTest.value + ", code=" + ACSErrTest0.value + ") :: low level ex", msg1);
        assertTrue(lr1.getMillis() >= timeBefore);
        assertTrue(lr1.getMillis() <= timeAfter);
        logProperties = (Map) lr1.getParameters()[0];
        assertTrue(logProperties.containsKey("Line"));
        assertTrue(logProperties.containsKey("ThreadName"));
        assertEquals(hostName, logProperties.get("HostName"));
        assertEquals("throwOriginalAcsJACSErrTest0Ex", lr1.getSourceMethodName());
        assertEquals(stackId, logProperties.get("StackId"));
        assertEquals(1, ((Long) logProperties.get("StackLevel")).intValue());
        Map userProps1 = (Map) lr1.getParameters()[1];
        assertEquals(1, userProps1.size());
        assertEquals("Poverty", userProps1.get("MyStupidProperty"));
        // last comes the wrapped NullPointerException, with stack level = 0
        LogRecord lr0 = logRecords[3];
        String msg0 = lr0.getMessage();
        assertEquals("java.lang.NullPointerException (type=0, code=0) :: mean NPE", msg0);
        logProperties = (Map) lr0.getParameters()[0];
        assertTrue(logProperties.containsKey("Line"));
        assertTrue(logProperties.containsKey("ThreadName"));
        assertEquals(hostName, logProperties.get("HostName"));
        assertEquals("throwOriginalAcsJACSErrTest0Ex", lr0.getSourceMethodName());
        assertEquals(stackId, logProperties.get("StackId"));
        assertEquals(0, ((Long) logProperties.get("StackLevel")).intValue());
        Map userProps0 = (Map) lr0.getParameters()[1];
        assertEquals(0, userProps0.size());
    }
}
Also used : LogRecord(java.util.logging.LogRecord) LogRecordCollectingLogger(alma.acs.testsupport.LogRecordCollectingLogger) AcsJACSErrTest0Ex(alma.ACSErrTypeTest.wrappers.AcsJACSErrTest0Ex) Map(java.util.Map)

Example 2 with AcsJACSErrTest0Ex

use of alma.ACSErrTypeTest.wrappers.AcsJACSErrTest0Ex in project ACS by ACS-Community.

the class AcsJExceptionTest method checkWrapperAcsJEx.

/**
     * Checks the structure and values of the exception obtained from 
     * {@link ClientServerExceptionExample#throwWrapperAcsJACSErrTest0Ex(boolean)}. 
     * @param ex 
     */
private void checkWrapperAcsJEx(AcsJACSErrTest0Ex ex) {
    assertEquals("remote call failed", ex.getMessage());
    assertEquals("ClientServerExceptionExample.java", ex.getFile());
    assertEquals(3, ex.getTraceDepth());
    assertEquals(hostName, ex.getHost());
    String threadName = ex.getThreadName();
    assertNotNull(threadName);
    assertTrue(threadName.trim().length() > 0);
    assertTrue(ex.getLine() > 0);
    assertNotNull(ex.getMethod());
    assertTrue(ex.getMethod().trim().length() > 0);
    assertEquals(Severity.Error, ex.getSeverity());
    Throwable cause1 = ex.getCause();
    assertNotNull(cause1);
    assertTrue(cause1 instanceof AcsJACSErrTest0Ex && cause1 != ex);
    assertEquals("low level ex", cause1.getMessage());
    AcsJACSErrTest0Ex acsJCause1 = (AcsJACSErrTest0Ex) cause1;
    assertEquals("ClientServerExceptionExample.java", acsJCause1.getFile());
    assertEquals("Poverty", acsJCause1.getProperty("MyStupidProperty"));
    assertEquals(2, acsJCause1.getTraceDepth());
    long timeCause1 = acsJCause1.getTimestampMillis();
    assertEquals("ClientServerExceptionExample.java", acsJCause1.getFile());
    assertEquals(hostName, acsJCause1.getHost());
    assertEquals(threadName, acsJCause1.getThreadName());
    assertTrue(acsJCause1.getLine() > 0);
    assertNotNull(acsJCause1.getMethod());
    assertTrue(acsJCause1.getMethod().trim().length() > 0);
    assertEquals(Severity.Error, acsJCause1.getSeverity());
    Throwable cause2 = cause1.getCause();
    assertNotNull(cause2);
    assertTrue(cause2 instanceof DefaultAcsJException);
    assertEquals("mean NPE", cause2.getMessage());
    assertEquals("java.lang.NullPointerException", ((DefaultAcsJException) cause2).getShortDescription());
    DefaultAcsJException acsJCause2 = (DefaultAcsJException) cause2;
    assertEquals("ClientServerExceptionExample.java", acsJCause2.getFile());
    assertEquals(timeCause1 - 1, acsJCause2.getTimestampMillis());
    assertEquals(1, acsJCause2.getTraceDepth());
    assertEquals(hostName, acsJCause2.getHost());
    // NPE did not carry thread name info
    assertEquals("NA", acsJCause2.getThreadName());
    assertTrue(acsJCause2.getLine() > 0);
    assertNotNull(acsJCause2.getMethod());
    assertTrue(acsJCause2.getMethod().trim().length() > 0);
    assertEquals(Severity.Error, acsJCause2.getSeverity());
}
Also used : AcsJACSErrTest0Ex(alma.ACSErrTypeTest.wrappers.AcsJACSErrTest0Ex)

Example 3 with AcsJACSErrTest0Ex

use of alma.ACSErrTypeTest.wrappers.AcsJACSErrTest0Ex in project ACS by ACS-Community.

the class ClientServerExceptionExample method throwOriginalAcsJACSErrTest0Ex.

/**
     * Represents an implementation method that does not rely on any other
     * remote method (lowest level). Therefore, the thrown
     * <code>AcsJACSErrTest0Ex</code> is the VM original, i.e. not converted
     * from an <code>ErrorTrace</code>.
     * 
     * @throws AcsJACSErrTest0Ex
     *             (always), caused by a NPE with message "mean NPE".
     */
public void throwOriginalAcsJACSErrTest0Ex() throws AcsJACSErrTest0Ex {
    Throwable causedByEx = new NullPointerException("mean NPE");
    AcsJACSErrTest0Ex ex = new AcsJACSErrTest0Ex("low level ex", causedByEx);
    ex.setProperty("MyStupidProperty", "Poverty");
    throw ex;
}
Also used : AcsJACSErrTest0Ex(alma.ACSErrTypeTest.wrappers.AcsJACSErrTest0Ex)

Aggregations

AcsJACSErrTest0Ex (alma.ACSErrTypeTest.wrappers.AcsJACSErrTest0Ex)3 LogRecordCollectingLogger (alma.acs.testsupport.LogRecordCollectingLogger)1 Map (java.util.Map)1 LogRecord (java.util.logging.LogRecord)1