Search in sources :

Example 1 with EntryLevelBeforeOperationEvent

use of org.iobserve.common.record.EntryLevelBeforeOperationEvent in project iobserve-analysis by research-iobserve.

the class SessionAndTraceRegistrationPayloadFilterTest method testDoFilter.

/**
 * Test method for
 * {@link org.iobserve.monitoring.probe.servlet.SessionAndTraceRegistrationPayloadFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)}.
 *
 * @throws InterruptedException
 *             during the sleep time of the thread
 */
// TODO Something goes occasionally wrong in this test. FixME!
// @Test
public void testDoFilter() throws InterruptedException {
    final ServletContext context = new TestServletContext();
    final ServletResponse response = new TestHttpServletResponse();
    final HttpSession session = new TestHttpSession(context);
    final TestHttpServletRequest request = new TestHttpServletRequest(context, session);
    final FilterConfig filterConfig = new TestFilterConfig(context);
    final SessionAndTraceRegistrationPayloadFilter filter = new SessionAndTraceRegistrationPayloadFilter();
    try {
        filter.init(filterConfig);
        filter.doFilter(request, response, this.createChain());
        MonitoringController.getInstance().terminateMonitoring();
        while (!MonitoringController.getInstance().isMonitoringTerminated()) {
            Thread.sleep(1000);
        }
        final List<IMonitoringRecord> storage = TestDumpWriter.getRecords();
        Assert.assertTrue("No records received", !storage.isEmpty());
        IMonitoringRecord record = storage.get(0);
        Assert.assertEquals("Should be KiekerMetadataRecord", KiekerMetadataRecord.class, record.getClass());
        record = storage.get(1);
        Assert.assertEquals("Should be TraceMetadata", TraceMetadata.class, record.getClass());
        record = storage.get(2);
        Assert.assertEquals("Should be EntryLevelBeforeOperationEvent", EntryLevelBeforeOperationEvent.class, record.getClass());
        if (record instanceof EntryLevelBeforeOperationEvent) {
            final EntryLevelBeforeOperationEvent beforeEvent = (EntryLevelBeforeOperationEvent) record;
            Assert.assertEquals("Class signature does not match", TestServletContext.CONTEXT_PATH, beforeEvent.getClassSignature());
            Assert.assertEquals("Operation signature does not match", TestHttpServletRequest.REQUEST_URI, beforeEvent.getOperationSignature());
            final Iterator<String> keys = request.getParameters().keySet().iterator();
            for (final String label : beforeEvent.getParameters()) {
                if (!keys.hasNext()) {
                    Assert.fail("Found more parameters than defined in the request.");
                } else {
                    Assert.assertEquals("Same parameter", keys.next(), label);
                }
            }
            final Iterator<String> values = request.getParameters().values().iterator();
            for (final String label : beforeEvent.getValues()) {
                if (!values.hasNext()) {
                    Assert.fail("Found more parameters than defined in the request.");
                } else {
                    Assert.assertEquals("Same parameter", values.next(), label);
                }
            }
        }
        record = storage.get(3);
        Assert.assertEquals("Should be AfterOperationEvent", AfterOperationEvent.class, record.getClass());
        Assert.assertEquals("Wrong number of records ", 4, storage.size());
    } catch (final ServletException e) {
        Assert.fail(e.getMessage());
    } catch (final IOException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : ServletResponse(javax.servlet.ServletResponse) HttpSession(javax.servlet.http.HttpSession) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) EntryLevelBeforeOperationEvent(org.iobserve.common.record.EntryLevelBeforeOperationEvent) IMonitoringRecord(kieker.common.record.IMonitoringRecord) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig)

Example 2 with EntryLevelBeforeOperationEvent

use of org.iobserve.common.record.EntryLevelBeforeOperationEvent in project iobserve-analysis by research-iobserve.

the class EntryCallStage method createEntryCall.

private PayloadAwareEntryCallEvent createEntryCall(final TraceMetadata traceMetaData) {
    final BeforeOperationEvent beforeOperationEvent = this.matcher.getBeforeOperationEvent();
    final AfterOperationEvent afterOperationEvent = this.matcher.getAfterOperationEvent();
    if (beforeOperationEvent instanceof EntryLevelBeforeOperationEvent) {
        final EntryLevelBeforeOperationEvent entryLevelBeforeEvent = (EntryLevelBeforeOperationEvent) beforeOperationEvent;
        return new PayloadAwareEntryCallEvent(beforeOperationEvent.getTimestamp(), afterOperationEvent.getTimestamp(), beforeOperationEvent.getOperationSignature(), beforeOperationEvent.getClassSignature(), traceMetaData.getSessionId(), traceMetaData.getHostname(), entryLevelBeforeEvent.getParameters(), entryLevelBeforeEvent.getValues(), entryLevelBeforeEvent.getRequestType());
    } else {
        return new PayloadAwareEntryCallEvent(beforeOperationEvent.getTimestamp(), afterOperationEvent.getTimestamp(), beforeOperationEvent.getOperationSignature(), beforeOperationEvent.getClassSignature(), traceMetaData.getSessionId(), traceMetaData.getHostname(), new String[0], new String[0], 0);
    }
}
Also used : PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) AfterOperationEvent(kieker.common.record.flow.trace.operation.AfterOperationEvent) EntryLevelBeforeOperationEvent(org.iobserve.common.record.EntryLevelBeforeOperationEvent) EntryLevelBeforeOperationEvent(org.iobserve.common.record.EntryLevelBeforeOperationEvent) BeforeOperationEvent(kieker.common.record.flow.trace.operation.BeforeOperationEvent)

Example 3 with EntryLevelBeforeOperationEvent

use of org.iobserve.common.record.EntryLevelBeforeOperationEvent in project iobserve-analysis by research-iobserve.

the class SessionAndTraceRegistrationPayloadFilter method logMonitoringAndHandleFilterChain.

private void logMonitoringAndHandleFilterChain(final FilterChain chain, final ServletRequest request, final ServletResponse response, final long traceId, final int orderIndex, final String operationSignature, final String componentSignature, final String[] parameters, final String[] parameterValues, final int type, final boolean newTrace) throws ServletException {
    try {
        SessionAndTraceRegistrationPayloadFilter.CTRLINST.newMonitoringRecord(new EntryLevelBeforeOperationEvent(SessionAndTraceRegistrationPayloadFilter.TIMESOURCE.getTime(), traceId, orderIndex, operationSignature, componentSignature, parameters, parameterValues, type));
        chain.doFilter(request, response);
        SessionAndTraceRegistrationPayloadFilter.CTRLINST.newMonitoringRecord(new AfterOperationEvent(SessionAndTraceRegistrationPayloadFilter.TIMESOURCE.getTime(), traceId, orderIndex, operationSignature, componentSignature));
    } catch (final Throwable th) {
        // NOPMD NOCS (catch throw is ok here)
        SessionAndTraceRegistrationPayloadFilter.CTRLINST.newMonitoringRecord(new AfterOperationFailedEvent(SessionAndTraceRegistrationPayloadFilter.TIMESOURCE.getTime(), traceId, orderIndex, operationSignature, componentSignature, th.toString()));
        throw new ServletException(th);
    } finally {
        // is this correct?
        SessionAndTraceRegistrationPayloadFilter.SESSION_REGISTRY.unsetThreadLocalSessionId();
        // Reset the thread-local trace information
        if (newTrace) {
            // close the trace
            SessionAndTraceRegistrationPayloadFilter.TRACEREGISTRY.unregisterTrace();
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) AfterOperationFailedEvent(kieker.common.record.flow.trace.operation.AfterOperationFailedEvent) AfterOperationEvent(kieker.common.record.flow.trace.operation.AfterOperationEvent) EntryLevelBeforeOperationEvent(org.iobserve.common.record.EntryLevelBeforeOperationEvent)

Aggregations

EntryLevelBeforeOperationEvent (org.iobserve.common.record.EntryLevelBeforeOperationEvent)3 ServletException (javax.servlet.ServletException)2 AfterOperationEvent (kieker.common.record.flow.trace.operation.AfterOperationEvent)2 IOException (java.io.IOException)1 FilterConfig (javax.servlet.FilterConfig)1 ServletContext (javax.servlet.ServletContext)1 ServletResponse (javax.servlet.ServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 IMonitoringRecord (kieker.common.record.IMonitoringRecord)1 AfterOperationFailedEvent (kieker.common.record.flow.trace.operation.AfterOperationFailedEvent)1 BeforeOperationEvent (kieker.common.record.flow.trace.operation.BeforeOperationEvent)1 PayloadAwareEntryCallEvent (org.iobserve.stages.general.data.PayloadAwareEntryCallEvent)1