|
1 | 1 | package org.ogo.test.datastructuretests; |
2 | 2 |
|
3 | | -import static org.junit.jupiter.api.Assertions.*; |
4 | | -import static org.ogo.client.OGO.queryBool; |
5 | | - |
6 | | -import edu.uci.ics.jung.graph.DirectedSparseGraph; |
7 | | -import edu.uci.ics.jung.graph.SparseGraph; |
8 | | -import edu.uci.ics.jung.graph.UndirectedSparseGraph; |
9 | 3 | import java.io.IOException; |
10 | 4 | import java.rmi.NotBoundException; |
11 | | -import java.rmi.RemoteException; |
12 | | -import java.util.ArrayDeque; |
13 | | -import java.util.ArrayList; |
14 | | -import java.util.HashMap; |
15 | | -import java.util.HashSet; |
16 | | -import java.util.LinkedList; |
17 | | -import java.util.Vector; |
18 | | -import java.util.concurrent.ThreadLocalRandom; |
19 | | -import java.util.stream.Collectors; |
20 | 5 | import org.junit.jupiter.api.BeforeAll; |
21 | | -import org.junit.jupiter.api.RepeatedTest; |
22 | | -import org.junit.jupiter.api.Test; |
23 | 6 | import org.ogo.client.OGO; |
| 7 | +import org.ogo.util.OGOProperties; |
24 | 8 |
|
25 | | -public class DataStructureTest { |
26 | | - |
27 | | - LinkedList<Integer> list1; |
28 | | - ArrayList<Integer> list2; |
29 | | - ArrayDeque<Integer> dque1; |
30 | | - Vector<Integer> vector1; |
31 | | - HashMap<Integer, Integer> map1; |
32 | | - SparseGraph<Integer, Integer> jungSparseGraph; |
33 | | - DirectedSparseGraph<Integer, Integer> jungdSparseGraph; |
34 | | - UndirectedSparseGraph<Integer, Integer> jungudSparseGraph; |
| 9 | +public abstract class DataStructureTest { |
| 10 | + private static boolean queryEngineInitialized = false; |
35 | 11 |
|
36 | 12 | /** |
37 | 13 | * @since 1.0.0 |
38 | 14 | */ |
39 | 15 | @BeforeAll |
40 | 16 | public static void initQueryEngine() throws InterruptedException, IOException, NotBoundException { |
41 | | - Thread.sleep(5000); |
42 | | - OGO.init(); |
43 | | - OGO.setWhiteList("ogo/test", "java/util"); // OGO.setExcludeFromBlackList("java/lang/Byte","java/lang/Short","java/lang/Integer","java/lang/Long","java/lang/Float","java/lang/Double","java/lang/Character","java/lang/String","java/lang/Boolean","List","Map","Set","java/lang/Class","Array","LinkedList","Collection","Deque","Vector"); |
44 | | - // OGO.setBlackList("jdk/","javax/","com/sun","sun/","Exception","maven","junit"); |
45 | | - OGO.clearDatabase = true; |
46 | | - // OGO.printCSV=true; |
47 | | - OGO.forceGC = true; |
48 | | - OGO.followRoot = true; |
49 | | - OGO.whitelist = true; |
50 | | - } |
51 | | - |
52 | | - /** |
53 | | - * @since 1.0.0 |
54 | | - */ |
55 | | - @RepeatedTest(1) |
56 | | - public void checkArrayDeque() throws RemoteException, InterruptedException { |
57 | | - Thread.sleep(200); |
58 | | - ThreadLocalRandom randGen = ThreadLocalRandom.current(); |
59 | | - int size = randGen.nextInt(10, 1000); |
60 | | - dque1 = ((randGen.ints(size, 0, 100000)).boxed()).collect(Collectors.toCollection(ArrayDeque::new)); |
61 | | - Integer item = randGen.nextInt(100, 100000); |
62 | | - boolean var1 = queryBool(this, |
63 | | - "MATCH ({$1})-[:elements]->(m)-[*]->(n {value:" + item + "}) RETURN COUNT(n) <> 0", dque1); |
64 | | - // boolean var1 = OgoArrayDeque.contains(dque1, item , false, this); |
65 | | - boolean var2 = OgoArrayDeque.contains(dque1, item, true, this); |
66 | | - assertEquals(var1, var2); |
67 | | - } |
68 | | - |
69 | | - @Test |
70 | | - public void checkArrayDeque2() throws RemoteException { |
71 | | - dque1 = new ArrayDeque<>(); |
72 | | - dque1.add(1); |
73 | | - boolean var1 = OgoArrayDeque.contains(dque1, 0, false, this); |
74 | | - boolean var2 = OgoArrayDeque.contains(dque1, 0, true, this); |
75 | | - |
76 | | - assertFalse(var1); |
77 | | - assertEquals(var1, var2); |
78 | | - assertFalse(var2); |
79 | | - } |
80 | | - |
81 | | - @Test |
82 | | - public void checkArrayDeque3() throws RemoteException { |
83 | | - dque1 = new ArrayDeque<>(); |
84 | | - dque1.add(1); |
85 | | - // boolean var1 = OgoArrayDeque.contains(dque1, 0, false, this); |
86 | | - // boolean var2 = OgoArrayDeque.contains(dque1, 0, true, this); |
87 | | - |
88 | | - boolean var3 = OgoArrayDeque.contains(dque1, 1, false, this); |
89 | | - boolean var4 = OgoArrayDeque.contains(dque1, 1, true, this); |
90 | | - |
91 | | - // assertTrue(!var1); |
92 | | - assertTrue(var3); |
93 | | - // assertTrue(var1 == var2); |
94 | | - assertEquals(var3, var4); |
95 | | - } |
96 | | - |
97 | | - /** |
98 | | - * @since 1.0.0 |
99 | | - */ |
100 | | - @RepeatedTest(1) |
101 | | - public void checkArrayList() throws RemoteException, InterruptedException { |
102 | | - Thread.sleep(200); |
103 | | - ThreadLocalRandom randGen = ThreadLocalRandom.current(); |
104 | | - int size = 10; // randGen.nextInt(10, 10); |
105 | | - list2 = ((randGen.ints(size, 0, 100000)).boxed()).collect(Collectors.toCollection(ArrayList::new)); |
106 | | - Integer item = randGen.nextInt(100, 100000); |
107 | | - boolean var1 = queryBool(this, |
108 | | - "MATCH ({$1})-[:elementData]->(m)-[*]->(n {value:" + item + "}) RETURN COUNT(n) <> 0", list2); |
109 | | - |
110 | | - // boolean var1 = OgoArrayList.contains(list2, item , false, this); |
111 | | - boolean var2 = OgoArrayList.contains(list2, item, true, this); |
112 | | - assertEquals(var1, var2); |
113 | | - } |
114 | | - |
115 | | - /** |
116 | | - * @since 1.0.0 |
117 | | - */ |
118 | | - @RepeatedTest(1) |
119 | | - public void checkVector() throws RemoteException, InterruptedException { |
120 | | - Thread.sleep(200); |
121 | | - ThreadLocalRandom randGen = ThreadLocalRandom.current(); |
122 | | - int size = randGen.nextInt(10, 500); |
123 | | - vector1 = ((randGen.ints(size, 0, 100000)).boxed()).collect(Collectors.toCollection(Vector::new)); |
124 | | - Integer item = randGen.nextInt(100, 100000); |
125 | | - boolean var1 = queryBool(this, |
126 | | - "MATCH ({$1})-[:elementData]->(m)-[*]->(n {value:" + item + "}) RETURN COUNT(n) <> 0", vector1); |
127 | | - // boolean var1 = OgoLinkedList.contains(list1, item , false, this); |
128 | | - boolean var2 = OgoVector.contains(vector1, item, true); |
129 | | - assertEquals(var1, var2); |
130 | | - } |
131 | | - |
132 | | - /** |
133 | | - * @since 1.0.0 |
134 | | - */ |
135 | | - @RepeatedTest(1) |
136 | | - public void checkLinkedList() throws RemoteException, InterruptedException { |
137 | | - Thread.sleep(200); |
138 | | - ThreadLocalRandom randGen = ThreadLocalRandom.current(); |
139 | | - int size = 5; |
140 | | - list1 = ((randGen.ints(size, 0, 100000)).boxed()).collect(Collectors.toCollection(LinkedList::new)); |
141 | | - Integer item = randGen.nextInt(100, 100000); |
142 | | - boolean var1 = queryBool(this, "MATCH ({$1})-[:first]->(m)-[*]->(n {value:" + item + "}) RETURN COUNT(n) <> 0", |
143 | | - list1); |
144 | | - // boolean var1 = OgoLinkedList.contains(list1, item , false, this); |
145 | | - boolean var2 = OgoLinkedList.contains(list1, item, true, this); |
146 | | - assertEquals(var1, var2); |
147 | | - } |
148 | | - |
149 | | - /** |
150 | | - * @since 1.0.0 |
151 | | - */ |
152 | | - @RepeatedTest(1) |
153 | | - public void checkHashMap() throws RemoteException, InterruptedException { |
154 | | - Thread.sleep(200); |
155 | | - ThreadLocalRandom randGen = ThreadLocalRandom.current(); |
156 | | - int size = randGen.nextInt(10, 500); |
157 | | - ArrayList<Integer> temp = ((randGen.ints(size, 0, 100000)).boxed()) |
158 | | - .collect(Collectors.toCollection(ArrayList::new)); |
159 | | - ArrayList<Integer> temp2 = ((randGen.ints(size, 0, 100000)).boxed()) |
160 | | - .collect(Collectors.toCollection(ArrayList::new)); |
161 | | - map1 = new HashMap<>(); |
162 | | - for (int j = 0; j < temp.size(); j++) { |
163 | | - map1.put(temp.get(j), temp2.get(j)); |
164 | | - } |
165 | | - Integer item = randGen.nextInt(100, 100000); |
166 | | - boolean var1 = queryBool(this, |
167 | | - "MATCH ({$1})-[:table]->(m)-[*]->()-[:key]->(n {value:" + item + "}) RETURN COUNT(n) <> 0", map1); |
168 | | - // boolean var1 = OgoLinkedList.contains(list1, item , false, this); |
169 | | - boolean var2 = OgoHashMap.containsKey(map1, item, true); |
170 | | - assertEquals(var1, var2); |
171 | | - } |
172 | | - |
173 | | - @Test |
174 | | - public void checkHashSet() throws RemoteException, InterruptedException { |
175 | | - Thread.sleep(200); |
176 | | - ThreadLocalRandom randGen = ThreadLocalRandom.current(); |
177 | | - int size = randGen.nextInt(10, 500); |
178 | | - HashSet<Integer> set = ((randGen.ints(size, 0, 100000)).boxed()).collect(Collectors.toCollection(HashSet::new)); |
179 | | - Integer item = randGen.nextInt(100000, 200000); |
180 | | - boolean var1 = queryBool(this, "MATCH ({$1})-[:map]->(m)-[:table]->(t)-[*]->()-[:value]->(n {value:" + item |
181 | | - + "}) RETURN COUNT(n) <> 0", set); |
182 | | - boolean var2 = OgoHashSet.contains(set, item, true); |
183 | | - assertEquals(var1, var2); |
184 | | - } |
185 | | - |
186 | | - /** |
187 | | - * @since 1.0.0 |
188 | | - */ |
189 | | - @RepeatedTest(1) |
190 | | - public void checkSparseGraph() throws RemoteException, InterruptedException { |
191 | | - Thread.sleep(200); |
192 | | - ThreadLocalRandom randGen = ThreadLocalRandom.current(); |
193 | | - int size = randGen.nextInt(10, 500); |
194 | | - ArrayList<Integer> temp = ((randGen.ints(size, 0, 100000)).boxed()) |
195 | | - .collect(Collectors.toCollection(ArrayList::new)); |
196 | | - ArrayList<Integer> temp2 = ((randGen.ints(size, 0, 100000)).boxed()) |
197 | | - .collect(Collectors.toCollection(ArrayList::new)); |
198 | | - jungSparseGraph = new SparseGraph<>(); |
199 | | - for (int j = 0; j < temp.size(); j++) { |
200 | | - jungSparseGraph.addVertex(temp.get(j)); |
201 | | - jungSparseGraph.addVertex(temp2.get(j)); |
202 | | - jungSparseGraph.addEdge(j, temp.get(j), temp2.get(j)); |
203 | | - } |
204 | | - Integer item = randGen.nextInt(100, 100000); |
205 | | - boolean var1 = queryBool(this, |
206 | | - "MATCH ({$1})-[:undirected_edges]->()-[:table]->()-[:`" + item + "`]->(n) RETURN n IS NOT NULL", |
207 | | - jungSparseGraph); |
208 | | - boolean var2 = jungSparseGraph.containsEdge(item); |
209 | | - assertEquals(var1, var2); |
210 | | - } |
211 | | - |
212 | | - /** |
213 | | - * @since 1.0.0 |
214 | | - */ |
215 | | - @RepeatedTest(1) |
216 | | - public void checkDirectedSparseGraph() throws RemoteException, InterruptedException { |
217 | | - Thread.sleep(200); |
218 | | - ThreadLocalRandom randGen = ThreadLocalRandom.current(); |
219 | | - int size = randGen.nextInt(10, 500); |
220 | | - ArrayList<Integer> temp = ((randGen.ints(size, 0, 100000)).boxed()) |
221 | | - .collect(Collectors.toCollection(ArrayList::new)); |
222 | | - ArrayList<Integer> temp2 = ((randGen.ints(size, 0, 100000)).boxed()) |
223 | | - .collect(Collectors.toCollection(ArrayList::new)); |
224 | | - jungdSparseGraph = new DirectedSparseGraph<>(); |
225 | | - for (int j = 0; j < temp.size(); j++) { |
226 | | - jungdSparseGraph.addVertex(temp.get(j)); |
227 | | - jungdSparseGraph.addVertex(temp2.get(j)); |
228 | | - jungdSparseGraph.addEdge(j, temp.get(j), temp2.get(j)); |
229 | | - } |
230 | | - Integer item = randGen.nextInt(100, 100000); |
231 | | - boolean var1 = queryBool(this, |
232 | | - "MATCH ({$1})-[:edges]->()-[:table]->()-[:`" + item + "`]->(n) RETURN n IS NOT NULL", jungdSparseGraph); |
233 | | - boolean var2 = jungdSparseGraph.containsEdge(item); |
234 | | - assertEquals(var1, var2); |
235 | | - } |
236 | | - |
237 | | - /** |
238 | | - * @since 1.0.0 |
239 | | - */ |
240 | | - @RepeatedTest(1) |
241 | | - public void checkUndirectedSparseGraph() throws RemoteException, InterruptedException { |
242 | | - Thread.sleep(200); |
243 | | - ThreadLocalRandom randGen = ThreadLocalRandom.current(); |
244 | | - int size = randGen.nextInt(10, 500); |
245 | | - ArrayList<Integer> temp = ((randGen.ints(size, 0, 100000)).boxed()) |
246 | | - .collect(Collectors.toCollection(ArrayList::new)); |
247 | | - ArrayList<Integer> temp2 = ((randGen.ints(size, 0, 100000)).boxed()) |
248 | | - .collect(Collectors.toCollection(ArrayList::new)); |
249 | | - jungudSparseGraph = new UndirectedSparseGraph<>(); |
250 | | - for (int j = 0; j < temp.size(); j++) { |
251 | | - jungudSparseGraph.addVertex(temp.get(j)); |
252 | | - jungudSparseGraph.addVertex(temp2.get(j)); |
253 | | - jungudSparseGraph.addEdge(j, temp.get(j), temp2.get(j)); |
| 17 | + if (!queryEngineInitialized) { |
| 18 | + Thread.sleep(5000); |
| 19 | + OGO.init(); |
| 20 | + OGO.setWhiteList("ogo/test", "java/util"); |
| 21 | + OGO.forceGC = true; |
| 22 | + OGO.followRoot = true; |
| 23 | + OGO.whitelist = true; |
| 24 | + queryEngineInitialized = true; |
254 | 25 | } |
255 | | - Integer item = randGen.nextInt(100, 100000); |
256 | | - boolean var1 = queryBool(this, |
257 | | - "MATCH ({$1})-[:edges]->()-[:table]->()-[:`" + item + "`]->(n) RETURN n IS NOT NULL", |
258 | | - jungudSparseGraph); |
259 | | - boolean var2 = jungudSparseGraph.containsEdge(item); |
260 | | - assertEquals(var1, var2); |
| 26 | + OGO.clearDatabase = OGOProperties.getClearDatabase(); |
261 | 27 | } |
262 | 28 | } |
0 commit comments