/
DexGraphTest.java
207 lines (174 loc) · 7.6 KB
/
DexGraphTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package com.tinkerpop.blueprints.impls.dex;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.EdgeTestSuite;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.GraphTestSuite;
import com.tinkerpop.blueprints.KeyIndexableGraph;
import com.tinkerpop.blueprints.QueryTestSuite;
import com.tinkerpop.blueprints.TestSuite;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.VertexTestSuite;
import com.tinkerpop.blueprints.impls.GraphTest;
import com.tinkerpop.blueprints.util.StringFactory;
import com.tinkerpop.blueprints.util.io.graphml.GraphMLReaderTestSuite;
import com.tinkerpop.blueprints.util.io.graphson.GraphSONReaderTestSuite;
import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
/**
* @author <a href="http://www.sparsity-technologies.com">Sparsity
* Technologies</a>
*/
public class DexGraphTest extends GraphTest {
/*public void testDexBenchmarkTestSuite() throws Exception {
this.stopWatch();
doTestSuite(new DexBenchmarkTestSuite(this));
printTestPerformance("DexBenchmarkTestSuite", this.stopWatch());
}*/
public void testVertexTestSuite() throws Exception {
this.stopWatch();
doTestSuite(new VertexTestSuite(this));
printTestPerformance("VertexTestSuite", this.stopWatch());
}
public void testEdgeTestSuite() throws Exception {
this.stopWatch();
doTestSuite(new EdgeTestSuite(this));
printTestPerformance("EdgeTestSuite", this.stopWatch());
}
public void testGraphTestSuite() throws Exception {
this.stopWatch();
doTestSuite(new GraphTestSuite(this));
printTestPerformance("GraphTestSuite", this.stopWatch());
}
public void testQueryTestSuite() throws Exception {
this.stopWatch();
doTestSuite(new QueryTestSuite(this));
printTestPerformance("QueryTestSuite", this.stopWatch());
}
/*
This test does not work because Dex properties are restricted to
the scope of a node/edge type. Thus, when using the KeyIndexableGraph
APIs it is required to previously set the label where the key property
is defined, as it is shown in the testKeyIndex below.
public void testKeyIndexableGraphTestSuite() throws Exception {
this.stopWatch();
doTestSuite(new KeyIndexableGraphTestSuite(this));
printTestPerformance("KeyIndexableGraphTestSuite", this.stopWatch());
}
//*/
public void testGraphMLReaderTestSuite() throws Exception {
this.stopWatch();
doTestSuite(new GraphMLReaderTestSuite(this));
printTestPerformance("GraphMLReaderTestSuite", this.stopWatch());
}
public void testGraphSONReaderTestSuite() throws Exception {
this.stopWatch();
doTestSuite(new GraphSONReaderTestSuite(this));
printTestPerformance("GraphSONReaderTestSuite", this.stopWatch());
}
/*
the GML Reader won't work with Dex because of our test approach. the test uses the toy
tinkergraph which has a mix of data types for the "weight" property on the edge...dex does
not allow an attribute with the same name to have values with different data types so it
blows up the test.
public void testGMLReaderTestSuite() throws Exception {
this.stopWatch();
doTestSuite(new GMLReaderTestSuite(this));
printTestPerformance("GMLReaderTestSuite", this.stopWatch());
}
*/
//
// specific dex tests
//
public void testDexVertexLabel() throws Exception {
Graph graph = generateGraph(true);
this.stopWatch();
assertTrue(graph.addVertex(null).getProperty(StringFactory.LABEL).equals(DexGraph.DEFAULT_DEX_VERTEX_LABEL));
((DexGraph) graph).label.set("people");
assertTrue(graph.addVertex(null).getProperty(StringFactory.LABEL).equals("people"));
((DexGraph) graph).label.set("thing");
assertTrue(graph.addVertex(null).getProperty(StringFactory.LABEL).equals("thing"));
assertTrue(graph.addVertex("whatever").getProperty(StringFactory.LABEL).equals("thing"));
((DexGraph) graph).label.set(null);
assertTrue(graph.addVertex(null).getProperty(StringFactory.LABEL).equals(DexGraph.DEFAULT_DEX_VERTEX_LABEL));
((DexGraph) graph).label.set("mylabel");
Vertex v1 = graph.addVertex("mylabel");
boolean excep = false;
try {
v1.setProperty(StringFactory.LABEL, "otherlabel");
} catch (IllegalArgumentException e) {
excep = true;
} finally {
assertTrue(excep);
}
printTestPerformance("Dex specific #testDexVertexLabel", this.stopWatch());
graph.shutdown();
}
public void testKeyIndex() {
KeyIndexableGraph graph = (KeyIndexableGraph) generateGraph(true);
this.stopWatch();
((DexGraph) graph).label.set("people");
graph.createKeyIndex("name", Vertex.class);
((DexGraph) graph).label.set("thing");
graph.createKeyIndex("name", Vertex.class);
assertTrue(graph.getIndexedKeys(Edge.class).isEmpty());
assertTrue(graph.getIndexedKeys(Vertex.class).size() == 1);
assertTrue(graph.getIndexedKeys(Vertex.class).contains("name"));
((DexGraph) graph).label.set("people");
Vertex v1 = graph.addVertex(null);
v1.setProperty("name", "foo");
Vertex v2 = graph.addVertex(null);
v2.setProperty("name", "boo");
((DexGraph) graph).label.set("thing");
Vertex v10 = graph.addVertex(null);
v10.setProperty("name", "foo");
Vertex v20 = graph.addVertex(null);
v20.setProperty("name", "boo");
((DexGraph) graph).label.set("people");
assertTrue(graph.getVertices("name", "foo").iterator().next().equals(v1));
((DexGraph) graph).label.set("thing");
assertTrue(graph.getVertices("name", "foo").iterator().next().equals(v10));
ArrayList<Vertex> result = new ArrayList<Vertex>(Arrays.asList(v1, v10));
((DexGraph) graph).label.set(null); // all types!
for (Vertex current : graph.getVertices("name", "foo")) {
assertTrue(result.contains(current));
result.remove(current);
}
assertTrue(result.size() == 0);
result = new ArrayList<Vertex>(Arrays.asList(v1, v2));
for (Vertex current : graph.getVertices(StringFactory.LABEL, "people")) {
assertTrue(result.contains(current));
result.remove(current);
}
assertTrue(result.size() == 0);
// table scan
v1.setProperty("age", 99);
((DexGraph) graph).label.set("people");
assertTrue(graph.getVertices("age", 99).iterator().next().equals(v1));
printTestPerformance("Dex specific #testKeyIndex", this.stopWatch());
graph.shutdown();
}
public Graph generateGraph() {
return generateGraph(false);
}
public Graph generateGraph(boolean create) {
String db = this.computeTestDataRoot() + "/blueprints_test.dex";
if (create) {
File f = new File(db);
if (f.exists()) f.delete();
}
return new DexGraph(db);
}
public void doTestSuite(final TestSuite testSuite) throws Exception {
File fDB = new File(this.computeTestDataRoot() + "/blueprints_test.dex");
fDB.delete();
for (Method method : testSuite.getClass().getDeclaredMethods()) {
if (method.getName().startsWith("test")) {
System.out.println("Testing " + method.getName() + "...");
method.invoke(testSuite);
fDB.delete();
}
}
}
}