-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
KernelTransactionFactory.java
116 lines (103 loc) · 5.28 KB
/
KernelTransactionFactory.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
/*
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.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.kernel.api;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import org.neo4j.collection.pool.Pool;
import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.internal.kernel.api.security.LoginContext;
import org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier;
import org.neo4j.io.pagecache.tracing.cursor.context.EmptyVersionContextSupplier;
import org.neo4j.kernel.api.explicitindex.AutoIndexing;
import org.neo4j.kernel.impl.api.KernelTransactionImplementation;
import org.neo4j.kernel.impl.api.SchemaState;
import org.neo4j.kernel.impl.api.SchemaWriteGuard;
import org.neo4j.kernel.impl.api.StatementOperationParts;
import org.neo4j.kernel.impl.api.TransactionHeaderInformation;
import org.neo4j.kernel.impl.api.TransactionHooks;
import org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess;
import org.neo4j.kernel.impl.api.index.IndexingService;
import org.neo4j.kernel.impl.api.state.ConstraintIndexCreator;
import org.neo4j.kernel.impl.constraints.StandardConstraintSemantics;
import org.neo4j.kernel.impl.factory.CanWrite;
import org.neo4j.kernel.impl.index.ExplicitIndexStore;
import org.neo4j.kernel.impl.locking.NoOpClient;
import org.neo4j.kernel.impl.locking.SimpleStatementLocks;
import org.neo4j.kernel.impl.locking.StatementLocks;
import org.neo4j.kernel.impl.proc.Procedures;
import org.neo4j.kernel.impl.transaction.TransactionHeaderInformationFactory;
import org.neo4j.kernel.impl.transaction.TransactionMonitor;
import org.neo4j.kernel.impl.util.Dependencies;
import org.neo4j.resources.CpuClock;
import org.neo4j.resources.HeapAllocation;
import org.neo4j.storageengine.api.StorageEngine;
import org.neo4j.storageengine.api.StorageReader;
import org.neo4j.storageengine.api.lock.LockTracer;
import org.neo4j.time.Clocks;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.neo4j.kernel.impl.transaction.tracing.TransactionTracer.NULL;
import static org.neo4j.kernel.impl.util.collection.CollectionsFactorySupplier.ON_HEAP;
import static org.neo4j.test.MockedNeoStores.mockedTokenHolders;
public class KernelTransactionFactory
{
public static class Instances
{
public KernelTransactionImplementation transaction;
public Instances( KernelTransactionImplementation transaction )
{
this.transaction = transaction;
}
}
private KernelTransactionFactory()
{
}
static Instances kernelTransactionWithInternals( LoginContext loginContext )
{
TransactionHeaderInformation headerInformation = new TransactionHeaderInformation( -1, -1, new byte[0] );
TransactionHeaderInformationFactory headerInformationFactory = mock( TransactionHeaderInformationFactory.class );
when( headerInformationFactory.create() ).thenReturn( headerInformation );
StorageEngine storageEngine = mock( StorageEngine.class );
StorageReader storageReader = mock( StorageReader.class );
when( storageEngine.newReader() ).thenReturn( storageReader );
KernelTransactionImplementation transaction = new KernelTransactionImplementation(
mock( StatementOperationParts.class ),
mock( SchemaWriteGuard.class ),
new TransactionHooks(),
mock( ConstraintIndexCreator.class ), new Procedures(), headerInformationFactory,
mock( TransactionRepresentationCommitProcess.class ), mock( TransactionMonitor.class ),
mock( Supplier.class ),
mock( Pool.class ),
Clocks.systemClock(), new AtomicReference<>( CpuClock.NOT_AVAILABLE ), new AtomicReference<>( HeapAllocation.NOT_AVAILABLE ), NULL,
LockTracer.NONE,
PageCursorTracerSupplier.NULL,
storageEngine, new CanWrite(), AutoIndexing.UNSUPPORTED,
mock( ExplicitIndexStore.class ), EmptyVersionContextSupplier.EMPTY, ON_HEAP, new StandardConstraintSemantics(),
mock( SchemaState.class), mock( IndexingService.class ), mockedTokenHolders(), new Dependencies() );
StatementLocks statementLocks = new SimpleStatementLocks( new NoOpClient() );
transaction.initialize( 0, 0, statementLocks, KernelTransaction.Type.implicit,
loginContext.authorize( s -> -1, DatabaseManager.DEFAULT_DATABASE_NAME ), 0L, 1L );
return new Instances( transaction );
}
static KernelTransaction kernelTransaction( LoginContext loginContext )
{
return kernelTransactionWithInternals( loginContext ).transaction;
}
}