Skip to content

Commit

Permalink
Add back tests for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas-Boltz committed Feb 23, 2024
1 parent b73b89f commit d7d8953
Show file tree
Hide file tree
Showing 143 changed files with 12,221 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.palladiosimulator.simulizar.monitorrepository.map.tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=17
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tests
Bundle-SymbolicName: org.palladiosimulator.simulizar.monitorrepository.map.tests
Bundle-Version: 5.2.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.palladiosimulator.simulizar.monitorrepository.map;bundle-version="5.2.0",
org.junit,
org.palladiosimulator.monitorrepository.map;bundle-version="1.0.0",
org.palladiosimulator.simulizar.runtimemeasurement,
org.palladiosimulator.measurementframework,
org.palladiosimulator.simulizar;bundle-version="2.0.8",
org.jscience
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig">
<booleanAttribute key="append.args" value="true"/>
<booleanAttribute key="askclear" value="false"/>
<booleanAttribute key="automaticAdd" value="true"/>
<booleanAttribute key="automaticValidate" value="false"/>
<stringAttribute key="bootstrap" value=""/>
<stringAttribute key="checked" value="[NONE]"/>
<booleanAttribute key="clearConfig" value="true"/>
<booleanAttribute key="clearws" value="true"/>
<booleanAttribute key="clearwslog" value="false"/>
<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
<booleanAttribute key="default" value="true"/>
<booleanAttribute key="includeOptional" value="true"/>
<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/org.palladiosimulator.simulizar.monitorrepository.map.tests"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.palladiosimulator.simulizar.monitorrepository.map.tests"/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.palladiosimulator.simulizar.monitorrepository.map.tests"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dosgi.requiredJavaVersion=1.6 -Xms40m -Xmx512m"/>
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="org.eclipse.platform.ide"/>
<booleanAttribute key="run_in_ui_thread" value="true"/>
<booleanAttribute key="show_selected_only" value="false"/>
<booleanAttribute key="tracing" value="false"/>
<booleanAttribute key="useCustomFeatures" value="false"/>
<booleanAttribute key="useDefaultConfig" value="true"/>
<booleanAttribute key="useDefaultConfigArea" value="false"/>
<booleanAttribute key="useProduct" value="true"/>
</launchConfiguration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package org.palladiosimulator.simulizar.monitorrepository.map.runtimemeasurement.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import java.util.List;

import javax.measure.Measure;
import javax.measure.quantity.Duration;
import javax.measure.unit.NonSI;
import javax.measure.unit.SI;

import org.junit.Before;
import org.junit.Test;
import org.palladiosimulator.edp2.models.measuringpoint.MeasuringPoint;
import org.palladiosimulator.edp2.models.measuringpoint.MeasuringpointFactory;
import org.palladiosimulator.measurementframework.MeasuringValue;
import org.palladiosimulator.measurementframework.TupleMeasurement;
import org.palladiosimulator.metricspec.constants.MetricDescriptionConstants;
import org.palladiosimulator.monitorrepository.MeasurementSpecification;
import org.palladiosimulator.monitorrepository.Monitor;
import org.palladiosimulator.monitorrepository.MonitorRepositoryFactory;
import org.palladiosimulator.monitorrepository.map.ExponentialSmoothing;
import org.palladiosimulator.monitorrepository.map.Map;
import org.palladiosimulator.monitorrepository.map.MapFactory;
import org.palladiosimulator.runtimemeasurement.RuntimeMeasurement;
import org.palladiosimulator.runtimemeasurement.RuntimeMeasurementFactory;
import org.palladiosimulator.runtimemeasurement.RuntimeMeasurementModel;
import org.palladiosimulator.simulizar.monitorrepository.map.runtimemeasurement.MonitorRepositoryMapRuntimeMeasurementsRecorder;

