Skip to content

Commit

Permalink
Add test for bug 42
Browse files Browse the repository at this point in the history
Also add method to clear all app objects

Tests #42
  • Loading branch information
rudi committed Nov 14, 2024
1 parent cceb835 commit 0667005
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public static synchronized NebulousApp remove(String uuid) {
return app;
}

/**
* Remove all application objects.
*/
public static synchronized void clear() {
apps.clear();
}

/**
* Return all currently registered apps.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ void readInvalidAppCreationMessage() throws IOException, URISyntaxException {

@Test
void readMultipleAppCreationMessages() throws IOException, URISyntaxException {
NebulousApps.clear(); // We are not restarted between tests, so app
// objects can accumulate; reset state
NebulousApp app = appFromTestFile("app-creation-message-mercabana.json");
NebulousApp app2 = appFromTestFile("app-message-2.json");
assertTrue(NebulousApps.values().size() == 2);
assertTrue(NebulousApps.values().size() == 2,
"Expected 2 app objects but got " + NebulousApps.values().size());
}

@Test
Expand Down Expand Up @@ -149,4 +152,12 @@ void checkComponentPlacements() throws IOException, URISyntaxException {
assertEquals(NebulousAppDeployer.getComponentLocation(kubevela.at("/spec/components/3")), NebulousAppDeployer.ComponentLocationType.EDGE_AND_CLOUD); // default unspecified
}

@Test
void bug42() throws IOException, URISyntaxException {
// https://github.com/eu-nebulous/optimiser-controller/issues/42
NebulousApp app = appFromTestFile("bug-42-app-creation-message.json");
JsonNode solverMessage = app.calculateAMPLMessage();
assertEquals(solverMessage.at("/Constants/deployed_memory/Value").asLong(), 8192L);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"title":"Augmenta-202411041708 Copy Copy",
"status":"draft",
"content":"apiVersion: core.oam.dev/v1beta1\nkind: Application\nmetadata:\n name: augmenta-app\nspec:\n components:\n - name: data-preparation-demo\n type: webservice\n properties:\n image: 'augmentacloud/map-generation:data_preparation_demo'\n imagePullPolicy: Always\n imagePullSecrets: [\"xxxx\"]\n cpu: \"4\"\n memory: \"8Gi\"\n env:\n - name: BROKER_SERVER\n valueFrom:\n fieldRef:\n fieldPath: status.hostIP\n - name: BROKER_PASSWORD\n value: \"xxxx\"\n - name: BROKER_USERNAME\n value: \"xxxx\"\n - name: map-generation-demo\n type: webservice\n properties:\n image: 'augmentacloud/map-generation:latest'\n imagePullPolicy: Always\n imagePullSecrets: [\"xxxx\"]\n cpu: '4'\n memory: \"8Gi\"\n env:\n - name: BROKER_SERVER\n valueFrom:\n fieldRef:\n fieldPath: status.hostIP\n - name: BROKER_PASSWORD\n value: \"xxxx\"\n - name: BROKER_USERNAME\n value: \"xxxx\"\n traits:\n - type: scaler\n properties:\n replicas: 1",
"variables":[
{"key":"spec_components_1_properties_cpu",
"path":"/spec/components/1/properties/cpu",
"type":"float",
"meaning":"cpu",
"value": {"lower_bound":8,"higher_bound":10}},
{"key":"spec_components_1_properties_memory",
"path":"/spec/components/1/properties/memory",
"type":"float",
"meaning":"memory",
"value":{"lower_bound":2400,"higher_bound":12000}},
{"key":"spec_components_1_traits_0_properties_replicas",
"path":"/spec/components/1/traits/0/properties/replicas",
"type":"float",
"meaning":"replicas",
"value":{
"lower_bound":1,
"higher_bound":5}}],
"environmentVariables":[],
"resources":[{"title":"aws-eut-20241121356",
"uuid":"48598ce1-8f8b-402a-9035-44a8553bba98",
"platform":"AWS",
"enabled":true,
"regions":"us-east-1"}],
"templates":[],
"parameters":[],
"metrics":[
{"type":"raw",
"name":"processing_time_minus_ha",
"level":"global",
"components":[],"sensor":"",
"config":[],
"isWindowOutputRaw":true,
"outputRaw":{"type":"all",
"interval":0,"unit":"ms",
"metaType":"object",
"scopedObjectName":"doc.application.outputRaw"},
"_id":"cm3emhkzc000s01w12hm23crn",
"metaType":"arrayItem",
"scopedArrayName":"doc.application.metrics",
"_docId":"cm3emhkza000i01w1d2cc86o0:en:published",
"_edit":true},
{"type":"raw",
"name":"field_area",
"level":"global",
"components":[],"sensor":"",
"config":[],
"isWindowOutputRaw":true,
"outputRaw":{"type":"all",
"interval":0,"unit":"ms",
"metaType":"object",
"scopedObjectName":"doc.application.outputRaw"},
"_id":"cm3emhkzc000t01w1aw404zt5",
"metaType":"arrayItem",
"scopedArrayName":"doc.application.metrics",
"_docId":"cm3emhkza000i01w1d2cc86o0:en:published",
"_edit":true},
{"type":"raw",
"name":"session_predicted_memory_mb",
"level":"global",
"components":[],"sensor":"",
"config":[],
"isWindowOutputRaw":true,
"outputRaw":{"type":"all",
"interval":0,"unit":"ms",
"metaType":"object",
"scopedObjectName":"doc.application.outputRaw"},
"_id":"cm3emhkzc000u01w167va8jn4",
"metaType":"arrayItem",
"scopedArrayName":"doc.application.metrics",
"_docId":"cm3emhkza000i01w1d2cc86o0:en:published",
"_edit":true}],
"sloViolations":{
"nodeKey":"9f69529f-f345-48e8-b0ac-e6f5cc1b4e46",
"isComposite":true,
"condition":"AND",
"not":false,
"children":[{"nodeKey":"d1949d20-61a3-426b-8cdd-64109ad2e231",
"isComposite":false,
"metricName":"processing_time_minus_ha",
"operator":"<",
"value":0},
{"nodeKey":"7372b55b-577c-4139-ae10-c76a31013bef",
"isComposite":false,
"metricName":"processing_time_minus_ha",
"operator":">",
"value":60}]},
"utilityFunctions":[
{
"name":"deployed_memory",
"type":"constant",
"expression": {
"formula":"a",
"variables":[
{
"name":"a",
"value":"spec_components_1_properties_memory"
}
]
}
},
{
"name":"utility",
"type":"maximize",
"expression":{
"formula":"1/exp(0.00000002*(Current_RAM - Optimal_RAM)^2)",
"variables":[
{
"name":"Current_RAM",
"value":"deployed_memory"
},
{
"name":"Optimal_RAM",
"value":"spec_components_1_properties_memory"
}
]
}
}
],
"uuid":"9dba01a2-0725-4202-b676-cc64eb7b75f4",
"_create":true,
"_delete":true
}

0 comments on commit 0667005

Please sign in to comment.