From db5eef35048323cf612bc63289cc11c7eb3356cc Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Thu, 5 Feb 2015 13:51:59 +0100 Subject: [PATCH] Further tests --- .../common/model/PropertiesModelTest.java | 81 +++++++++++++++++++ ...ggregatedTraceStatisticsDecoratorTest.java | 59 ++++++++++++++ .../stages/TraceStatisticsDecoratorTest.java | 2 +- 3 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 src/test/java/kieker/diagnosis/common/model/PropertiesModelTest.java create mode 100644 src/test/java/kieker/diagnosis/common/model/importer/stages/AggregatedTraceStatisticsDecoratorTest.java diff --git a/src/test/java/kieker/diagnosis/common/model/PropertiesModelTest.java b/src/test/java/kieker/diagnosis/common/model/PropertiesModelTest.java new file mode 100644 index 00000000..38729267 --- /dev/null +++ b/src/test/java/kieker/diagnosis/common/model/PropertiesModelTest.java @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright 2014 Kieker Project (http://kieker-monitoring.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 kieker.diagnosis.common.model; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +import java.util.Observable; +import java.util.Observer; +import java.util.concurrent.TimeUnit; + +import org.junit.Test; + +public final class PropertiesModelTest { + + @Test + public void transactionalSettingShouldWork() { + final BooleanObserver observer = new BooleanObserver(); + final PropertiesModel model = new PropertiesModel(); + model.addObserver(observer); + + model.startModification(); + + model.setTimeunit(TimeUnit.NANOSECONDS); + assertThat(observer.isFlag(), is(false)); + + model.commitModification(); + + assertThat(observer.isFlag(), is(true)); + } + + @Test + public void usualSettingShouldNotifyObservers() { + final BooleanObserver observer = new BooleanObserver(); + final PropertiesModel model = new PropertiesModel(); + model.addObserver(observer); + + model.setTimeunit(TimeUnit.NANOSECONDS); + assertThat(observer.isFlag(), is(true)); + } + + @Test + public void settingShouldBePersisted() { + final PropertiesModel fstModel = new PropertiesModel(); + fstModel.setTimeunit(TimeUnit.NANOSECONDS); + fstModel.setTimeunit(TimeUnit.MICROSECONDS); + + final PropertiesModel sndModel = new PropertiesModel(); + assertThat(sndModel.getTimeunit(), is(TimeUnit.MICROSECONDS)); + } + + private static class BooleanObserver implements Observer { + + private boolean flag = false; + + @Override + public void update(final Observable o, final Object arg) { + this.flag = true; + } + + public boolean isFlag() { + return this.flag; + } + + } + +} diff --git a/src/test/java/kieker/diagnosis/common/model/importer/stages/AggregatedTraceStatisticsDecoratorTest.java b/src/test/java/kieker/diagnosis/common/model/importer/stages/AggregatedTraceStatisticsDecoratorTest.java new file mode 100644 index 00000000..68aa8e74 --- /dev/null +++ b/src/test/java/kieker/diagnosis/common/model/importer/stages/AggregatedTraceStatisticsDecoratorTest.java @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright 2014 Kieker Project (http://kieker-monitoring.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 kieker.diagnosis.common.model.importer.stages; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; + +import kieker.diagnosis.common.domain.AggregatedTrace; +import kieker.diagnosis.common.domain.OperationCall; +import kieker.diagnosis.common.domain.Trace; + +import org.junit.Test; + +public final class AggregatedTraceStatisticsDecoratorTest { + + @Test + public void minMaxMeanAndAvgCalculationForSingleCallShouldWork() throws Exception { + final OperationCall call1 = new OperationCall("", "", "", 43); + final OperationCall call2 = new OperationCall("", "", "", 44); + final OperationCall call3 = new OperationCall("", "", "", 45); + + call1.setDuration(15); + call2.setDuration(7); + call3.setDuration(44); + + final Trace trace1 = new Trace(call1, 43); + final Trace trace2 = new Trace(call2, 44); + final Trace trace3 = new Trace(call3, 45); + + final AggregatedTrace trace = new AggregatedTrace(Arrays.asList(trace1, trace2, trace3)); + + final AggregatedTraceStatisticsDecorator decorator = new AggregatedTraceStatisticsDecorator(); + + decorator.onStarting(); + decorator.execute(trace); + + assertThat(trace.getRootOperationCall().getMinDuration(), is(7L)); + assertThat(trace.getRootOperationCall().getMaxDuration(), is(44L)); + assertThat(trace.getRootOperationCall().getAvgDuration(), is(22L)); + assertThat(trace.getRootOperationCall().getMeanDuration(), is(15L)); + } + +} diff --git a/src/test/java/kieker/diagnosis/common/model/importer/stages/TraceStatisticsDecoratorTest.java b/src/test/java/kieker/diagnosis/common/model/importer/stages/TraceStatisticsDecoratorTest.java index f656acaf..7234e2a0 100644 --- a/src/test/java/kieker/diagnosis/common/model/importer/stages/TraceStatisticsDecoratorTest.java +++ b/src/test/java/kieker/diagnosis/common/model/importer/stages/TraceStatisticsDecoratorTest.java @@ -24,7 +24,7 @@ import kieker.diagnosis.common.domain.Trace; import org.junit.Test; -public class TraceStatisticsDecoratorTest { +public final class TraceStatisticsDecoratorTest { @Test public void percentCalculationShouldWork() throws Exception { -- GitLab