From e5106cd6c015e1546c9e4ca972eefbcac0dcc8d6 Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Wed, 27 Sep 2023 16:16:23 +0200 Subject: [PATCH] Fixed test to be able to be executed on OS different from linux --- .../instances/SmartgearResourcesTest.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/SmartgearResourcesTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/SmartgearResourcesTest.java index 8a7ad83..bdcaade 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/SmartgearResourcesTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/SmartgearResourcesTest.java @@ -445,6 +445,37 @@ public class SmartgearResourcesTest extends ERManagementTest { public static final String CPU_MODEL_B = "model\b"; public static final String CPU_MODEL_NUMBER = "modelNumber"; + + public static List getFakeCPUFacets() { + List cpuFacets = new ArrayList<>(); + + if(cpuFacets.size()==0) { + for(int i=0; i<8; i++) { + CPUFacet cpuFacet = new CPUFacetImpl(); + cpuFacet.setVendor("Apple"); + cpuFacet.setModel("Apple M2 Pro"); + cpuFacet.setClockSpeed("3,504 GHz"); + cpuFacet.setAdditionalProperty("coreType", "Performance Cores (Avalanche)"); + cpuFacets.add(cpuFacet); + } + for(int i=0; i<4; i++) { + CPUFacet cpuFacet = new CPUFacetImpl(); + cpuFacet.setVendor("Apple"); + cpuFacet.setModel("Apple M2 Pro"); + cpuFacet.setClockSpeed("2.424 GHz"); + cpuFacet.setAdditionalProperty("coreType", "Efficiency Cores (Blizzard)"); + cpuFacets.add(cpuFacet); + + } + } + return cpuFacets; + } + + /** + * This function properly works on Linux but fails on + * other system such as Mac OS. In such case, the function + * getFakeCPUFacet() is used instead; + */ public static List getCPUFacets() { List cpuFacets = new ArrayList<>(); @@ -453,7 +484,7 @@ public class SmartgearResourcesTest extends ERManagementTest { if (!file.exists()) { logger.warn("cannot acquire CPU info (no /proc/cpuinfo)"); - return cpuFacets; + return getFakeCPUFacets(); } BufferedReader input = null; @@ -531,6 +562,11 @@ public class SmartgearResourcesTest extends ERManagementTest { } } } + + if(cpuFacets.size()==0) { + return getFakeCPUFacets(); + } + return cpuFacets; } }