Skip to content
Snippets Groups Projects
Commit fa3440e7 authored by Nils Christian Ehmke's avatar Nils Christian Ehmke
Browse files

Refactoring

parent 9fc5e591
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,9 @@
package kieker.diagnosis.common.model.importer.stages;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import java.util.ArrayList;
import java.util.List;
......@@ -26,54 +29,41 @@ import kieker.common.record.flow.trace.operation.AfterOperationFailedEvent;
import kieker.common.record.flow.trace.operation.BeforeOperationEvent;
import kieker.diagnosis.common.domain.OperationCall;
import kieker.diagnosis.common.domain.Trace;
import kieker.diagnosis.common.model.importer.stages.TraceReconstructor;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import teetime.framework.Analysis;
import teetime.framework.AnalysisConfiguration;
import teetime.framework.pipe.IPipeFactory;
import teetime.framework.pipe.SingleElementPipeFactory;
import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering;
import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication;
import teetime.stage.CollectorSink;
import teetime.stage.IterableProducer;
public final class TraceReconstructorTest {
private List<Trace> traceCollectorList;
private TraceReconstructor reconstructorUnderTest;
private CollectorSink<Trace> traceCollector;
@Before
public void initializeTraceReconstructor() {
this.traceCollectorList = new ArrayList<>();
this.reconstructorUnderTest = new TraceReconstructor();
this.traceCollector = new CollectorSink<>(this.traceCollectorList);
final IPipeFactory pipeFactory = new SingleElementPipeFactory();
pipeFactory.create(this.reconstructorUnderTest.getOutputPort(), this.traceCollector.getInputPort());
}
@Test
public void reconstructionOfSingleTraceShouldWork() {
final IFlowRecord[] records = new IFlowRecord[9];
records[0] = new TraceMetadata(1, 1, TraceMetadata.NO_SESSION_ID, TraceMetadata.NO_HOSTNAME, TraceMetadata.NO_PARENT_TRACEID, TraceMetadata.NO_PARENT_ORDER_INDEX);
records[1] = new BeforeOperationEvent(1, 1, 1, "main()", "Main");
records[2] = new BeforeOperationEvent(1, 1, 1, "Bookstore()", "Bookstore");
records[3] = new AfterOperationEvent(1, 1, 1, "Bookstore()", "Bookstore");
records[4] = new BeforeOperationEvent(1, 1, 1, "Catalog()", "Catalog");
records[5] = new BeforeOperationEvent(1, 1, 1, "CRM()", "CRM");
records[6] = new AfterOperationEvent(1, 1, 1, "CRM()", "CRM");
records[7] = new AfterOperationEvent(1, 1, 1, "Catalog()", "Catalog");
records[8] = new AfterOperationEvent(1, 1, 1, "main()", "Main");
for (final IFlowRecord record : records) {
this.reconstructorUnderTest.execute(record);
}
Assert.assertThat(this.traceCollectorList, Matchers.hasSize(1));
final Trace trace = this.traceCollectorList.get(0);
final List<IFlowRecord> input = new ArrayList<>();
input.add(new TraceMetadata(1, 1, TraceMetadata.NO_SESSION_ID, TraceMetadata.NO_HOSTNAME, TraceMetadata.NO_PARENT_TRACEID, TraceMetadata.NO_PARENT_ORDER_INDEX));
input.add(new BeforeOperationEvent(1, 1, 1, "main()", "Main"));
input.add(new BeforeOperationEvent(1, 1, 1, "Bookstore()", "Bookstore"));
input.add(new AfterOperationEvent(1, 1, 1, "Bookstore()", "Bookstore"));
input.add(new BeforeOperationEvent(1, 1, 1, "Catalog()", "Catalog"));
input.add(new BeforeOperationEvent(1, 1, 1, "CRM()", "CRM"));
input.add(new AfterOperationEvent(1, 1, 1, "CRM()", "CRM"));
input.add(new AfterOperationEvent(1, 1, 1, "Catalog()", "Catalog"));
input.add(new AfterOperationEvent(1, 1, 1, "main()", "Main"));
final ReconstructionConfiguration configuration = new ReconstructionConfiguration(input);
final Analysis analysis = new Analysis(configuration);
analysis.start();
Assert.assertThat(configuration.getOutput(), hasSize(1));
final Trace trace = configuration.getOutput().get(0);
final OperationCall rootCall = trace.getRootOperationCall();
Assert.assertThat(rootCall.getOperation(), Matchers.is("main()"));
Assert.assertThat(rootCall.getChildren(), Matchers.hasSize(2));
......@@ -85,22 +75,22 @@ public final class TraceReconstructorTest {
@Test
public void reconstructionOfInterleavedTracesShouldWork() {
final IFlowRecord[] records = new IFlowRecord[9];
final List<IFlowRecord> input = new ArrayList<>();
input.add(new TraceMetadata(1, 1, TraceMetadata.NO_SESSION_ID, TraceMetadata.NO_HOSTNAME, TraceMetadata.NO_PARENT_TRACEID, TraceMetadata.NO_PARENT_ORDER_INDEX));
input.add(new BeforeOperationEvent(1, 1, 1, "main()", "Main"));
input.add(new TraceMetadata(2, 1, TraceMetadata.NO_SESSION_ID, TraceMetadata.NO_HOSTNAME, TraceMetadata.NO_PARENT_TRACEID, TraceMetadata.NO_PARENT_ORDER_INDEX));
input.add(new BeforeOperationEvent(1, 2, 1, "Bookstore()", "Bookstore"));
input.add(new AfterOperationEvent(1, 1, 1, "main()", "Main"));
input.add(new AfterOperationEvent(1, 2, 1, "Bookstore()", "Bookstore"));
records[0] = new TraceMetadata(1, 1, TraceMetadata.NO_SESSION_ID, TraceMetadata.NO_HOSTNAME, TraceMetadata.NO_PARENT_TRACEID, TraceMetadata.NO_PARENT_ORDER_INDEX);
records[1] = new BeforeOperationEvent(1, 1, 1, "main()", "Main");
records[2] = new TraceMetadata(2, 1, TraceMetadata.NO_SESSION_ID, TraceMetadata.NO_HOSTNAME, TraceMetadata.NO_PARENT_TRACEID, TraceMetadata.NO_PARENT_ORDER_INDEX);
records[3] = new BeforeOperationEvent(1, 2, 1, "Bookstore()", "Bookstore");
records[4] = new AfterOperationEvent(1, 1, 1, "main()", "Main");
records[5] = new AfterOperationEvent(1, 2, 1, "Bookstore()", "Bookstore");
final ReconstructionConfiguration configuration = new ReconstructionConfiguration(input);
final Analysis analysis = new Analysis(configuration);
analysis.start();
for (final IFlowRecord record : records) {
this.reconstructorUnderTest.execute(record);
}
Assert.assertThat(this.traceCollectorList, Matchers.hasSize(2));
Assert.assertThat(configuration.getOutput(), hasSize(2));
final Trace fstTrace = this.traceCollectorList.get(0);
final Trace sndTrace = this.traceCollectorList.get(1);
final Trace fstTrace = configuration.getOutput().get(0);
final Trace sndTrace = configuration.getOutput().get(1);
Assert.assertThat(fstTrace.getRootOperationCall().getOperation(), Matchers.is("main()"));
Assert.assertThat(sndTrace.getRootOperationCall().getOperation(), Matchers.is("Bookstore()"));
......@@ -108,20 +98,20 @@ public final class TraceReconstructorTest {
@Test
public void reconstructionOfCompleteFailedTraceShouldWork() {
final IFlowRecord[] records = new IFlowRecord[9];
final List<IFlowRecord> input = new ArrayList<>();
input.add(new TraceMetadata(1, 1, TraceMetadata.NO_SESSION_ID, TraceMetadata.NO_HOSTNAME, TraceMetadata.NO_PARENT_TRACEID, TraceMetadata.NO_PARENT_ORDER_INDEX));
input.add(new BeforeOperationEvent(1, 1, 1, "main()", "Main"));
input.add(new BeforeOperationEvent(1, 1, 1, "Bookstore()", "Bookstore"));
input.add(new AfterOperationFailedEvent(1, 1, 1, "Bookstore()", "Bookstore", "NullPointerException"));
input.add(new AfterOperationFailedEvent(1, 1, 1, "main()", "Main", "IllegalArgumentException"));
records[0] = new TraceMetadata(1, 1, TraceMetadata.NO_SESSION_ID, TraceMetadata.NO_HOSTNAME, TraceMetadata.NO_PARENT_TRACEID, TraceMetadata.NO_PARENT_ORDER_INDEX);
records[1] = new BeforeOperationEvent(1, 1, 1, "main()", "Main");
records[2] = new BeforeOperationEvent(1, 1, 1, "Bookstore()", "Bookstore");
records[3] = new AfterOperationFailedEvent(1, 1, 1, "Bookstore()", "Bookstore", "NullPointerException");
records[8] = new AfterOperationFailedEvent(1, 1, 1, "main()", "Main", "IllegalArgumentException");
final ReconstructionConfiguration configuration = new ReconstructionConfiguration(input);
final Analysis analysis = new Analysis(configuration);
analysis.start();
for (final IFlowRecord record : records) {
this.reconstructorUnderTest.execute(record);
}
Assert.assertThat(this.traceCollectorList, Matchers.hasSize(1));
Assert.assertThat(configuration.getOutput(), hasSize(1));
final Trace trace = this.traceCollectorList.get(0);
final Trace trace = configuration.getOutput().get(0);
final OperationCall rootCall = trace.getRootOperationCall();
Assert.assertThat(rootCall.isFailed(), Matchers.is(true));
Assert.assertThat(rootCall.getFailedCause(), Matchers.is("IllegalArgumentException"));
......@@ -131,25 +121,47 @@ public final class TraceReconstructorTest {
@Test
public void reconstructionOfPartialFailedTraceShouldWork() {
final IFlowRecord[] records = new IFlowRecord[9];
final List<IFlowRecord> input = new ArrayList<>();
input.add(new TraceMetadata(1, 1, TraceMetadata.NO_SESSION_ID, TraceMetadata.NO_HOSTNAME, TraceMetadata.NO_PARENT_TRACEID, TraceMetadata.NO_PARENT_ORDER_INDEX));
input.add(new BeforeOperationEvent(1, 1, 1, "main()", "Main"));
input.add(new BeforeOperationEvent(1, 1, 1, "Bookstore()", "Bookstore"));
input.add(new AfterOperationFailedEvent(1, 1, 1, "Bookstore()", "Bookstore", "NullPointerException"));
input.add(new AfterOperationEvent(1, 1, 1, "main()", "Main"));
records[0] = new TraceMetadata(1, 1, TraceMetadata.NO_SESSION_ID, TraceMetadata.NO_HOSTNAME, TraceMetadata.NO_PARENT_TRACEID, TraceMetadata.NO_PARENT_ORDER_INDEX);
records[1] = new BeforeOperationEvent(1, 1, 1, "main()", "Main");
records[2] = new BeforeOperationEvent(1, 1, 1, "Bookstore()", "Bookstore");
records[3] = new AfterOperationFailedEvent(1, 1, 1, "Bookstore()", "Bookstore", "NullPointerException");
records[8] = new AfterOperationEvent(1, 1, 1, "main()", "Main");
final ReconstructionConfiguration configuration = new ReconstructionConfiguration(input);
final Analysis analysis = new Analysis(configuration);
analysis.start();
for (final IFlowRecord record : records) {
this.reconstructorUnderTest.execute(record);
}
Assert.assertThat(this.traceCollectorList, Matchers.hasSize(1));
Assert.assertThat(configuration.getOutput(), hasSize(1));
final Trace trace = this.traceCollectorList.get(0);
final Trace trace = configuration.getOutput().get(0);
final OperationCall rootCall = trace.getRootOperationCall();
Assert.assertThat(rootCall.isFailed(), Matchers.is(false));
Assert.assertThat(rootCall.containsFailure(), Matchers.is(true));
Assert.assertThat(rootCall.getChildren().get(0).isFailed(), Matchers.is(true));
Assert.assertThat(rootCall.getChildren().get(0).getFailedCause(), Matchers.is("NullPointerException"));
Assert.assertThat(rootCall.isFailed(), is(false));
Assert.assertThat(rootCall.containsFailure(), is(true));
Assert.assertThat(rootCall.getChildren().get(0).isFailed(), is(true));
Assert.assertThat(rootCall.getChildren().get(0).getFailedCause(), is("NullPointerException"));
}
private static class ReconstructionConfiguration extends AnalysisConfiguration {
private final List<Trace> traceCollectorList = new ArrayList<>();
public ReconstructionConfiguration(final List<IFlowRecord> input) {
final IterableProducer<List<IFlowRecord>, IFlowRecord> producer = new IterableProducer<>(input);
final TraceReconstructor reconstructor = new TraceReconstructor();
final CollectorSink<Trace> collector = new CollectorSink<>(this.traceCollectorList);
final IPipeFactory pipeFactory = AnalysisConfiguration.PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false);
pipeFactory.create(producer.getOutputPort(), reconstructor.getInputPort());
pipeFactory.create(reconstructor.getOutputPort(), collector.getInputPort());
this.addThreadableStage(producer);
}
public List<Trace> getOutput() {
return this.traceCollectorList;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment