use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.
the class OperationsTest method setUp.
@BeforeEach
void setUp() throws Exception {
TxState realTxState = new TxState();
txState = Mockito.spy(realTxState);
when(transaction.getReasonIfTerminated()).thenReturn(Optional.empty());
when(transaction.lockClient()).thenReturn(locks);
when(transaction.dataWrite()).thenReturn(write);
when(transaction.isOpen()).thenReturn(true);
when(transaction.lockTracer()).thenReturn(LockTracer.NONE);
when(transaction.txState()).thenReturn(txState);
when(transaction.securityContext()).thenReturn(SecurityContext.authDisabled(AccessMode.Static.FULL, EMBEDDED_CONNECTION, DB_NAME));
logHelper = new SecurityLogHelper(getFormat());
securityLog = new CommunitySecurityLog((LogExtended) logHelper.getLogProvider().getLog(this.getClass()));
when(transaction.securityAuthorizationHandler()).thenReturn(new SecurityAuthorizationHandler(securityLog));
DefaultPooledCursors cursors = mock(DefaultPooledCursors.class);
nodeCursor = mock(FullAccessNodeCursor.class);
propertyCursor = mock(FullAccessPropertyCursor.class);
relationshipCursor = mock(DefaultRelationshipScanCursor.class);
when(cursors.allocateFullAccessNodeCursor(NULL)).thenReturn(nodeCursor);
when(cursors.allocateFullAccessPropertyCursor(NULL, INSTANCE)).thenReturn(propertyCursor);
when(cursors.allocateRelationshipScanCursor(NULL)).thenReturn(relationshipCursor);
StorageEngine engine = mock(StorageEngine.class);
storageReader = mock(StorageReader.class);
storageReaderSnapshot = mock(StorageSchemaReader.class);
when(storageReader.nodeExists(anyLong(), any())).thenReturn(true);
when(storageReader.constraintsGetForLabel(anyInt())).thenReturn(Collections.emptyIterator());
when(storageReader.constraintsGetAll()).thenReturn(Collections.emptyIterator());
when(storageReader.schemaSnapshot()).thenReturn(storageReaderSnapshot);
when(engine.newReader()).thenReturn(storageReader);
indexingService = mock(IndexingService.class);
Dependencies dependencies = new Dependencies();
var facade = mock(GraphDatabaseFacade.class);
dependencies.satisfyDependency(facade);
allStoreHolder = new AllStoreHolder(storageReader, transaction, cursors, mock(GlobalProcedures.class), mock(SchemaState.class), indexingService, mock(IndexStatisticsStore.class), dependencies, Config.defaults(), INSTANCE);
constraintIndexCreator = mock(ConstraintIndexCreator.class);
tokenHolders = mockedTokenHolders();
creationContext = mock(CommandCreationContext.class);
IndexingProvidersService indexingProvidersService = mock(IndexingProvidersService.class);
when(indexingProvidersService.indexProviderByName("native-btree-1.0")).thenReturn(GenericNativeIndexProvider.DESCRIPTOR);
when(indexingProvidersService.getDefaultProvider()).thenReturn(GenericNativeIndexProvider.DESCRIPTOR);
when(indexingProvidersService.indexProviderByName("fulltext-1.0")).thenReturn(FulltextIndexProviderFactory.DESCRIPTOR);
when(indexingProvidersService.getFulltextProvider()).thenReturn(FulltextIndexProviderFactory.DESCRIPTOR);
when(indexingProvidersService.indexProviderByName("provider-1.0")).thenReturn(new IndexProviderDescriptor("provider", "1.0"));
when(indexingProvidersService.completeConfiguration(any())).thenAnswer(inv -> inv.getArgument(0));
operations = new Operations(allStoreHolder, storageReader, mock(IndexTxStateUpdater.class), creationContext, transaction, new KernelToken(storageReader, creationContext, transaction, tokenHolders), cursors, constraintIndexCreator, mock(ConstraintSemantics.class), indexingProvidersService, Config.defaults(), INSTANCE, () -> KernelVersion.LATEST, mock(DbmsRuntimeRepository.class));
operations.initialize(NULL);
this.order = inOrder(locks, txState, storageReader, storageReaderSnapshot, creationContext);
}
use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.
the class IndexTxStateUpdaterTestBase method setUp.
void setUp(List<IndexDescriptor> indexes) throws IndexNotFoundKernelException {
txState = mock(TransactionState.class);
when(txState.memoryTracker()).thenReturn(EmptyMemoryTracker.INSTANCE);
StorageReader storageReader = mock(StorageReader.class);
when(storageReader.valueIndexesGetRelated(any(), anyInt(), any())).thenAnswer(invocationOnMock -> {
long[] tokens = invocationOnMock.getArgument(0);
int propertyKeyId = invocationOnMock.getArgument(1);
Set<IndexDescriptor> descriptors = new HashSet<>();
for (IndexDescriptor index : indexes) {
SchemaDescriptor schema = index.schema();
if (schema.isAffected(tokens) && contains(schema.getPropertyIds(), propertyKeyId)) {
if (schema.propertySchemaType() == PropertySchemaType.COMPLETE_ALL_TOKENS) {
descriptors.add(index);
}
}
}
return descriptors;
});
when(storageReader.valueIndexesGetRelated(any(), any(int[].class), any())).thenAnswer(invocationOnMock -> {
long[] tokens = invocationOnMock.getArgument(0);
int[] propertyKeyIds = invocationOnMock.getArgument(1);
Set<IndexDescriptor> descriptors = new HashSet<>();
for (IndexDescriptor index : indexes) {
if (index.schema().isAffected(tokens)) {
boolean containsAll = true;
for (int propertyId : index.schema().getPropertyIds()) {
containsAll &= contains(propertyKeyIds, propertyId);
}
if (containsAll) {
descriptors.add(index);
}
}
}
return descriptors;
});
Read readOps = mock(Read.class);
when(readOps.txState()).thenReturn(txState);
IndexingService indexingService = mock(IndexingService.class);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(any(IndexDescriptor.class))).thenReturn(indexProxy);
indexTxUpdater = new IndexTxStateUpdater(storageReader, readOps, indexingService);
}
use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.
the class KernelTokenTest method setUp.
@BeforeEach
void setUp() {
ktx = mock(KernelTransactionImplementation.class);
transactionState = mock(TransactionState.class);
when(ktx.txState()).thenReturn(transactionState);
commandCreationContext = mock(CommandCreationContext.class);
storageReader = mock(StorageReader.class);
propertyKeyTokens = mock(TokenHolder.class);
labelTokens = mock(TokenHolder.class);
relationshipTypeTokens = mock(TokenHolder.class);
tokenHolders = new TokenHolders(propertyKeyTokens, labelTokens, relationshipTypeTokens);
kernelToken = new KernelToken(storageReader, commandCreationContext, ktx, tokenHolders);
}
use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.
the class KernelTransactionsTest method newKernelTransactions.
private KernelTransactions newKernelTransactions(boolean testKernelTransactions, TransactionCommitProcess commitProcess, StorageReader firstReader, Config config, StorageReader... otherReaders) throws Throwable {
Locks locks = mock(Locks.class);
Locks.Client client = mock(Locks.Client.class);
when(locks.newClient()).thenReturn(client);
StorageEngine storageEngine = mock(StorageEngine.class);
when(storageEngine.newReader()).thenReturn(firstReader, otherReaders);
when(storageEngine.newCommandCreationContext(any())).thenReturn(mock(CommandCreationContext.class));
doAnswer(invocation -> {
Collection<StorageCommand> argument = invocation.getArgument(0);
argument.add(mock(StorageCommand.class));
return null;
}).when(storageEngine).createCommands(anyCollection(), any(ReadableTransactionState.class), any(StorageReader.class), any(CommandCreationContext.class), any(ResourceLocker.class), any(LockTracer.class), anyLong(), any(TxStateVisitor.Decorator.class), any(CursorContext.class), any(MemoryTracker.class));
return newKernelTransactions(locks, storageEngine, commitProcess, testKernelTransactions, config);
}
use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.
the class KernelTransactionFactory method kernelTransactionWithInternals.
private static Instances kernelTransactionWithInternals(LoginContext loginContext) {
StorageEngine storageEngine = mock(StorageEngine.class);
StorageReader storageReader = mock(StorageReader.class);
when(storageEngine.newReader()).thenReturn(storageReader);
when(storageEngine.newCommandCreationContext(any())).thenReturn(mock(CommandCreationContext.class));
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependency(mock(GraphDatabaseFacade.class));
KernelTransactionImplementation transaction = new KernelTransactionImplementation(Config.defaults(), mock(DatabaseTransactionEventListeners.class), mock(ConstraintIndexCreator.class), mock(GlobalProcedures.class), mock(InternalTransactionCommitProcess.class), mock(TransactionMonitor.class), mock(Pool.class), Clocks.nanoClock(), new AtomicReference<>(CpuClock.NOT_AVAILABLE), mock(DatabaseTracers.class, RETURNS_MOCKS), storageEngine, any -> CanWrite.INSTANCE, EmptyVersionContextSupplier.EMPTY, ON_HEAP, new StandardConstraintSemantics(), mock(SchemaState.class), mockedTokenHolders(), mock(IndexingService.class), mock(IndexStatisticsStore.class), dependencies, new TestDatabaseIdRepository().defaultDatabase(), LeaseService.NO_LEASES, MemoryPools.NO_TRACKING, DatabaseReadOnlyChecker.writable(), TransactionExecutionMonitor.NO_OP, CommunitySecurityLog.NULL_LOG, () -> KernelVersion.LATEST, mock(DbmsRuntimeRepository.class));
transaction.initialize(0, 0, new NoOpClient(), KernelTransaction.Type.IMPLICIT, loginContext.authorize(LoginContext.IdLookup.EMPTY, DEFAULT_DATABASE_NAME, CommunitySecurityLog.NULL_LOG), 0L, 1L, EMBEDDED_CONNECTION);
return new Instances(transaction);
}
Aggregations