21
21
import com .graphhopper .routing .ch .PrepareEncoder ;
22
22
import com .graphhopper .routing .util .*;
23
23
import com .graphhopper .routing .weighting .FastestWeighting ;
24
+ import com .graphhopper .routing .weighting .ShortestWeighting ;
24
25
import com .graphhopper .routing .weighting .Weighting ;
25
26
import com .graphhopper .storage .index .QueryResult ;
26
27
import com .graphhopper .util .*;
@@ -252,7 +253,7 @@ public void testQueryGraph() {
252
253
EdgeExplorer explorer = baseGraph .createEdgeExplorer ();
253
254
254
255
assertTrue (chGraph .getNodes () < qGraph .getNodes ());
255
- assertTrue (baseGraph .getNodes () == qGraph .getNodes ());
256
+ assertEquals (baseGraph .getNodes (), qGraph .getNodes ());
256
257
257
258
// traverse virtual edges and normal edges but no shortcuts!
258
259
assertEquals (GHUtility .asSet (fromRes .getClosestNode ()), GHUtility .getNeighbors (explorer .setBaseNode (0 )));
@@ -414,7 +415,7 @@ public void testShortcutCreationAndAccessForManyVehicles() {
414
415
// throw exception for wrong encoder
415
416
try {
416
417
assertFalse (carCHGraph .getEdgeIteratorState (carSC02 .getEdge (), 2 ).isForward (tmpBike ));
417
- assertTrue ( false );
418
+ fail ( );
418
419
} catch (AssertionError ex ) {
419
420
}
420
421
@@ -425,8 +426,60 @@ public void testShortcutCreationAndAccessForManyVehicles() {
425
426
// throw exception for wrong encoder
426
427
try {
427
428
assertFalse (bikeCHGraph .getEdgeIteratorState (bikeSC02 .getEdge (), 2 ).isBackward (tmpCar ));
428
- assertTrue ( false );
429
+ fail ( );
429
430
} catch (AssertionError ex ) {
430
431
}
431
432
}
433
+
434
+ @ Test (expected = IllegalStateException .class )
435
+ public void testLoadingWithWrongWeighting_throws () {
436
+ // we start with one weighting
437
+ GraphHopperStorage ghStorage = newGHStorage (new GHDirectory (defaultGraphLoc , DAType .RAM_STORE ), false );
438
+ ghStorage .create (defaultSize );
439
+ ghStorage .flush ();
440
+
441
+ // but then configure another weighting and try to load the graph from disk -> error
442
+ GraphHopperStorage newGHStorage = createStorageWithWeightings (new ShortestWeighting (carEncoder ));
443
+ newGHStorage .loadExisting ();
444
+ }
445
+
446
+ @ Test (expected = IllegalStateException .class )
447
+ public void testLoadingWithExtraWeighting_throws () {
448
+ // we start with one weighting
449
+ GraphHopperStorage ghStorage = newGHStorage (new GHDirectory (defaultGraphLoc , DAType .RAM_STORE ), false );
450
+ ghStorage .create (defaultSize );
451
+ ghStorage .flush ();
452
+
453
+ // but then add an additional weighting and try to load the graph from disk -> error
454
+ GraphHopperStorage newGHStorage = createStorageWithWeightings (
455
+ new FastestWeighting (carEncoder ), new ShortestWeighting (carEncoder ));
456
+ newGHStorage .loadExisting ();
457
+ }
458
+
459
+ @ Test
460
+ public void testLoadingWithLessWeightings_works () {
461
+ // we start with a gh storage with two ch weightings and flush it to disk
462
+ FastestWeighting weighting1 = new FastestWeighting (carEncoder );
463
+ ShortestWeighting weighting2 = new ShortestWeighting (carEncoder );
464
+ GraphHopperStorage originalStorage = createStorageWithWeightings (weighting1 , weighting2 );
465
+ originalStorage .create (defaultSize );
466
+ originalStorage .flush ();
467
+
468
+ // now we create a new storage but only use one of the weightings, which should be ok
469
+ GraphHopperStorage smallStorage = createStorageWithWeightings (weighting1 );
470
+ smallStorage .loadExisting ();
471
+ assertEquals (1 , smallStorage .getCHWeightings ().size ());
472
+ smallStorage .flush ();
473
+
474
+ // now we create yet another storage that uses both weightings again, which still works
475
+ GraphHopperStorage fullStorage = createStorageWithWeightings (weighting1 , weighting2 );
476
+ fullStorage .loadExisting ();
477
+ assertEquals (2 , fullStorage .getCHWeightings ().size ());
478
+ fullStorage .flush ();
479
+ }
480
+
481
+ private GraphHopperStorage createStorageWithWeightings (Weighting ... weightings ) {
482
+ return new GraphHopperStorage (Arrays .asList (weightings ), new GHDirectory (defaultGraphLoc , DAType .RAM_STORE ),
483
+ encodingManager , false , new GraphExtension .NoOpExtension ());
484
+ }
432
485
}
0 commit comments