-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathHGTestBase.java
More file actions
84 lines (69 loc) · 1.98 KB
/
HGTestBase.java
File metadata and controls
84 lines (69 loc) · 1.98 KB
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
package hgtest;
import java.io.File;
import org.hypergraphdb.HGConfiguration;
import org.hypergraphdb.HyperGraph;
import org.hypergraphdb.util.HGUtils;
import org.hypergraphdb.util.Mapping;
import org.junit.AfterClass;
import org.junit.BeforeClass;
public class HGTestBase
{
protected static HyperGraph graph;
protected static HGConfiguration config = new HGConfiguration();
public static void reopenDb()
{
graph.close();
graph.open(graph.getLocation());
}
public static String getGraphLocation()
{
return T.getTmpDirectory() /* "/home/borislav/data" */ + File.separator + "hgtest";
}
public static HyperGraph getGraph()
{
return graph;
}
public static void openGraph()
{
GraphFactory gfac = HGUtils.getImplementationOf("hgtest.GraphFactory", "hgtest.DefaultGraphFactory");
graph = gfac.createGraph(getGraphLocation());
}
@BeforeClass
public static void setUp()
{
try
{
HGUtils.dropHyperGraphInstance(getGraphLocation());
openGraph();
}
catch (Throwable t)
{
t.printStackTrace(System.err);
}
}
@AfterClass
public static void tearDown()
{
graph.close();
HGUtils.dropHyperGraphInstance(getGraphLocation());
}
// backport 1.0, remove later
static void directoryRecurse(File top, Mapping<File, Boolean> mapping)
{
File[] subs = top.listFiles();
if (subs != null)
{
for(File sub : subs)
{
if (sub.isDirectory())
directoryRecurse(sub, mapping);
mapping.eval(sub);
}
mapping.eval(top);
}
}
public static void tx(final Runnable runnable)
{
graph.getTransactionManager().ensureTransaction(() -> { runnable.run(); return null; });
}
}