|
17 | 17 | */
|
18 | 18 | package com.graphhopper.storage;
|
19 | 19 |
|
20 |
| -import static org.junit.Assert.assertEquals; |
21 |
| -import static org.junit.Assert.assertTrue; |
22 |
| - |
23 | 20 | import java.io.IOException;
|
24 |
| - |
25 |
| -import org.junit.Test; |
| 21 | +import java.util.Random; |
26 | 22 |
|
27 | 23 | import com.graphhopper.util.EdgeIteratorState;
|
28 | 24 | import com.graphhopper.util.Helper;
|
| 25 | +import org.junit.Test; |
| 26 | + |
| 27 | +import static org.junit.Assert.assertEquals; |
| 28 | +import static org.junit.Assert.assertTrue; |
29 | 29 |
|
30 | 30 | /**
|
31 | 31 | *
|
@@ -93,4 +93,45 @@ public void testSave_and_fileFormat_withTurnCostEntries() throws IOException
|
93 | 93 | graph.edge(3, 4, 123, true).setWayGeometry(Helper.createPointList(4.4, 5.5, 6.6, 7.7));
|
94 | 94 | checkGraph(graph);
|
95 | 95 | }
|
| 96 | + |
| 97 | + @Test |
| 98 | + public void testEnsureCapacity() throws IOException { |
| 99 | + graph = newGraph(new MMapDirectory(defaultGraphLoc), false); |
| 100 | + graph.setSegmentSize(128); |
| 101 | + graph.create(100); // 100 is the minimum size |
| 102 | + |
| 103 | + // assert that turnCostStorage can hold 104 turn cost entries at the beginning |
| 104 | + assertEquals(104, turnCostStorage.getCapacity() / 16); |
| 105 | + |
| 106 | + Random r = new Random(); |
| 107 | + |
| 108 | + NodeAccess na = graph.getNodeAccess(); |
| 109 | + for (int i = 0; i < 100; i++) { |
| 110 | + double randomLat = 90 * r.nextDouble(); |
| 111 | + double randomLon = 180 * r.nextDouble(); |
| 112 | + |
| 113 | + na.setNode(i, randomLat, randomLon); |
| 114 | + } |
| 115 | + |
| 116 | + // Make node 50 the 'center' node |
| 117 | + for (int nodeId = 51; nodeId < 100; nodeId++) { |
| 118 | + graph.edge(50, nodeId, r.nextDouble(), true); |
| 119 | + } |
| 120 | + for (int nodeId = 0; nodeId < 50; nodeId++) { |
| 121 | + graph.edge(nodeId, 50, r.nextDouble(), true); |
| 122 | + } |
| 123 | + |
| 124 | + // add 100 turn cost entries around node 50 |
| 125 | + for (int edgeId = 0; edgeId < 50; edgeId++) { |
| 126 | + turnCostStorage.addTurnInfo(50, edgeId, edgeId + 50, 1337); |
| 127 | + turnCostStorage.addTurnInfo(50, edgeId + 50, edgeId, 1337); |
| 128 | + } |
| 129 | + |
| 130 | + turnCostStorage.addTurnInfo(50, 0, 1, 1337); |
| 131 | + assertEquals(104, turnCostStorage.getCapacity() / 16); // we are still good here |
| 132 | + |
| 133 | + turnCostStorage.addTurnInfo(50, 0, 2, 1337); |
| 134 | + // A new segment should be added, which will support 128 / 16 = 8 more entries. |
| 135 | + assertEquals(112, turnCostStorage.getCapacity() / 16); |
| 136 | + } |
96 | 137 | }
|
0 commit comments