diff --git a/build.gradle b/build.gradle index a574fcfe..882f49e8 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,7 @@ configurations { dependencies { configurations.implementation.extendsFrom(configurations.extraLibs) - api 'com.google.code.gson:gson:2.8.9' + api 'com.google.code.gson:gson:2.10.1' api 'net.openhft:compiler:2.3.0' // Used by representation/owrl/CodeBuilder.java api group: 'org.json', name: 'json', version: '20230227' api group: 'org.opt4j', name: 'opt4j-core', version: '3.1' // Used in GLAS diff --git a/src/test/java/br/unicamp/cst/core/entities/MemoryBufferTest.java b/src/test/java/br/unicamp/cst/core/entities/MemoryBufferTest.java index 9f064e73..0cfc5e4a 100644 --- a/src/test/java/br/unicamp/cst/core/entities/MemoryBufferTest.java +++ b/src/test/java/br/unicamp/cst/core/entities/MemoryBufferTest.java @@ -123,8 +123,9 @@ public void pintStatusTest(){ System.setOut(new PrintStream(outputStreamCaptor)); memoryBuffer.printStatus(); + String s = outputStreamCaptor.toString().trim().replaceAll("\r\n", "\n"); - assertTrue(outputStreamCaptor.toString().trim().contains(expectedMessage)); + assertTrue(outputStreamCaptor.toString().replaceAll("\r\n", "\n").trim().contains(expectedMessage)); } } diff --git a/src/test/java/br/unicamp/cst/core/profiler/TestMemoryObserver.java b/src/test/java/br/unicamp/cst/core/profiler/TestMemoryObserver.java index bc3a0abc..3b16e393 100644 --- a/src/test/java/br/unicamp/cst/core/profiler/TestMemoryObserver.java +++ b/src/test/java/br/unicamp/cst/core/profiler/TestMemoryObserver.java @@ -18,11 +18,11 @@ import br.unicamp.cst.core.entities.MemoryObject; import br.unicamp.cst.core.entities.Mind; import br.unicamp.cst.core.exceptions.CodeletActivationBoundsException; -import br.unicamp.cst.support.TimeStamp; import java.util.logging.Level; import java.util.logging.Logger; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import org.junit.jupiter.api.Test; class CodeletToTest extends Codelet { @@ -367,18 +367,26 @@ public void proc() { //setI in Memory Container and verify if Codelet was notified long ts = output.getTimestamp(); input.setI(0); - while(ts == output.getTimestamp()); + long startwait = System.currentTimeMillis(); + while(ts == output.getTimestamp()) { + if (System.currentTimeMillis() - startwait > 2000) { + System.out.println("Restarting timer due to inactivity"); + c.start(); + } + if (System.currentTimeMillis() - startwait > 5000) fail("Some problem have occurred 3 !"); + } int nout = (int) output.getI(); System.out.println("Result: "+output.getI()); assertEquals(nout,1); c.setPublishSubscribe(false); ts = output.getTimestamp(); - long startwait = System.currentTimeMillis(); + startwait = System.currentTimeMillis(); while(ts == output.getTimestamp()) { if (System.currentTimeMillis() - startwait > 2000) { System.out.println("Restarting timer due to inactivity"); - c.start(); + m.start(); } + if (System.currentTimeMillis() - startwait > 5000) fail("Some problem have occurred 4 !"); } System.out.println("Result: "+output.getI()+" "+c.getActivation()); m.shutDown(); @@ -432,18 +440,26 @@ public void proc() { //setI in Memory Container and verify if Codelet was notified long ts = output.getTimestamp(); input.setI(0,0); - while(ts == output.getTimestamp()); + while(ts == output.getTimestamp()) System.out.print("."); + long startwait = System.currentTimeMillis(); + while(ts == output.getTimestamp()) { + if (System.currentTimeMillis() - startwait > 2000) { + System.out.println("I am waiting too long ... something wrong happened"); + } + if (System.currentTimeMillis() - startwait > 5000) fail("Some problem have occurred 1 !"); + } int nout = (int) output.getI(); System.out.println("Result: "+output.getI()+" "+c.getActivation()); assertEquals(nout,1); c.setPublishSubscribe(false); ts = output.getTimestamp(); - long startwait = System.currentTimeMillis(); + startwait = System.currentTimeMillis(); while(ts == output.getTimestamp()) { if (System.currentTimeMillis() - startwait > 2000) { System.out.println("Restarting timer due to inactivity"); - c.start(); + m.start(); } + if (System.currentTimeMillis() - startwait > 5000) fail("Some problem have occurred 2 !"); } System.out.println("Result: "+output.getI()+" "+c.getActivation()); diff --git a/src/test/java/br/unicamp/cst/io/rest/TestREST.java b/src/test/java/br/unicamp/cst/io/rest/TestREST.java index 47a4b31e..1a28c7ea 100644 --- a/src/test/java/br/unicamp/cst/io/rest/TestREST.java +++ b/src/test/java/br/unicamp/cst/io/rest/TestREST.java @@ -325,6 +325,7 @@ public void testRest1() { tr.StartTimer(); System.out.println("Creating a server in port "+port); RESTServer rs = new RESTServer(tr.m,port,true); + try {Thread.sleep(500);} catch (Exception e){}; processTest(); } @@ -339,6 +340,7 @@ public void testRest2() { tr.StartTimer(); System.out.println("Creating a server in port "+port); RESTServer rs = new RESTServer(tr.m,port); + try {Thread.sleep(500);} catch (Exception e){}; processTest(); } @@ -353,6 +355,7 @@ public void testRest3() { tr.StartTimer(); System.out.println("Creating a server in port "+port); RESTServer rs = new RESTServer(tr.m,port,true,"*"); + try {Thread.sleep(500);} catch (Exception e){}; processTest(); } @@ -367,6 +370,7 @@ public void testRest4() { tr.StartTimer(); System.out.println("Creating a server in port "+port); RESTServer rs = new RESTServer(tr.m,port,true); + try {Thread.sleep(500);} catch (Exception e){}; processTestWithoutGroups(); } @@ -381,6 +385,7 @@ public void testRest5() { tr.StartTimer(); System.out.println("Creating a server in port "+port); RESTServer rs = new RESTServer(tr.m,port); + try {Thread.sleep(500);} catch (Exception e){}; processTestWithoutGroups(); } @@ -395,6 +400,7 @@ public void testRest6() { tr.StartTimer(); System.out.println("Creating a server in port "+port); RESTServer rs = new RESTServer(tr.m,port,true,"*"); + try {Thread.sleep(500);} catch (Exception e){}; processTestWithoutGroups(); } @@ -409,6 +415,7 @@ public void testRest7() { tr.StartTimer(); System.out.println("Creating a server in port "+port); RESTServer rs = new RESTServer(tr.m,port,true,"*",500L); + try {Thread.sleep(500);} catch (Exception e){}; processTest(); } @@ -423,6 +430,7 @@ public void testRest8() { tr.StartTimer(); System.out.println("Creating a server in port "+port); RESTServer rs = new RESTServer(tr.m,port,true,"*",500L); + try {Thread.sleep(500);} catch (Exception e){}; processTestWithoutGroups(); } @@ -437,42 +445,43 @@ public void testRestRawMemory() { tr.StartTimer(); System.out.println("Creating a server in port "+port); RESTServer rs = new RESTServer(tr.m,port,true,"*",500L); + try {Thread.sleep(500);} catch (Exception e){}; String mes = sendGET(); - System.out.println(mes); + System.out.println("Test 1: "+mes); long m0 = tr.m.getRawMemory().getAllMemoryObjects().get(0).getId(); GET_URL = "http://localhost:"+port+"/rawmemory/"+m0; mes = sendGET(); - System.out.println(mes); + System.out.println("Test 2: "+mes); GET_URL = "http://localhost:"+port+"/rawmemory/"+m0+"/I"; mes = sendGET(); - System.out.println(mes); + System.out.println("Test 3: "+mes); GET_URL = "http://localhost:"+port+"/rawmemory/"+m0+"/timestamp"; mes = sendGET(); - System.out.println(mes); + System.out.println("Test 4: "+mes); GET_URL = "http://localhost:"+port+"/rawmemory/"+m0+"/evaluation"; mes = sendGET(); - System.out.println(mes); + System.out.println("Test 5: "+mes); GET_URL = "http://localhost:"+port+"/rawmemory/"+m0+"/name"; mes = sendGET(); - System.out.println(mes); + System.out.println("Test 6: "+mes); GET_URL = "http://localhost:"+port+"/rawmemory/"+m0+"/id"; mes = sendGET(); - System.out.println(mes); + System.out.println("Test 7: "+mes); GET_URL = "http://localhost:"+port+"/rawmemory/7"; mes = sendGET(); - System.out.println(mes); + System.out.println("Test 8: "+mes); assertEquals(mes,"Not Found"); GET_URL = "http://localhost:"+port+"/rawmemory/whatever"; mes = sendGET(); - System.out.println(mes); + System.out.println("Test 9: "+mes); assertEquals(mes,"Not Found"); GET_URL = "http://localhost:"+port+"/rawmemory/"+m0+"/whatever"; mes = sendGET(); - System.out.println(mes); + System.out.println("Test 10: "+mes); assertEquals(mes,"Not Found"); GET_URL = "http://localhost:"+port+"/rawmemory/whatever/whatever"; mes = sendGET(); - System.out.println(mes); + System.out.println("Test 11: "+mes); assertEquals(mes,"Not Found"); //processTestWithoutGroups(); } diff --git a/src/test/java/br/unicamp/cst/representation/idea/TestIdea.java b/src/test/java/br/unicamp/cst/representation/idea/TestIdea.java index 38e18e22..327f7eb7 100644 --- a/src/test/java/br/unicamp/cst/representation/idea/TestIdea.java +++ b/src/test/java/br/unicamp/cst/representation/idea/TestIdea.java @@ -23,6 +23,7 @@ import br.unicamp.cst.core.profiler.TestComplexMemoryObjectInfo; import br.unicamp.cst.support.TimeStamp; import java.util.HashMap; +import java.util.Locale; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import org.junit.jupiter.api.Test; @@ -85,6 +86,7 @@ public void testGet() { @Test public void testIdea() { + Locale.setDefault(Locale.US); System.out.println("\n Starting the testIdea ..."); Idea ln = new Idea("a"); Idea ln2 = new Idea("b"); @@ -260,6 +262,7 @@ public void testIdea2() { @Test public void testIsMethods() { + Locale.setDefault(Locale.US); Idea i = new Idea(); i.setName("test"); assertEquals(i.getName(),"test"); diff --git a/src/test/java/br/unicamp/cst/support/ToStringTest.java b/src/test/java/br/unicamp/cst/support/ToStringTest.java index 2c842bf0..680f11fc 100644 --- a/src/test/java/br/unicamp/cst/support/ToStringTest.java +++ b/src/test/java/br/unicamp/cst/support/ToStringTest.java @@ -10,6 +10,7 @@ * **********************************************************************************************/ package br.unicamp.cst.support; import java.util.Date; +import java.util.Locale; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; @@ -21,6 +22,7 @@ public class ToStringTest { @Test public void testFrom() { + Locale.setDefault(Locale.US); Object o = null; String s = ToString.from(o); assertEquals(s,"");