public class MonitorRepositoryMapRuntimeMeasurementsRecorderTest {

private static final double DELTA = Math.pow(10, -8);

private Map mapProcessingType;
private ExponentialSmoothing exponentialSmoothing;
private RuntimeMeasurementModel rmModel;
private MeasuringPoint measuringPoint;
private Monitor monitor;
private MeasurementSpecification spec;
private Measure<Double, Duration> pointInTime;
private MeasuringValue wrongMetricMeasurement;
private MeasuringValue correctMeasurement;

private InternalRuntimeMeasurementsRecorder rtMeasurementsRecorderUnderTest;

@Before
public void setUp() throws Exception {
this.measuringPoint = MeasuringpointFactory.eINSTANCE.createResourceURIMeasuringPoint();
this.measuringPoint.setStringRepresentation("MeasuringPoint");

this.monitor = MonitorRepositoryFactory.eINSTANCE.createMonitor();
this.monitor.setMeasuringPoint(this.measuringPoint);

this.spec = MonitorRepositoryFactory.eINSTANCE.createMeasurementSpecification();
this.spec.setMetricDescription(MetricDescriptionConstants.RESPONSE_TIME_METRIC);
this.spec.setMonitor(this.monitor);

this.exponentialSmoothing = MapFactory.eINSTANCE.createExponentialSmoothing();
this.exponentialSmoothing.setSmoothingFactor(0.5); // computes the arithmetic mean then

this.mapProcessingType = MapFactory.eINSTANCE.createMap();
this.mapProcessingType.setEntityName("Map Processing Type Response Time");
this.mapProcessingType.setMapper(this.exponentialSmoothing);
this.mapProcessingType.setOutputMetricDescription(MetricDescriptionConstants.RESPONSE_TIME_METRIC);
this.mapProcessingType.setMeasurementSpecification(this.spec);

this.rmModel = RuntimeMeasurementFactory.eINSTANCE.createRuntimeMeasurementModel();

this.rtMeasurementsRecorderUnderTest = new InternalRuntimeMeasurementsRecorder(this.rmModel,
this.mapProcessingType);

this.pointInTime = Measure.valueOf(10d, SI.SECOND);
this.correctMeasurement = new TupleMeasurement(MetricDescriptionConstants.RESPONSE_TIME_METRIC_TUPLE,
this.pointInTime, Measure.valueOf(1d / 60, NonSI.MINUTE)); // 1 second = 1/60 min
this.wrongMetricMeasurement = new TupleMeasurement(MetricDescriptionConstants.POWER_CONSUMPTION_TUPLE,
this.pointInTime, Measure.valueOf(42d, SI.WATT));
}

@Test(expected = NullPointerException.class)
public void testCtorNullArgument() {
new MonitorRepositoryMapRuntimeMeasurementsRecorder(null, this.mapProcessingType);
}

@Test(expected = NullPointerException.class)
public void testCtorNullArgument2() {
new MonitorRepositoryMapRuntimeMeasurementsRecorder(this.rmModel, null);
}

@Test(expected = IllegalStateException.class)
public void testCtorIllegalStateArgument() {
// use the response time metric set description to trigger the exception
this.mapProcessingType.setOutputMetricDescription(MetricDescriptionConstants.RESPONSE_TIME_METRIC_TUPLE);
new MonitorRepositoryMapRuntimeMeasurementsRecorder(this.rmModel, this.mapProcessingType);
}

@Test(expected = NullPointerException.class)
public void testNewMeasurementAvailableNullArgument() {
this.rtMeasurementsRecorderUnderTest.newMeasurementAvailable(null);
}

@Test(expected = IllegalStateException.class)
public void testNewMeasurementAvailableWrongMetric() {
this.rtMeasurementsRecorderUnderTest.newMeasurementAvailable(this.wrongMetricMeasurement);
}

@Test
public void testNewMeasurementAvailableCompatibleMetric() {
this.rtMeasurementsRecorderUnderTest.newMeasurementAvailable(this.correctMeasurement);
RuntimeMeasurement measurement = this.rtMeasurementsRecorderUnderTest.getMeasurement();

assertEquals(this.spec.getId(), measurement.getMeasurementSpecification().getId());
assertEquals(this.measuringPoint.getStringRepresentation(),
measurement.getMeasuringPoint().getStringRepresentation());
assertEquals(0.5, measurement.getMeasuringValue(), DELTA); // 0.5s

this.rtMeasurementsRecorderUnderTest.newMeasurementAvailable(this.correctMeasurement);
measurement = this.rtMeasurementsRecorderUnderTest.getMeasurement();
assertEquals(0.75, measurement.getMeasuringValue(), DELTA);
}

@Test
public void testPreUnregister() {
List<RuntimeMeasurement> allMeasurements = this.rtMeasurementsRecorderUnderTest.getModel().getMeasurements();
int size = allMeasurements.size();
this.rtMeasurementsRecorderUnderTest.preUnregister();

assertEquals(size - 1, this.rtMeasurementsRecorderUnderTest.getModel().getMeasurements().size());
assertFalse(this.rmModel.getMeasurements().contains(this.rtMeasurementsRecorderUnderTest.getMeasurement()));
}

private class InternalRuntimeMeasurementsRecorder extends MonitorRepositoryMapRuntimeMeasurementsRecorder {

public InternalRuntimeMeasurementsRecorder(final RuntimeMeasurementModel rmModel, final Map mapProcessingType) {
super(rmModel, mapProcessingType);
}

public RuntimeMeasurement getMeasurement() {
return super.getPRMMeasurement();
}

public RuntimeMeasurementModel getModel() {
return super.getPrmModel();
}

}
}
11 changes: 11 additions & 0 deletions tests/org.palladiosimulator.simulizar.reliability.tests/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
28 changes: 28 additions & 0 deletions tests/org.palladiosimulator.simulizar.reliability.tests/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.palladiosimulator.simulizar.reliability.tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Reliability Extension Tests
Bundle-SymbolicName: org.palladiosimulator.simulizar.reliability.tests
Bundle-Version: 5.2.0.qualifier
Fragment-Host: org.palladiosimulator.simulizar.reliability;bundle-version="5.2.0"
Automatic-Module-Name: org.palladiosimulator.simulizar.reliability.tests
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.palladiosimulator.simulizar.test.commons;bundle-version="5.0.0",
tools.mdsd.junit5utils;bundle-version="0.1.0",
de.uka.ipd.sdq.workflow,
org.palladiosimulator.metricspec,
org.palladiosimulator.edp2,
tools.mdsd.library.standalone.initialization;bundle-version="0.2.0",
org.palladiosimulator.pcm.resources;bundle-version="4.3.0",
de.uka.ipd.sdq.simulation.abstractsimengine.desmoj;bundle-version="4.3.0",
de.uka.ipd.sdq.errorhandling;bundle-version="4.3.0",
de.desmoj;bundle-version="2.3.3"
Import-Package: org.hamcrest;version="2.2.0",
org.junit.jupiter.api;version="5.7.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.palladiosimulator.simulizar.reliability.tests;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.closeTo;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.palladiosimulator.simulizar.test.commons.util.MeasurementTestUtils.allMeasurementsOfMetric;
import static org.palladiosimulator.simulizar.test.commons.util.MeasurementTestUtils.getMeasurementOfAt;

import org.junit.jupiter.api.Test;
import org.palladiosimulator.edp2.models.ExperimentData.ExperimentRun;
import org.palladiosimulator.measurementframework.measure.IdentifierMeasure;
import org.palladiosimulator.metricspec.constants.MetricDescriptionConstants;
import org.palladiosimulator.pcm.usagemodel.UsageScenario;
import org.palladiosimulator.simulizar.reliability.di.DaggerReliabilityExtensionComponent;
import org.palladiosimulator.simulizar.test.commons.annotation.LoadPCMInstanceFromBundle;
import org.palladiosimulator.simulizar.test.commons.annotation.RunSimuLizar;
import org.palladiosimulator.simulizar.test.commons.annotation.SimulationConfig;
import org.palladiosimulator.simulizar.test.commons.annotation.UseSimuLizarExtension;

import de.uka.ipd.sdq.workflow.jobs.JobFailedException;
import de.uka.ipd.sdq.workflow.jobs.UserCanceledException;
import tools.mdsd.junit5utils.annotations.PluginTestOnly;

@PluginTestOnly
class ExecutionResultTest {

@Test
@LoadPCMInstanceFromBundle(bundleName = "org.palladiosimulator.simulizar.reliability.tests", basePath = "testmodels/simulizar151", modelFiles = {
"default.allocation", "default.usagemodel", "My.monitorrepository" })
@UseSimuLizarExtension(DaggerReliabilityExtensionComponent.class)
@SimulationConfig(simulateReliability = true)
@RunSimuLizar
void testExecutionResultRecording(UsageScenario usageScenarion,ExperimentRun expRun)
throws JobFailedException, UserCanceledException {
var resultMeasurement = getMeasurementOfAt(expRun.getMeasurement(),
MetricDescriptionConstants.EXECUTION_RESULT_TYPE_TUPLE, usageScenarion);
assertTrue(resultMeasurement.isPresent());

var results = allMeasurementsOfMetric(resultMeasurement.get(), MetricDescriptionConstants.EXECUTION_RESULT_TYPE);

var noSuccesses = results.stream().map(IdentifierMeasure.class::cast).map(m -> m.getValue().getLiteral())
.filter(lit -> lit.equals(MetricDescriptionConstants.EXECUTION_RESULT_TYPE_SUCCESS.getLiteral())).count();
assertThat(noSuccesses * 1.0 / results.size(), is(closeTo(0.7d, 0.1)));
}

}
Loading

0 comments on commit d7d8953

Please sign in to comment.