Skip to content

Commit a837e22

Browse files
author
Peter
committed
some more close operations for tests under windows
1 parent f1fa83a commit a837e22

File tree

5 files changed

+34
-31
lines changed

5 files changed

+34
-31
lines changed

config-example.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ prepare.chShortcuts=fastest
2424
osmreader.wayPointMaxDistance=1
2525

2626
# possible options: CAR,FOOT,BIKE (comma separated)
27+
# when using two or three option together remeber to set "prepare.chShortcuts=no" above
2728
osmreader.acceptWay=CAR
2829

2930
# if you want to reduce storage size and you don't need instructions for a path uncomment this

core/src/test/java/com/graphhopper/storage/AbstractDirectoryTester.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ public abstract class AbstractDirectoryTester
3737
@After
3838
public void tearDown()
3939
{
40-
Helper.removeDir(new File(location));
4140
if (da != null)
42-
{
4341
da.close();
44-
}
42+
Helper.removeDir(new File(location));
4543
}
4644

4745
@Before

core/src/test/java/com/graphhopper/storage/AbstractGraphStorageTester.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ public void testCopyTo()
282282
ex.printStackTrace();
283283
assertTrue(ex.toString(), false);
284284
}
285+
close(gs);
285286
}
286287

287288
@Test
@@ -514,9 +515,7 @@ public boolean containsLatitude( Graph g, EdgeIterator iter, double latitude )
514515
while (iter.next())
515516
{
516517
if (Math.abs(g.getLatitude(iter.getAdjNode()) - latitude) < 1e-4)
517-
{
518518
return true;
519-
}
520519
}
521520
return false;
522521
}
@@ -936,19 +935,16 @@ public static int getIdOf( Graph g, double latitude )
936935
static void close( Object o )
937936
{
938937
if (o == null)
939-
{
940938
return;
941-
}
939+
942940
if (o instanceof Closeable)
943-
{
944941
try
945942
{
946943
((Closeable) o).close();
947944
} catch (IOException ex)
948945
{
949946
throw new RuntimeException(ex);
950947
}
951-
}
952948
}
953949

954950
@Test

core/src/test/java/com/graphhopper/storage/GraphHopperStorageTest.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public void testNoCreateCalled() throws IOException
7474
{
7575
assertFalse("AssertionError should be raised", true);
7676
}
77+
gs.close();
7778
}
7879

7980
@Test
@@ -151,27 +152,28 @@ protected void checkGraph( Graph g )
151152
@Test
152153
public void internalDisconnect()
153154
{
154-
GraphHopperStorage tmpStorage = (GraphHopperStorage) createGraph();
155-
EdgeIteratorState iter0 = tmpStorage.edge(0, 1, 10, true);
156-
EdgeIteratorState iter2 = tmpStorage.edge(1, 2, 10, true);
157-
EdgeIteratorState iter3 = tmpStorage.edge(0, 3, 10, true);
155+
GraphHopperStorage tmpGS = (GraphHopperStorage) createGraph();
156+
EdgeIteratorState iter0 = tmpGS.edge(0, 1, 10, true);
157+
EdgeIteratorState iter2 = tmpGS.edge(1, 2, 10, true);
158+
EdgeIteratorState iter3 = tmpGS.edge(0, 3, 10, true);
158159

159-
EdgeExplorer explorer = tmpStorage.createEdgeExplorer();
160+
EdgeExplorer explorer = tmpGS.createEdgeExplorer();
160161

161162
assertEquals(GHUtility.asSet(3, 1), GHUtility.getNeighbors(explorer.setBaseNode(0)));
162163
assertEquals(GHUtility.asSet(2, 0), GHUtility.getNeighbors(explorer.setBaseNode(1)));
163164
// remove edge "1-2" but only from 1 not from 2
164-
tmpStorage.internalEdgeDisconnect(iter2.getEdge(), -1, iter2.getBaseNode(), iter2.getAdjNode());
165+
tmpGS.internalEdgeDisconnect(iter2.getEdge(), -1, iter2.getBaseNode(), iter2.getAdjNode());
165166
assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(explorer.setBaseNode(1)));
166167
assertEquals(GHUtility.asSet(1), GHUtility.getNeighbors(explorer.setBaseNode(2)));
167168
// let 0 unchanged -> no side effects
168169
assertEquals(GHUtility.asSet(3, 1), GHUtility.getNeighbors(explorer.setBaseNode(0)));
169170

