15
15
import java .io .File ;
16
16
import java .util .BitSet ;
17
17
import java .util .List ;
18
+ import java .util .TreeMap ;
18
19
import java .util .concurrent .ThreadPoolExecutor ;
19
20
import java .util .stream .Collectors ;
20
21
24
25
/**
25
26
* Tests that saving a graph and reloading it (round trip through serialization and deserialization) does not corrupt
26
27
* the graph, and yields exactly the same data.
27
- *
28
+ * <p>
28
29
* We tried several existing libraries to perform the comparison but nothing did exactly what we needed in a way that
29
30
* we could control precisely.
30
- *
31
+ * <p>
31
32
* Created by abyrd on 2018-10-26
32
33
*/
33
34
public class GraphSerializationTest {
@@ -36,7 +37,7 @@ public class GraphSerializationTest {
36
37
* Tests that saving a Graph to disk and reloading it results in a separate but semantically identical Graph.
37
38
*/
38
39
@ Test
39
- public void testRoundTrip () throws Exception {
40
+ public void testRoundTrip () throws Exception {
40
41
// This graph does not make an ideal test because it doesn't have any street data.
41
42
// TODO switch to another graph that has both GTFS and OSM data
42
43
Graph originalGraph = ConstantsForTests .getInstance ().getPortlandGraph ();
@@ -69,13 +70,13 @@ public void testRoundTrip () throws Exception {
69
70
* and allows us to perform a very deep comparison of almost the entire object graph because there are no problems
70
71
* with lists being reordered, transient indexes being rebuilt, etc. The ObjectDiffer supports such comparisons
71
72
* of identical objects with a special switch specifically for testing.
72
- *
73
+ * <p>
73
74
* This is as much a test of the ObjectDiffer itself as of OpenTripPlanner serialization. It is situated here
74
75
* instead of in the same package as ObjectDiffer so it has access to the OpenTripPlanner classes, which provide a
75
76
* suitably complex tangle of fields and references for exercising all the differ's capabilities.
76
77
*/
77
78
@ Test
78
- public void compareGraphToItself () {
79
+ public void compareGraphToItself () {
79
80
// This graph does not make an ideal test because it doesn't have any street data.
80
81
// TODO switch to another graph that has both GTFS and OSM data
81
82
Graph originalGraph = ConstantsForTests .getInstance ().getPortlandGraph ();
@@ -87,7 +88,7 @@ public void compareGraphToItself () {
87
88
objectDiffer .ignoreFields ("incoming" , "outgoing" );
88
89
objectDiffer .useEquals (BitSet .class , LineString .class , Polygon .class );
89
90
// ThreadPoolExecutor contains a weak reference to a very deep chain of Finalizer instances.
90
- objectDiffer .ignoreClasses (WeakValueHashMap .class , ThreadPoolExecutor .class );
91
+ objectDiffer .ignoreClasses (WeakValueHashMap .class , ThreadPoolExecutor .class , TreeMap . class , org . opentripplanner . common . LuceneIndex . class );
91
92
// This setting is critical to perform a deep test of an object against itself.
92
93
objectDiffer .enableComparingIdenticalObjects ();
93
94
objectDiffer .compareTwoObjects (originalGraph , originalGraph );
@@ -105,7 +106,7 @@ public void testEmptyGraphs() {
105
106
assertNoDifferences (graph1 , graph2 );
106
107
}
107
108
108
- private static void assertNoDifferences (Graph g1 , Graph g2 ) {
109
+ private static void assertNoDifferences (Graph g1 , Graph g2 ) {
109
110
// Make some exclusions because some classes are inherently transient or contain unordered lists we can't yet compare.
110
111
ObjectDiffer objectDiffer = new ObjectDiffer ();
111
112
// Skip incoming and outgoing edge lists. These are unordered lists which will not compare properly.
@@ -116,7 +117,7 @@ private static void assertNoDifferences (Graph g1, Graph g2) {
116
117
// HashGridSpatialIndex contains unordered lists in its bins. This is rebuilt after deserialization anyway.
117
118
// The deduplicator in the loaded graph will be empty, because it is transient and only fills up when items
118
119
// are deduplicated.
119
- objectDiffer .ignoreClasses (HashGridSpatialIndex .class , ThreadPoolExecutor .class , Deduplicator .class );
120
+ objectDiffer .ignoreClasses (HashGridSpatialIndex .class , ThreadPoolExecutor .class , Deduplicator .class , TreeMap . class , org . opentripplanner . common . LuceneIndex . class , graphql . schema . GraphQLSchema . class );
120
121
objectDiffer .compareTwoObjects (g1 , g2 );
121
122
// Print differences before assertion so we can see what went wrong.
122
123
assertFalse (objectDiffer .hasDifferences ());
0 commit comments