-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
KernelAPIReadTestBase.java
114 lines (104 loc) · 3.94 KB
/
KernelAPIReadTestBase.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
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.internal.kernel.api;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import java.io.IOException;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.internal.kernel.api.security.SecurityContext;
/**
* KernelAPIReadTestBase is the basis of read tests targeting the Kernel API.
*
* As tests are packaged together with the API, they cannot provide all the functionality needed to construct the
* test graph, or provide the concrete Kernel to test. These things are abstracted behind the
* KernelAPIReadTestSupport interface, which needs to be implemented to test reading Kernel implementations.
*
* As read tests do not modify the graph, the test graph is created lazily on the first test run.
*
* @param <ReadSupport> The test support for the current test.
*/
@SuppressWarnings( "WeakerAccess" )
public abstract class KernelAPIReadTestBase<ReadSupport extends KernelAPIReadTestSupport>
{
protected static final TemporaryFolder folder = new TemporaryFolder();
protected static KernelAPIReadTestSupport testSupport;
private Session session;
private Transaction tx;
protected Read read;
protected ExplicitIndexRead indexRead;
protected SchemaRead schemaRead;
protected Token token;
protected ManagedTestCursors cursors;
/**
* Creates a new instance of KernelAPIReadTestSupport, which will be used to execute the concrete test
*/
public abstract ReadSupport newTestSupport();
/**
* Create the graph which all test in the class will be executed against. The graph is only built once,
* regardless of the number of tests.
*
* @param graphDb a graph API which should be used to build the test graph
*/
abstract void createTestGraph( GraphDatabaseService graphDb );
@Before
public void setupGraph() throws IOException, KernelException
{
if ( testSupport == null )
{
folder.create();
testSupport = newTestSupport();
testSupport.setup( folder.getRoot(), this::createTestGraph );
}
Kernel kernel = testSupport.kernelToTest();
session = kernel.beginSession( SecurityContext.AUTH_DISABLED );
cursors = new ManagedTestCursors( kernel.cursors() );
tx = session.beginTransaction( Transaction.Type.explicit );
token = session.token();
read = tx.dataRead();
indexRead = tx.indexRead();
schemaRead = tx.schemaRead();
}
@Rule
public CursorsClosedPostCondition cursorsClosedPostCondition = new CursorsClosedPostCondition( cursors );
@After
public void closeTransaction() throws Exception
{
tx.success();
tx.close();
session.close();
}
@AfterClass
public static void tearDown() throws Exception
{
if ( testSupport != null )
{
testSupport.tearDown();
folder.delete();
testSupport = null;
}
}
}