170171
// remove edge "0-1" but only from 0
171-
tmpStorage.internalEdgeDisconnect(iter0.getEdge(), (long) iter3.getEdge() * tmpStorage.edgeEntryBytes, iter0.getBaseNode(), iter0.getAdjNode());
172+
tmpGS.internalEdgeDisconnect(iter0.getEdge(), (long) iter3.getEdge() * tmpGS.edgeEntryBytes, iter0.getBaseNode(), iter0.getAdjNode());
172173
assertEquals(GHUtility.asSet(3), GHUtility.getNeighbors(explorer.setBaseNode(0)));
173174
assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(explorer.setBaseNode(3)));
174175
assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(explorer.setBaseNode(1)));
176+
tmpGS.close();
175177
}
176178

177179
@Test
@@ -190,10 +192,11 @@ public void testEnsureSize()
190192
public void testBigDataEdge()
191193
{
192194
Directory dir = new RAMDirectory();
193-
GraphHopperStorage gs = new GraphHopperStorage(dir, encodingManager);
194-
gs.create(defaultSize);
195-
gs.setEdgeCount(Integer.MAX_VALUE / 2);
196-
assertTrue(gs.getAllEdges().next());
195+
GraphHopperStorage tmpGS = new GraphHopperStorage(dir, encodingManager);
196+
tmpGS.create(defaultSize);
197+
tmpGS.setEdgeCount(Integer.MAX_VALUE / 2);
198+
assertTrue(tmpGS.getAllEdges().next());
199+
tmpGS.close();
197200
}
198201

199202
@Test

core/src/test/java/com/graphhopper/storage/index/AbstractLocation2IDIndexTester.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
public abstract class AbstractLocation2IDIndexTester
4646
{
4747
String location = "./target/tmp/";
48+
LocationIndex idx;
4849

4950
public abstract LocationIndex createIndex( Graph g, int resolution );
5051

@@ -56,6 +57,8 @@ public boolean hasEdgeSupport()
5657
@Before
5758
public void setUp()
5859
{
60+
if(idx != null)
61+
idx.close();
5962
Helper.removeDir(new File(location));
6063
}
6164

@@ -71,7 +74,7 @@ public void testSimpleGraph()
7174
Graph g = createGraph(new EncodingManager("CAR"));
7275
initSimpleGraph(g);
7376

74-
LocationIndex idx = createIndex(g, 8);
77+
idx = createIndex(g, 8);
7578
assertEquals(4, idx.findID(5, 2));
7679
assertEquals(3, idx.findID(1.5, 2));
7780
assertEquals(0, idx.findID(-1, -1));
@@ -123,7 +126,7 @@ public void testSimpleGraph2()
123126
Graph g = createGraph(new EncodingManager("CAR"));
124127
initSimpleGraph(g);
125128

126-
LocationIndex idx = createIndex(g, 28);
129+
idx = createIndex(g, 28);
127130
assertEquals(4, idx.findID(5, 2));
128131
assertEquals(3, idx.findID(1.5, 2));
129132
assertEquals(0, idx.findID(-1, -1));
@@ -147,16 +150,15 @@ public void testGrid()
147150
Graph g = createSampleGraph(new EncodingManager("CAR"));
148151
int locs = g.getNodes();
149152

150-
LocationIndex index = createIndex(g, 120);
153+
idx = createIndex(g, 120);
151154
// if we would use less array entries then some points gets the same key so avoid that for this test
152155
// e.g. for 16 we get "expected 6 but was 9" i.e 6 was overwritten by node j9 which is a bit closer to the grid center
153156
// go through every point of the graph if all points are reachable
154157
for (int i = 0; i < locs; i++)
155158
{
156159
double lat = g.getLatitude(i);
157160
double lon = g.getLongitude(i);
158-
assertEquals("nodeId:" + i + " " + (float) lat + "," + (float) lon,
159-
i, index.findID(lat, lon));
161+
assertEquals("nodeId:" + i + " " + (float) lat + "," + (float) lon, i, idx.findID(lat, lon));
160162
}
161163

162164
// hit random lat,lon and compare result to full index
@@ -176,7 +178,7 @@ public void testGrid()
176178
double fullLat = g.getLatitude(fullId);
177179
double fullLon = g.getLongitude(fullId);
178180
float fullDist = (float) dist.calcDist(lat, lon, fullLat, fullLon);
179-
int newId = index.findID(lat, lon);
181+
int newId = idx.findID(lat, lon);
180182
double newLat = g.getLatitude(newId);
181183
double newLon = g.getLongitude(newId);
182184
float newDist = (float) dist.calcDist(lat, lon, newLat, newLon);
@@ -191,6 +193,7 @@ public void testGrid()
191193
+ " found:" + newLat + "," + newLon + " foundDist:" + newDist,
192194
Math.abs(fullDist - newDist) < 50000);
193195
}
196+
fullIndex.close();
194197
}
195198

