diff --git a/src/main/java/teetime/util/test/eval/BucketTimingsReader.java b/src/main/java/teetime/util/test/eval/BucketTimingsReader.java deleted file mode 100644 index dcfcd8c72bd1e67cd84c6a94af6e3d471cc08927..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/test/eval/BucketTimingsReader.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (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.util.test.eval; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Charsets; -import com.google.common.io.CharSource; -import com.google.common.io.Files; - -public final class BucketTimingsReader { - - private static final Logger LOGGER = LoggerFactory.getLogger(BucketTimingsReader.class); - - private BucketTimingsReader() {} - - public static void main(final String[] args) throws IOException { - final String fileName = args[0]; - - final Long[] currentTimings = new Long[10000]; - int processedLines = 0; - final List<Long> buckets = new LinkedList<Long>(); - - LOGGER.trace("Reading " + fileName); - final CharSource charSource = Files.asCharSource(new File(fileName), Charsets.UTF_8); - final BufferedReader bufferedStream = charSource.openBufferedStream(); - String line; - while (null != (line = bufferedStream.readLine())) { - final String[] strings = line.split(";"); - final Long timing = new Long(strings[1]); - currentTimings[processedLines] = timing; - processedLines++; - if (currentTimings.length == processedLines) { - // Long aggregatedTimings = StatisticsUtil.calculateQuintiles(Arrays.asList(currentTimings)).get(0.5); - final Long aggregatedTimings = StatisticsUtil.calculateAverage(Arrays.asList(currentTimings)); - buckets.add(aggregatedTimings); - processedLines = 0; - } - } - - LOGGER.trace("#buckets: " + buckets.size()); - - final List<Long> durationsInNs = buckets.subList(buckets.size() / 2, buckets.size()); - - LOGGER.trace("Calculating quantiles..."); - final Map<Double, Long> quintiles = StatisticsUtil.calculateQuintiles(durationsInNs); - LOGGER.info(StatisticsUtil.getQuantilesString(quintiles)); - - final long confidenceWidth = StatisticsUtil.calculateConfidenceWidth(durationsInNs); - LOGGER.info("Confidence width: " + confidenceWidth); - } -} diff --git a/src/main/java/teetime/util/test/eval/MathUtil.java b/src/main/java/teetime/util/test/eval/MathUtil.java deleted file mode 100644 index b42f18e237d63ce813d6d115f9e9ee0d42822dc4..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/test/eval/MathUtil.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (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.util.test.eval; - -import java.util.List; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public final class MathUtil { - - private MathUtil() { - // utility class - } - - public static double getVariance(final List<Long> values, final long avgValue) { - double sum = 0; - for (final long val : values) { - final long diff = val - avgValue; - sum += (diff * diff) / (values.size() - 1); - } - return sum; - } - - public static double getConfidenceWidth(final double z, final double variance, final long n) { - return z * Math.sqrt(variance / n); - } - - public static double getConfidenceWidth(final double z, final List<Long> values, final long avgValue) { - final double variance = MathUtil.getVariance(values, avgValue); - final double confidenceWidth = MathUtil.getConfidenceWidth(z, variance, values.size()); - return confidenceWidth; - } -} diff --git a/src/main/java/teetime/util/test/eval/PerformanceResult.java b/src/main/java/teetime/util/test/eval/PerformanceResult.java deleted file mode 100644 index 41e7443cef29e00dbaa1a4c0df39ef42680ee9ca..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/test/eval/PerformanceResult.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (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.util.test.eval; - -import java.util.Map; - -public class PerformanceResult { - - public long overallDurationInNs; - public long sumInNs; - public Map<Double, Long> quantiles; - public long avgDurInNs; - public long confidenceWidthInNs; - - public PerformanceResult() {} - - @Override - public String toString() { - final StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("overallDurationInNs: "); - stringBuilder.append(this.overallDurationInNs); - stringBuilder.append("\n"); - - stringBuilder.append("sumInNs: "); - stringBuilder.append(this.sumInNs); - stringBuilder.append("\n"); - - stringBuilder.append("avgDurInNs: "); - stringBuilder.append(this.avgDurInNs); - stringBuilder.append("\n"); - - stringBuilder.append("confidenceWidthInNs: "); - stringBuilder.append(this.confidenceWidthInNs); - stringBuilder.append("\n"); - - stringBuilder.append(StatisticsUtil.getQuantilesString(this.quantiles)); - - return stringBuilder.toString(); - } -} diff --git a/src/main/java/teetime/util/test/eval/StatisticsUtil.java b/src/main/java/teetime/util/test/eval/StatisticsUtil.java deleted file mode 100644 index c49c187d70189c996e1fab7f9701545c21c665ff..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/test/eval/StatisticsUtil.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (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.util.test.eval; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.TimeUnit; - -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public final class StatisticsUtil { - - /** - * @since 1.10 - */ - private StatisticsUtil() { - // utility class - } - - public static PerformanceResult computeStatistics(final long overallDurationInNs, final List<TimestampObject> timestampObjects) { - final PerformanceResult performanceResult = new PerformanceResult(); - - performanceResult.overallDurationInNs = overallDurationInNs; - - final List<Long> sortedDurationsInNs = new ArrayList<Long>(timestampObjects.size() / 2); - long sumInNs = 0; - for (int i = timestampObjects.size() / 2; i < timestampObjects.size(); i++) { - final TimestampObject timestampObject = timestampObjects.get(i); - final long durationInNs = timestampObject.getStopTimestamp() - timestampObject.getStartTimestamp(); - // sortedDurationsInNs.set(i - (timestampObjects.size() / 2), durationInNs); - sortedDurationsInNs.add(durationInNs); - sumInNs += durationInNs; - } - - performanceResult.sumInNs = sumInNs; - - final Map<Double, Long> quintileValues = StatisticsUtil.calculateQuintiles(sortedDurationsInNs); - performanceResult.quantiles = quintileValues; - - final long avgDurInNs = sumInNs / (timestampObjects.size() / 2); - performanceResult.avgDurInNs = avgDurInNs; - - final long confidenceWidthInNs = StatisticsUtil.calculateConfidenceWidth(sortedDurationsInNs, avgDurInNs); - performanceResult.confidenceWidthInNs = confidenceWidthInNs; - - return performanceResult; - } - - public static String getQuantilesString(final Map<Double, Long> quantilesValues) { - final StringBuilder builder = new StringBuilder(); - for (final Entry<Double, Long> entry : quantilesValues.entrySet()) { - final String quantile = (entry.getKey() * 100) + " % : " + TimeUnit.NANOSECONDS.toNanos(entry.getValue()) + " ns"; - builder.append(quantile); - builder.append("\n"); - } - return builder.toString(); - } - - public static long calculateConfidenceWidth(final List<Long> durations, final long avgDurInNs) { - final double z = 1.96; // for alpha = 0.05 - final double variance = MathUtil.getVariance(durations, avgDurInNs); - final long confidenceWidthInNs = (long) MathUtil.getConfidenceWidth(z, variance, durations.size()); - return confidenceWidthInNs; - } - - public static long calculateConfidenceWidth(final List<Long> durations) { - return StatisticsUtil.calculateConfidenceWidth(durations, StatisticsUtil.calculateAverage(durations)); - } - - public static long calculateAverage(final List<Long> durations) { - long sumNs = 0; - for (final Long value : durations) { - sumNs += value; - } - - return sumNs / durations.size(); - } - - public static Map<Double, Long> calculateQuintiles(final List<Long> durationsInNs) { - Collections.sort(durationsInNs); - - final Map<Double, Long> quintileValues = new LinkedHashMap<Double, Long>(); - final double[] quintiles = { 0.00, 0.25, 0.50, 0.75, 1.00 }; - for (final double quintile : quintiles) { - final int index = (int) ((durationsInNs.size() - 1) * quintile); - quintileValues.put(quintile, durationsInNs.get(index)); - } - return quintileValues; - } - - public static void removeLeadingZeroThroughputs(final List<Long> throughputs) { - final Iterator<Long> iterator = throughputs.iterator(); - while (iterator.hasNext()) { - if (iterator.next() == 0) { - iterator.remove(); - } else { - break; - } - } - } - -} diff --git a/src/main/java/teetime/util/test/framework/AbstractProfiledPerformanceAssertion.java b/src/main/java/teetime/util/test/framework/AbstractProfiledPerformanceAssertion.java deleted file mode 100644 index 60afa855fee84d54148bc44569b5ff2e9ccbd1f1..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/test/framework/AbstractProfiledPerformanceAssertion.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (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.util.test.framework; - -public abstract class AbstractProfiledPerformanceAssertion { - - public abstract String getCorrespondingPerformanceProfile(); - - public abstract void check(); -} diff --git a/src/main/java/teetime/util/test/framework/MeasurementRepository.java b/src/main/java/teetime/util/test/framework/MeasurementRepository.java deleted file mode 100644 index be3552b876a1a3317d91cadae0576d941e8fed43..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/test/framework/MeasurementRepository.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (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.util.test.framework; - -import java.util.HashMap; -import java.util.Map; - -import teetime.util.test.eval.PerformanceResult; - -public class MeasurementRepository { - - public final Map<String, PerformanceResult> performanceResults = new HashMap<String, PerformanceResult>(); - - public MeasurementRepository() {} - - public static final String buildTestMethodIdentifier(final Class<?> testClass, final String methodName) { - return testClass.getName() + "(" + methodName + ")"; - } -} diff --git a/src/main/java/teetime/util/test/framework/PerformanceCheckProfileRepository.java b/src/main/java/teetime/util/test/framework/PerformanceCheckProfileRepository.java deleted file mode 100644 index a3ee2c7195b066e6695784ed2d3d4ce0b91b9868..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/test/framework/PerformanceCheckProfileRepository.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (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.util.test.framework; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PerformanceCheckProfileRepository { - - private static final Logger LOGGER = LoggerFactory.getLogger(PerformanceCheckProfileRepository.class); - - public static final PerformanceCheckProfileRepository INSTANCE = new PerformanceCheckProfileRepository(); - - private final Map<Class<?>, AbstractProfiledPerformanceAssertion> performanceCheckProfiles = new HashMap<Class<?>, AbstractProfiledPerformanceAssertion>(); - private String currentProfile; - - public PerformanceCheckProfileRepository() { - String hostName = getHostName(); - // this.currentProfile = System.getProperty("TestProfile", "ChwWork"); - currentProfile = hostName; - LOGGER.info("Using test profile '" + this.currentProfile + "'"); - } - - private String getHostName() { - String hostname = "Unknown"; - - try - { - InetAddress addr = InetAddress.getLocalHost(); - hostname = addr.getHostName(); - } catch (UnknownHostException ex) { - LOGGER.warn("Hostname can not be resolved"); - } - - return hostname; - } - - public void setCurrentProfile(final String currentProfile) { - this.currentProfile = currentProfile; - } - - public String getCurrentProfile() { - return this.currentProfile; - } - - public void register(final Class<?> testClass, final AbstractProfiledPerformanceAssertion profile) { - if (profile.getCorrespondingPerformanceProfile().equals(this.currentProfile)) { - this.performanceCheckProfiles.put(testClass, profile); - } - } - - public AbstractProfiledPerformanceAssertion get(final Class<?> clazz) { - return this.performanceCheckProfiles.get(clazz); - } -} diff --git a/src/test/java/teetime/framework/pipe/SpScPipeTest.java b/src/test/java/teetime/framework/pipe/SpScPipeTest.java index 5b06fa1e574a277a361c4c09ad26d990d5e061c0..c7a2db5b4ddd36feee67a09fb80d84f1a57559da 100644 --- a/src/test/java/teetime/framework/pipe/SpScPipeTest.java +++ b/src/test/java/teetime/framework/pipe/SpScPipeTest.java @@ -27,6 +27,7 @@ import teetime.framework.AbstractInterThreadPipe; import teetime.framework.InputPort; import teetime.framework.OutputPort; import teetime.framework.signal.ISignal; +import teetime.framework.signal.InitializingSignal; import teetime.framework.signal.StartingSignal; import teetime.framework.signal.TerminatingSignal; import teetime.framework.signal.ValidatingSignal; @@ -46,11 +47,14 @@ public class SpScPipeTest { List<ISignal> signals = new ArrayList<ISignal>(); signals.add(new StartingSignal()); signals.add(new TerminatingSignal()); + signals.add(new InitializingSignal()); signals.add(new ValidatingSignal()); signals.add(new StartingSignal()); signals.add(new TerminatingSignal()); + signals.add(new InitializingSignal()); signals.add(new ValidatingSignal()); signals.add(new StartingSignal()); + signals.add(new InitializingSignal()); signals.add(new TerminatingSignal()); signals.add(new ValidatingSignal());