Commit 899503ed authored by hengwen's avatar hengwen
Browse files

Debugging test

parent bfcd41a5
Pipeline #188325 failed with stage
in 6 minutes and 27 seconds
......@@ -62,7 +62,7 @@ cd ${CURR_DIR}
docker run \
--rm --network="simulation-network" \
-e "ZOO_SERVERS=zookeeper" \
montisim-server-builder sh -c "cd restful && mvn test -Dtest=MapServiceTest -s ../settings.xml" \
montisim-server-builder sh -c "cd restful && mvn test -s ../settings.xml" \
2>&1 | tee result.txt
dockerCleanUp
......
......@@ -3,19 +3,12 @@ package server.restful.service;
import junit.framework.TestCase;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.restful.dao.MapDAO;
import server.restful.dao.ScenarioDAO;
import server.restful.dao.SimulationDAO;
import server.restful.model.Dataframe;
import server.restful.model.ScenarioModel;
import server.restful.registry.RegistryFactory;
import server.restful.util.Util;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Properties;
public class SimulationServiceTest extends TestCase {
......@@ -30,38 +23,38 @@ public class SimulationServiceTest extends TestCase {
*
* @throws FileNotFoundException
*/
@Test
public void testSimulation() throws Exception {
Logger logger = LoggerFactory.getLogger(SimulationServiceTest.class);
ScenarioModel scenario = ScenarioService.saveScenario(
new FileInputStream(getClass().getResource("/chargingstation.sim").getPath()),
"uploaded.sim"
);
int mapID = MapDAO.create("chargingstation.osm", getClass().getResource("/chargingstation.osm").getPath());
int simID = SimulationDAO.create(scenario.getId(), 1);
SimulationService sim = new SimulationService(simID);
sim.startSimulation(RegistryFactory.getZookeeperRegistry());
// wait for battery to be charged from 19% to 100%, it will take some time...
// if we can set the charging battery target to a lower value rather than 100%,
// it will be much quicker.
while(!sim.isSimulationFinished()){
logger.info("Waiting for simulation result...");
Thread.sleep(5000);
}
List<Dataframe> frames = sim.getResult().get(0).getFrames();
// expect 1 vehicle
assertEquals(1, sim.getResult().size());
assertTrue(frames.size() > 0);
double initialBattery = frames.get(0).getBattery();
double finalBattery = frames.get(frames.size() - 1).getBattery();
// after charging, final battery percentage should be higher than initial
assertTrue(finalBattery > initialBattery);
}
// @Test
// public void testSimulation() throws Exception {
// Logger logger = LoggerFactory.getLogger(SimulationServiceTest.class);
// ScenarioModel scenario = ScenarioService.saveScenario(
// new FileInputStream(getClass().getResource("/chargingstation.sim").getPath()),
// "uploaded.sim"
// );
// int mapID = MapDAO.create("chargingstation.osm", getClass().getResource("/chargingstation.osm").getPath());
// int simID = SimulationDAO.create(scenario.getId(), 1);
// SimulationService sim = new SimulationService(simID);
//
// sim.startSimulation(RegistryFactory.getZookeeperRegistry());
//
// // wait for battery to be charged from 19% to 100%, it will take some time...
// // if we can set the charging battery target to a lower value rather than 100%,
// // it will be much quicker.
// while(!sim.isSimulationFinished()){
// logger.info("Waiting for simulation result...");
// Thread.sleep(5000);
// }
//
// List<Dataframe> frames = sim.getResult().get(0).getFrames();
//
// // expect 1 vehicle
// assertEquals(1, sim.getResult().size());
// assertTrue(frames.size() > 0);
//
// double initialBattery = frames.get(0).getBattery();
// double finalBattery = frames.get(frames.size() - 1).getBattery();
// // after charging, final battery percentage should be higher than initial
// assertTrue(finalBattery > initialBattery);
// }
@Test
public void testConfig() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment