Skip to content
Snippets Groups Projects
Commit 33d9dffe authored by Nikolaus Huber's avatar Nikolaus Huber
Browse files

git-svn-id: https://se1.informatik.uni-wuerzburg.de/usvn/svn/code/code/DMM/trunk@9571 9e42b895-fcda-4063-8a3b-11be15eb1bbd
parent 52cf136c
No related branches found
No related tags found
No related merge requests found
...@@ -19,69 +19,68 @@ import edu.kit.ipd.descartes.perfdatarepo.Result; ...@@ -19,69 +19,68 @@ import edu.kit.ipd.descartes.perfdatarepo.Result;
public class WeightingFunctionHelperTest { public class WeightingFunctionHelperTest {
private static final String PERF_DATA_REPO_XMI_FILE = "../ExampleModels/Adaptation/PerformanceDataRepositoryDummy.xmi"; private static final String PERF_DATA_REPO_XMI_FILE = "../ExampleModels/Adaptation/PerformanceDataRepositoryDummy.xmi";
private static final double UTIL_WEIGHT = 2.0d; private static final double UTIL_WEIGHT = 2.0d;
PerformanceDataRepositoryHandler perfDataHandler = PerformanceDataRepositoryHandler.getInstance(); private PerformanceDataRepositoryHandler perfDataHandler = PerformanceDataRepositoryHandler.getInstance();
PerformanceDataRepository perfDataRepo = null; private PerformanceDataRepository perfDataRepo = null;
WeightingFunction function = null; private WeightingFunction function = null;
private enum METRIC_TYPES { private enum METRIC_TYPES {
UTILIZATION, UTILIZATION, RESPONSE_TIME;
RESPONSE_TIME; }
}
private MetricType getTypeHelper(METRIC_TYPES mType) {
private MetricType getTypeHelper(METRIC_TYPES mType) { EList<MetricType> types = perfDataRepo.getMetricTypes();
EList<MetricType> types = perfDataRepo.getMetricTypes(); switch (mType) {
switch (mType) { case UTILIZATION:
case UTILIZATION: return types.get(0);
return types.get(0); case RESPONSE_TIME:
case RESPONSE_TIME: return types.get(1);
return types.get(1); default:
default: return null;
return null; }
} }
}
@Before
@Before public void setUp() throws Exception {
public void setUp() throws Exception { perfDataRepo = (PerformanceDataRepository) perfDataHandler.load(URI.createFileURI(PERF_DATA_REPO_XMI_FILE));
perfDataRepo = (PerformanceDataRepository) perfDataHandler.load(URI.createFileURI(PERF_DATA_REPO_XMI_FILE)); MetricType metricType = getTypeHelper(METRIC_TYPES.UTILIZATION);
MetricType metricType = getTypeHelper(METRIC_TYPES.UTILIZATION);
function = AdaptationFactory.eINSTANCE.createWeightingFunction();
function = AdaptationFactory.eINSTANCE.createWeightingFunction(); WeightedMetric wUtil = AdaptationFactory.eINSTANCE.createWeightedMetric();
WeightedMetric wUtil = AdaptationFactory.eINSTANCE.createWeightedMetric(); wUtil.setId("1");
wUtil.setId("1"); wUtil.setName("UtilizationMetricWeight");
wUtil.setName("UtilizationMetricWeight"); wUtil.setWeight(UTIL_WEIGHT);
wUtil.setWeight(UTIL_WEIGHT); wUtil.setMetricType(metricType);
wUtil.setMetricType(metricType); function.getWeightedMetrics().add(wUtil);
function.getWeightedMetrics().add(wUtil); }
}
@Test
@Test public void testGetWeightForMetricType() {
public void testGetWeightForMetricType() { double weight = 0.0;
double weight = 0.0; MetricType metricType = getTypeHelper(METRIC_TYPES.RESPONSE_TIME);
MetricType metricType = getTypeHelper(METRIC_TYPES.RESPONSE_TIME); weight = WeightingFunctionHelper.getWeightForMetricType(function, metricType);
weight = WeightingFunctionHelper.getWeightForMetricType(function, metricType); assertEquals(Double.NaN, weight, 0.0);
assertEquals(Double.NaN, weight, 0.0);
metricType = getTypeHelper(METRIC_TYPES.UTILIZATION);
metricType = getTypeHelper(METRIC_TYPES.UTILIZATION); weight = WeightingFunctionHelper.getWeightForMetricType(function, metricType);
weight = WeightingFunctionHelper.getWeightForMetricType(function, metricType); assertEquals(UTIL_WEIGHT, weight, 0.0);
assertEquals(UTIL_WEIGHT, weight, 0.0); }
}
@Test
@Test public void testGetValueForMetricType() {
public void testGetValueForMetricType() { double testValue = 0;
double testValue = 0; MetricType metricType = getTypeHelper(METRIC_TYPES.UTILIZATION);
MetricType metricType = getTypeHelper(METRIC_TYPES.UTILIZATION);
Result emptyResult = PerfdatarepoFactory.eINSTANCE.createResult();
Result emptyResult = PerfdatarepoFactory.eINSTANCE.createResult(); testValue = WeightingFunctionHelper.getValueForMetricType(metricType, emptyResult);
testValue = WeightingFunctionHelper.getValueForMetricType(metricType, emptyResult); assertEquals(Double.NaN, testValue, 0);
assertEquals(Double.NaN, testValue, 0);
Impact impact = perfDataRepo.getImpactHistory().get(0);
Impact impact = perfDataRepo.getImpactHistory().get(0); Result before = impact.getBefore();
Result before = impact.getBefore(); testValue = WeightingFunctionHelper.getValueForMetricType(metricType, before);
testValue = WeightingFunctionHelper.getValueForMetricType(metricType, before); assertEquals(0.4, testValue, 0);
assertEquals(0.4, testValue, 0); }
}
} }
...@@ -51,17 +51,17 @@ public class WeightedSumCalculatorTest extends AbstractTest { ...@@ -51,17 +51,17 @@ public class WeightedSumCalculatorTest extends AbstractTest {
MetricValue metric1ValueBefore = PerfdatarepoFactory.eINSTANCE.createMetricValue(); MetricValue metric1ValueBefore = PerfdatarepoFactory.eINSTANCE.createMetricValue();
metric1ValueBefore.setMetric(respTime); metric1ValueBefore.setMetricType(respTime);
metric1ValueBefore.setValue(100); metric1ValueBefore.setValue(100);
MetricValue metric1ValueAfter = PerfdatarepoFactory.eINSTANCE.createMetricValue(); MetricValue metric1ValueAfter = PerfdatarepoFactory.eINSTANCE.createMetricValue();
metric1ValueAfter.setMetric(respTime); metric1ValueAfter.setMetricType(respTime);
metric1ValueAfter.setValue(50); metric1ValueAfter.setValue(50);
MetricValue metric2ValueBefore = PerfdatarepoFactory.eINSTANCE.createMetricValue(); MetricValue metric2ValueBefore = PerfdatarepoFactory.eINSTANCE.createMetricValue();
metric2ValueBefore.setMetric(util); metric2ValueBefore.setMetricType(util);
metric2ValueBefore.setValue(0.6); metric2ValueBefore.setValue(0.6);
MetricValue metric2ValueAfter = PerfdatarepoFactory.eINSTANCE.createMetricValue(); MetricValue metric2ValueAfter = PerfdatarepoFactory.eINSTANCE.createMetricValue();
metric2ValueAfter.setMetric(util); metric2ValueAfter.setMetricType(util);
metric2ValueAfter.setValue(0.8); metric2ValueAfter.setValue(0.8);
Result before = PerfdatarepoFactory.eINSTANCE.createResult(); Result before = PerfdatarepoFactory.eINSTANCE.createResult();
......
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