Skip to content
Snippets Groups Projects
Commit 4f8ebc0c authored by erbel's avatar erbel
Browse files

Enhance simulation to accept properties written in single quotes

parent d085d895
No related branches found
No related tags found
No related merge requests found
Pipeline #172997 passed
CPU = None,Low,Medium,High,Critical,3000
Mem = None1,Low1,Medium1,High1,Critical1,4000
MecoTaskResultWhile = false,false,false,true,2000
MecoTaskResultForEach = var0;var1;var2;var3;var4;var5;var6,var10;var11;var12;var13;var14;var15;var16,var20;var21;var22;var23;var24;var25;var26,2000
CoarseResult = qa,qa,qa,picking,picking,3000
\ No newline at end of file
CPU=None,Low,Medium,High,Critical,3000
Mem=None1,Low1,Medium1,High1,Critical1,4000
MecoTaskResultWhile=false,false,false,true,2000
MecoTaskResultForEach='var0,var1,var2,var3,var4,var5,var6','var10,var11,var12,var13,var14,var15,var16','var20,var21,var22,var23,var24,var25,var26',2000
CResult=qa,qa,qa,picking,picking,3000
\ No newline at end of file
......@@ -15,6 +15,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.cmf.occi.core.AttributeState;
import org.eclipse.cmf.occi.core.impl.OCCIFactoryImpl;
......@@ -33,9 +35,21 @@ public class ResultproviderSimulation implements Runnable {
public ResultproviderSimulation(Monitorableproperty monProp) {
this.monProp = monProp;
String property = getProperty(monProp.getMonitoringProperty());
LOGGER.info("Monitoring property for" + monProp.getMonitoringProperty() + ": " + property);
List<String> items = new ArrayList<String>(Arrays.asList(property.split("\\s*,\\s*")));
this.interval = Integer.parseInt(items.get(items.size() - 1));
items.remove(items.get(items.size() - 1));
String itemsString = String.join(",", items);
Pattern p = Pattern.compile("\'([^\']*)\'");
Matcher m = p.matcher(itemsString);
if (m.find() == true) {
items.clear();
while (m.find()) {
items.add(m.group(1));
}
}
this.results = items;
LOGGER.info("Creating Simulation for: " + monProp.getMonitoringProperty() + "; with values: " + results
+ "; and interval: " + interval);
......
......@@ -52,7 +52,25 @@ public class ResultproviderTest {
e.printStackTrace();
}
assertTrue(monProp.getMonitoringResult() != null);
assertFalse(monProp.getMonitoringResult().contains(","));
}
@Test
public void startSimulationWithSensorQuotes() {
Resultprovider rp = createResultprovider(Status.UNDEPLOYED);
Monitorableproperty monProp = getMonProp(getSensor(rp));
monProp.setMonitoringProperty("MecoTaskResultForEach");
assertTrue(monProp.getMonitoringResult() == null);
rp.start();
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertTrue(monProp.getMonitoringResult().contains(","));
}
@Test
......
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