Commit 61f59d7b authored by hengwen's avatar hengwen
Browse files

New test with electric vehicle

parent c04cca21
......@@ -6,31 +6,59 @@ import org.junit.Test;
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 {
// @Test
// public void testSimulation() {
// int scenarioID = ScenarioDAO.create("straight.sim", getClass().getResource("/straight.sim").getPath());
// int mapID = MapDAO.create("straight.osm", getClass().getResource("/straight.osm").getPath());
// int simID = SimulationDAO.create(scenarioID, 1);
// SimulationService sim = new SimulationService(simID);
// try {
// sim.startSimulation(RegistryFactory.getZookeeperRegistry());
// sim.getResult();
// assertEquals(1, sim.getResult().size());
// assertTrue(sim.getResult().get(0).getFrames().size() > 0);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
/**
* This test will execute a complete simulation task using chargingstation.sim.
* In the simulation, we create a vehicle with 19.9% initial battery percentage.
* It will
* 1. query the restful server for the nearest charging station
* 2. re-plan its trajectory to drive there
* 3. after it's fully charged (battery > 99%), drive to its original destination
*
* @throws FileNotFoundException
*/
@Test
public void testSimulation() throws Exception {
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()){
System.out.println("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