From 07b186e58ba25c14c1ee0bb98a63c5dd0cf26223 Mon Sep 17 00:00:00 2001
From: as <asalveter@gmail.com>
Date: Wed, 18 Mar 2015 17:07:57 +0100
Subject: [PATCH] create the class TraceValidator and a half test
---
...dTraceCounter.java => TraceValidator.java} | 37 ++++-----
.../filter/flow/TraceValidatorTest.java | 83 +++++++++++++++++++
.../ValidEventRecordTraceCounterTest.java | 71 ----------------
3 files changed, 100 insertions(+), 91 deletions(-)
rename src/main/java/teetime/stage/traceAnalysis/filter/flow/{ValidEventRecordTraceCounter.java => TraceValidator.java} (52%)
create mode 100644 src/test/java/teetime/stage/traceAnalysis/filter/flow/TraceValidatorTest.java
delete mode 100644 src/test/java/teetime/stage/traceAnalysis/filter/flow/ValidEventRecordTraceCounterTest.java
diff --git a/src/main/java/teetime/stage/traceAnalysis/filter/flow/ValidEventRecordTraceCounter.java b/src/main/java/teetime/stage/traceAnalysis/filter/flow/TraceValidator.java
similarity index 52%
rename from src/main/java/teetime/stage/traceAnalysis/filter/flow/ValidEventRecordTraceCounter.java
rename to src/main/java/teetime/stage/traceAnalysis/filter/flow/TraceValidator.java
index 6ac13448..824e408e 100644
--- a/src/main/java/teetime/stage/traceAnalysis/filter/flow/ValidEventRecordTraceCounter.java
+++ b/src/main/java/teetime/stage/traceAnalysis/filter/flow/TraceValidator.java
@@ -17,37 +17,34 @@ package teetime.stage.traceAnalysis.filter.flow;
import teetime.framework.AbstractConsumerStage;
import teetime.framework.OutputPort;
-
-import kieker.analysis.plugin.filter.flow.TraceEventRecords;
+import teetime.stage.trace.traceReconstruction.EventBasedTrace;
/**
- * Counts and reports the number of incoming valid {@link TraceEventRecords}.
+ * This class detects valid and invalid EventBasedTraces.
*
- * @author Andre van Hoorn, Arne Jan Salveter
+ * @author Arne Jan Salveter
*
- * @since 1.7
*/
-public class ValidEventRecordTraceCounter extends AbstractConsumerStage<TraceEventRecords> {
+public class TraceValidator extends AbstractConsumerStage<EventBasedTrace> {
- /** The output port delivering the incoming TraceEventRecords */
- private final OutputPort<TraceEventRecords> outputPort = this.createOutputPort();
- private int counter = 0;
+ private final OutputPort<EventBasedTrace> outputPortValid = this.createOutputPort();
+ private final OutputPort<EventBasedTrace> outputPortInvalid = this.createOutputPort();
- /** @return the counter */
- public int getCounter() {
- return counter;
+ public OutputPort<EventBasedTrace> getOutputPortValid() {
+ return outputPortValid;
}
- /** @return the outputPort */
- public OutputPort<TraceEventRecords> getOutputPort() {
- return outputPort;
+ public OutputPort<EventBasedTrace> getOutputPortInvalid() {
+ return outputPortInvalid;
}
@Override
- protected void execute(final TraceEventRecords element) {
- // Wie kann ich diesen Teil in teetime umsetzen?
- // super.reportSuccess(validTrace.getTraceMetadata().getTraceId());
- this.counter++;
- this.outputPort.send(element);
+ protected void execute(final EventBasedTrace element) {
+ if (element.isInvalid()) {
+ this.outputPortInvalid.send(element);
+ } else {
+ this.outputPortValid.send(element);
+ }
}
+
}
diff --git a/src/test/java/teetime/stage/traceAnalysis/filter/flow/TraceValidatorTest.java b/src/test/java/teetime/stage/traceAnalysis/filter/flow/TraceValidatorTest.java
new file mode 100644
index 00000000..43ec4502
--- /dev/null
+++ b/src/test/java/teetime/stage/traceAnalysis/filter/flow/TraceValidatorTest.java
@@ -0,0 +1,83 @@
+/**
+ * Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package teetime.stage.traceAnalysis.filter.flow;
+
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
+import static org.junit.Assert.assertThat;
+import static teetime.framework.test.StageTester.test;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import teetime.stage.trace.traceReconstruction.EventBasedTrace;
+import teetime.util.Pair;
+
+import kieker.common.record.flow.trace.ConstructionEvent;
+
+/**
+ * @author Arne Jan Salveter
+ */
+public class TraceValidatorTest {
+
+ Collection<Pair<Thread, Throwable>> exceptions;
+ private TraceValidator validator;
+ private EventBasedTrace input1;
+ private EventBasedTrace input2;
+ private ConstructionEvent validEvent;
+ private LinkedList<EventBasedTrace> resultsOutputPortValid;
+ private LinkedList<EventBasedTrace> resultsOutputPortInvalid;
+
+ @Before
+ public void initializeValidatorAndInputs() {
+ validator = new TraceValidator();
+ input1 = new EventBasedTrace();
+ validEvent = new ConstructionEvent(1, 1, 1, "Test", 1);
+ input1.insertEvent(validEvent);
+ input2 = new EventBasedTrace();
+ resultsOutputPortValid = new LinkedList<EventBasedTrace>();
+ resultsOutputPortInvalid = new LinkedList<EventBasedTrace>();
+ }
+
+ @Test
+ public void theOutputPortValidShouldForwardOneElement() {
+ exceptions = test(validator)
+ .and().send(input1).to(validator.getInputPort())
+ .and().receive(resultsOutputPortValid).from(validator.getOutputPortValid())
+ .and().receive(resultsOutputPortInvalid).from(validator.getOutputPortInvalid())
+ .start();
+ assertThat(exceptions, is(empty()));
+ assertThat(resultsOutputPortValid, contains(input1));
+ assertThat(resultsOutputPortInvalid, is(empty()));
+ }
+
+ @Test
+ public void theOutputPortInvalidShouldForwardOneElement() {
+ exceptions = test(validator)
+ .and().send(input2).to(validator.getInputPort())
+ .and().receive(resultsOutputPortValid).from(validator.getOutputPortValid())
+ .and().receive(resultsOutputPortInvalid).from(validator.getOutputPortInvalid())
+ .start();
+ assertThat(exceptions, is(empty()));
+ assertThat(resultsOutputPortValid, is(empty()));
+ assertThat(resultsOutputPortInvalid, contains(input2));
+ }
+
+}
diff --git a/src/test/java/teetime/stage/traceAnalysis/filter/flow/ValidEventRecordTraceCounterTest.java b/src/test/java/teetime/stage/traceAnalysis/filter/flow/ValidEventRecordTraceCounterTest.java
deleted file mode 100644
index 06d37bf2..00000000
--- a/src/test/java/teetime/stage/traceAnalysis/filter/flow/ValidEventRecordTraceCounterTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package teetime.stage.traceAnalysis.filter.flow;
-
-import java.util.LinkedList;
-
-import org.junit.Before;
-
-/**
- * @author Arne Jan Salveter
- */
-public class ValidEventRecordTraceCounterTest {
-
- private ValidEventRecordTraceCounter validERTCounter;
- private ValidEventRecordTraceCounter input1;
- private ValidEventRecordTraceCounter input2;
- private ValidEventRecordTraceCounter input3;
- private ValidEventRecordTraceCounter input4;
- private LinkedList<ValidEventRecordTraceCounter> inputElements;
- private LinkedList<ValidEventRecordTraceCounter> results;
-
- @Before
- public void initializeAnomalyDetectionFilterAndInputs() {
- validERTCounter = new ValidEventRecordTraceCounter();
- input1 = new ValidEventRecordTraceCounter();
- input2 = new ValidEventRecordTraceCounter();
- input3 = new ValidEventRecordTraceCounter();
- input4 = new ValidEventRecordTraceCounter();
- inputElements.add(input1);
- inputElements.add(input2);
- inputElements.add(input3);
- inputElements.add(input4);
-
- results = new LinkedList<ValidEventRecordTraceCounter>();
- }
-
- // @Test
- // public void theOutputPortShouldForwardZeroElements() {
- // Collection<Pair<Thread, Throwable>> exceptions;
- // exceptions = test(validERTCounter).and().send().to(validERTCounter.getInputPort())
- // .and().receive(results).from(validERTCounter.getOutputPort())
- // .start();
- // assertThat(exceptions, is(empty()));
- // assertThat(results, is(empty()));
- // assertTrue("counter is not 0", validERTCounter.getCounter() == 0);
- // }
- //
- // @Test
- // public void theOutputPortShouldForwardFourElements() {
- // Collection<Pair<Thread, Throwable>> exceptions;
- // exceptions = test(validERTCounter).and().send(inputElements).to(validERTCounter.getInputPort())
- // .and().receive(results).from(validERTCounter.getOutputPort())
- // .start();
- // assertThat(exceptions, is(empty()));
- // assertThat(results, contains(input1, input2, input3, input4));
- // assertTrue("counter is not 4", validERTCounter.getCounter() == 4);
- // }
-}
--
GitLab