use of org.eclipse.winery.repository.targetallocation.util.TopologyWrapper in project winery by eclipse.
the class KargerMinCutVariationTest method twoTargetLabelsOnePossibleResult.
@Test
public void twoTargetLabelsOnePossibleResult() {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "MinExternalConnectionsTest1", false);
TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
ConnectsToGraph connectsToGraph = new ConnectsToGraph(topology);
KargerMinCutVariation kargerMinCutVariation = new KargerMinCutVariation(connectsToGraph);
List<ConnectsToGraph> results = new ArrayList<>(kargerMinCutVariation.computeTargetLabelPartitions());
// testing a monte carlo algorithm doesn't always work
if (results.size() != 1 || results.get(0).getEdges().size() != 1) {
LOGGER.debug("Monte Carlo Algorithm produced wrong result");
return;
}
assertEquals(results.size(), 1);
ConnectsToGraph result = results.get(0);
assertEquals(result.getEdges().size(), 1);
assertEquals(result.getNodes().size(), 2);
Set<String> pastureProvider = new HashSet<>(Collections.singletonList("shetland_pony"));
Set<String> fieldProvider = new HashSet<>(Arrays.asList("shetland_pony_2", "shetland_pony_3", "shetland_pony_4"));
ConnectsToGraph.Node pastureNode = result.getNodes().stream().filter(node -> node.getTargetLabel().equalsIgnoreCase("PastureProvider")).collect(Collectors.toList()).get(0);
ConnectsToGraph.Node fieldNode = result.getNodes().stream().filter(node -> node.getTargetLabel().equalsIgnoreCase("FieldProvider")).collect(Collectors.toList()).get(0);
assertEquals(pastureNode.getNodeTemplateIds(), pastureProvider);
assertEquals(fieldNode.getNodeTemplateIds(), fieldProvider);
}
use of org.eclipse.winery.repository.targetallocation.util.TopologyWrapper in project winery by eclipse.
the class KargerMinCutVariationTest method performanceTest.
@Test
public void performanceTest() {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "MinExternalConnectionsTest2", false);
TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
ConnectsToGraph connectsToGraph = new ConnectsToGraph(topology);
KargerMinCutVariation kargerMinCutVariation = new KargerMinCutVariation(connectsToGraph);
List<ConnectsToGraph> results = new ArrayList<>(kargerMinCutVariation.computeTargetLabelPartitions());
// testing a monte carlo algorithm doesn't always work
if (results.size() != 4 || results.get(0).getEdges().size() != 4) {
LOGGER.debug("Monte Carlo Algorithm produced wrong result");
return;
}
assertEquals(results.size(), 4);
assertEquals(results.get(0).getEdges().size(), 4);
assertEquals(results.get(1).getEdges().size(), 4);
assertEquals(results.get(2).getEdges().size(), 4);
assertEquals(results.get(3).getEdges().size(), 4);
}
use of org.eclipse.winery.repository.targetallocation.util.TopologyWrapper in project winery by eclipse.
the class MinHostsTest method testOneTargetLabelPresent.
@Test
public void testOneTargetLabelPresent() throws Exception {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest2", false);
TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
List<TopologyWrapper> topologies = minHosts.allocate(topology);
assertEquals(1, topologies.size());
TTopologyTemplate topology1 = topologies.get(0).getTopology();
assertEquals(7, topology1.getNodeTemplateOrRelationshipTemplate().size());
List<String> types1 = new ArrayList<>();
for (TNodeTemplate nodeTemplate : topology1.getNodeTemplates()) {
types1.add(nodeTemplate.getType().getLocalPart());
}
assertEquals(4, types1.size());
assertEquals(3, types1.stream().filter(type -> type.equalsIgnoreCase("shetland_pony")).count());
assertEquals(1, types1.stream().filter(type -> type.equalsIgnoreCase("pasture")).count());
for (TNodeTemplate nodeTemplate : topologies.get(0).getTopLevelNTs()) {
assertEquals("pasture", topologies.get(0).getHostedOnSuccessor(nodeTemplate).getType().getLocalPart());
}
}
use of org.eclipse.winery.repository.targetallocation.util.TopologyWrapper in project winery by eclipse.
the class MinHostsTest method testTwoTargetLabelsPresent.
@Test
public void testTwoTargetLabelsPresent() throws Exception {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest3", false);
TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
List<TopologyWrapper> topologies = minHosts.allocate(topology);
assertEquals(2, topologies.size());
TTopologyTemplate topology1 = topologies.get(0).getTopology();
TTopologyTemplate topology2 = topologies.get(1).getTopology();
assertEquals(8, topology1.getNodeTemplateOrRelationshipTemplate().size());
assertEquals(8, topology2.getNodeTemplateOrRelationshipTemplate().size());
List<String> types1 = new ArrayList<>();
for (TNodeTemplate nodeTemplate : topology1.getNodeTemplates()) {
types1.add(nodeTemplate.getType().getLocalPart());
}
assertEquals(5, types1.size());
assertEquals(3, types1.stream().filter(type -> type.equalsIgnoreCase("shetland_pony")).count());
assertEquals(1, types1.stream().filter(type -> type.equalsIgnoreCase("pasture")).count());
assertEquals(1, types1.stream().filter(type -> type.equalsIgnoreCase("field_-w1-wip1")).count());
for (TNodeTemplate nodeTemplate : topologies.get(0).getTopLevelHosts()) {
List<TNodeTemplate> predecessors = topologies.get(0).getHostedOnPredecessors(nodeTemplate);
if (nodeTemplate.getType().getLocalPart().equalsIgnoreCase("pasture")) {
assertEquals(predecessors.size(), 2);
} else if (nodeTemplate.getType().getLocalPart().equalsIgnoreCase("field")) {
assertEquals(predecessors.size(), 1);
}
}
List<String> types2 = new ArrayList<>();
for (TNodeTemplate nodeTemplate : topology2.getNodeTemplates()) {
types2.add(nodeTemplate.getType().getLocalPart());
}
assertEquals(5, types2.size());
assertEquals(3, types2.stream().filter(type -> type.equalsIgnoreCase("shetland_pony")).count());
assertEquals(1, types2.stream().filter(type -> type.equalsIgnoreCase("pasture")).count());
assertEquals(1, types2.stream().filter(type -> type.equalsIgnoreCase("field_-w1-wip1")).count());
for (TNodeTemplate nodeTemplate : topologies.get(1).getTopLevelHosts()) {
List<TNodeTemplate> predecessors = topologies.get(1).getHostedOnPredecessors(nodeTemplate);
if (nodeTemplate.getType().getLocalPart().equalsIgnoreCase("pasture")) {
assertEquals(predecessors.size(), 1);
} else if (nodeTemplate.getType().getLocalPart().equalsIgnoreCase("field")) {
assertEquals(predecessors.size(), 2);
}
}
}
use of org.eclipse.winery.repository.targetallocation.util.TopologyWrapper in project winery by eclipse.
the class MinHostsTest method testFilter.
@Test
public void testFilter() throws Exception {
List<TopologyWrapper> topologies = new ArrayList<>();
for (int i = 1; i < 5; i++) {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest" + i, false);
topologies.add(new TopologyWrapper(repository.getElement(id).getTopologyTemplate()));
}
assertEquals(4, topologies.size());
Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
List<TopologyWrapper> filtered = minHosts.filter(topologies);
assertEquals(2, filtered.size());
assertEquals(5, filtered.get(0).getNodeTemplates().size());
}
Aggregations