196199
// our simple index has only one node per tile => problems if multiple subnetworks
@@ -203,7 +206,7 @@ boolean testGridIgnore( int i )
203206
public void testSinglePoints120()
204207
{
205208
Graph g = createSampleGraph(new EncodingManager("CAR"));
206-
LocationIndex idx = createIndex(g, 120);
209+
idx = createIndex(g, 120);
207210

208211
assertEquals(1, idx.findID(1.637, 2.23));
209212
assertEquals(10, idx.findID(3.649, 1.375));
@@ -218,7 +221,7 @@ public void testSinglePoints120()
218221
public void testSinglePoints32()
219222
{
220223
Graph g = createSampleGraph(new EncodingManager("CAR"));
221-
LocationIndex idx = createIndex(g, 32);
224+
idx = createIndex(g, 32);
222225

223226
// 10 or 6
224227
assertEquals(10, idx.findID(3.649, 1.375));
@@ -244,7 +247,8 @@ public void testNoErrorOnEdgeCase_lastIndex()
244247
{
245248
g.setNode(i, (float) rand.nextDouble() * 10 + 10, (float) rand.nextDouble() * 10 + 10);
246249
}
247-
createIndex(g, 200);
250+
LocationIndex idx = createIndex(g, 200);
251+
idx.close();
248252
Helper.removeDir(new File(location));
249253
}
250254

@@ -343,7 +347,7 @@ public void testDifferentVehicles()
343347
final EncodingManager encodingManager = new EncodingManager("CAR,FOOT");
344348
Graph g = createGraph(encodingManager);
345349
initSimpleGraph(g);
346-
LocationIndex idx = createIndex(g, 32);
350+
idx = createIndex(g, 32);
347351
assertEquals(1, idx.findID(1, -1));
348352

349353
// now make all edges from node 1 accessible for CAR only
@@ -353,7 +357,8 @@ public void testDifferentVehicles()
353357
{
354358
iter.setFlags(carEncoder.setProperties(50, true, true));
355359
}
356-
360+
idx.close();
361+
357362
idx = createIndex(g, 32);
358363
FootFlagEncoder footEncoder = (FootFlagEncoder) encodingManager.getEncoder("FOOT");
359364
assertEquals(2, idx.findClosest(1, -1, new DefaultEdgeFilter(footEncoder)).getClosestNode());

0 commit comments

Comments
 (0)