@Override public GraphHopperStorage createGHStorage(String location, boolean enabled3D) { // reduce segment size in order to test the case where multiple segments come into the game GraphHopperStorage gs = newGHStorage(new RAMDirectory(location), enabled3D); gs.setSegmentSize(defaultSize / 2); gs.create(defaultSize); return gs; }
@Test public void testDoThrowExceptionIfDimDoesNotMatch() { graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), false); graph.create(1000); graph.flush(); graph.close(); graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), true); try { graph.loadExisting(); assertTrue(false); } catch (Exception ex) { } }
@Test public void testSave_and_Freeze() throws IOException { graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), true).create(defaultSize); graph.edge(1, 0); graph.freeze(); graph.flush(); graph.close(); graph = newGHStorage(new MMapDirectory(defaultGraphLoc), true); assertTrue(graph.loadExisting()); assertEquals(2, graph.getNodes()); assertTrue(graph.isFrozen()); }
@Test public void testEnsureSize() { Directory dir = new RAMDirectory(); graph = newGHStorage(dir, false).create(defaultSize); int roughEdgeRowLength = 4 * 8; int testIndex = dir.find("edges", DAType.RAM_INT).getSegmentSize() * 3 / roughEdgeRowLength; // we need a big node index to trigger multiple segments, but low enough to avoid OOM graph.edge(0, testIndex, 10, true); // test if optimize works without error graph.optimize(); }
@Test public void testSave_and_fileFormat() throws IOException { graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), true).create(defaultSize); NodeAccess na = graph.getNodeAccess(); assertTrue(na.is3D()); na.setNode(0, 10, 10, 0); na.setNode(1, 11, 20, 1); na.setNode(2, 12, 12, 0.4); EdgeIteratorState iter2 = graph.edge(0, 1, 100, true); iter2.setWayGeometry(Helper.createPointList3D(1.5, 1, 0, 2, 3, 0)); EdgeIteratorState iter1 = graph.edge(0, 2, 200, true); iter1.setWayGeometry(Helper.createPointList3D(3.5, 4.5, 0, 5, 6, 0)); graph.edge(9, 10, 200, true); graph.edge(9, 11, 200, true); graph.edge(1, 2, 120, false); iter1.setName("named street1"); iter2.setName("named street2"); checkGraph(graph); graph.flush(); graph.close(); graph = newGHStorage(new MMapDirectory(defaultGraphLoc), true); assertTrue(graph.loadExisting()); assertEquals(12, graph.getNodes()); checkGraph(graph); assertEquals("named street1", graph.getEdgeIteratorState(iter1.getEdge(), iter1.getAdjNode()).getName()); assertEquals("named street2", graph.getEdgeIteratorState(iter2.getEdge(), iter2.getAdjNode()).getName()); graph.edge(3, 4, 123, true).setWayGeometry(Helper.createPointList3D(4.4, 5.5, 0, 6.6, 7.7, 0)); checkGraph(graph); }