use of kieker.common.record.IMonitoringRecord 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 = TestDummyWriter.getEvents();
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());
}
}
use of kieker.common.record.IMonitoringRecord in project iobserve-analysis by research-iobserve.
the class FixTraceMetadata method execute.
@Override
protected void execute(final IMonitoringRecord event) throws Exception {
if (event instanceof TraceMetadata) {
this.traces.put(((TraceMetadata) event).getTraceId(), event.getLoggingTimestamp());
this.outputPort.send(event);
final List<IMonitoringRecord> keptRecords = this.stash.get(((TraceMetadata) event).getTraceId());
if (keptRecords != null) {
for (final IMonitoringRecord record : keptRecords) {
this.outputPort.send(record);
}
}
} else if (event instanceof ITraceRecord) {
final Long time = this.traces.get(((ITraceRecord) event).getTraceId());
if (time != null) {
this.traces.put(((ITraceRecord) event).getTraceId(), event.getLoggingTimestamp());
this.outputPort.send(event);
} else {
List<IMonitoringRecord> keptRecords = this.stash.get(((ITraceRecord) event).getTraceId());
if (keptRecords == null) {
keptRecords = new ArrayList<>();
}
keptRecords.add(event);
this.stash.put(((ITraceRecord) event).getTraceId(), keptRecords);
}
} else {
this.outputPort.send(event);
}
}
use of kieker.common.record.IMonitoringRecord in project iobserve-analysis by research-iobserve.
the class HackedRecordFromBinaryFileCreator method processBuffer.
private void processBuffer(final ReaderRegistry<String> registry, final IValueDeserializer deserializer, final OutputPort<IMonitoringRecord> outputPort) throws IOException {
this.buffer.flip();
try {
/**
* Needs at least an record id.
*/
while (this.buffer.position() + 4 <= this.buffer.limit()) {
this.buffer.mark();
final IMonitoringRecord record = this.deserializeRecord(registry, deserializer);
if (record == null) {
return;
} else {
outputPort.send(record);
}
}
this.buffer.mark();
this.buffer.compact();
} catch (final BufferUnderflowException ex) {
HackedRecordFromBinaryFileCreator.LOGGER.warn("Unexpected buffer underflow. Resetting and compacting buffer.", ex);
this.buffer.reset();
this.buffer.compact();
throw ex;
}
}
use of kieker.common.record.IMonitoringRecord in project iobserve-analysis by research-iobserve.
the class MultipleConnectionTcpReaderStage method deserializeRecord.
private boolean deserializeRecord(final Connection connection, final int clazzId) throws IOException {
final String recordClassName = connection.getRegistry().get(clazzId);
// identify logging timestamp
if (connection.getBuffer().remaining() < MultipleConnectionTcpReaderStage.LONG_BYTES) {
// incomplete record, move back
connection.getBuffer().reset();
connection.getBuffer().compact();
return false;
} else {
final long loggingTimestamp = connection.getBuffer().getLong();
// identify record data
final IRecordFactory<? extends IMonitoringRecord> recordFactory = this.recordFactories.get(recordClassName);
if (connection.getBuffer().remaining() < recordFactory.getRecordSizeInBytes()) {
// incomplete record, move back
connection.getBuffer().reset();
connection.getBuffer().compact();
return false;
} else {
try {
final IMonitoringRecord record = recordFactory.create(connection.getValueDeserializer());
this.recordRewriter.rewrite(connection, record, loggingTimestamp, this.outputPort);
return true;
} catch (final RecordInstantiationException ex) {
super.logger.error("Failed to create: " + recordClassName, ex);
// incomplete record, move back
connection.getBuffer().reset();
connection.getBuffer().compact();
return false;
}
}
}
}
use of kieker.common.record.IMonitoringRecord in project iobserve-analysis by research-iobserve.
the class ProbeControlFilterTest method setUp.
/**
* Setup the test.
*/
@Before
public void setUp() {
synchronized (this) {
final IRecordReceivedListener listener = new IRecordReceivedListener() {
@Override
public void onRecordReceived(final IMonitoringRecord record) {
// do nothing.. the TCP sender is tested elsewhere
}
};
ProbeControlFilterTest.port++;
this.tcpReader = new SingleSocketRecordReader(ProbeControlFilterTest.port, ProbeControlFilterTest.BUFFER_SIZE, ProbeControlFilterTest.LOGGER, listener);
new Thread(this.tcpReader).start();
this.probeControlFilter = new ProbeControlFilter(new TcpProbeController());
}
}
Aggregations