Search in sources :

Example 6 with StorageReader

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);
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) CommunitySecurityLog(org.neo4j.internal.kernel.api.security.CommunitySecurityLog) IndexingProvidersService(org.neo4j.kernel.impl.api.index.IndexingProvidersService) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) SecurityLogHelper(org.neo4j.logging.SecurityLogHelper) LogExtended(org.neo4j.logging.log4j.LogExtended) StorageEngine(org.neo4j.storageengine.api.StorageEngine) SecurityAuthorizationHandler(org.neo4j.internal.kernel.api.security.SecurityAuthorizationHandler) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) StorageSchemaReader(org.neo4j.storageengine.api.StorageSchemaReader) TxState(org.neo4j.kernel.impl.api.state.TxState) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Dependencies(org.neo4j.collection.Dependencies) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with StorageReader

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);
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) HashSet(java.util.HashSet)

Example 8 with StorageReader

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);
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) TokenHolder(org.neo4j.token.api.TokenHolder) TokenHolders(org.neo4j.token.TokenHolders) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with StorageReader

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);
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ResourceLocker(org.neo4j.lock.ResourceLocker) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) Locks(org.neo4j.kernel.impl.locking.Locks) LockTracer(org.neo4j.lock.LockTracer) CursorContext(org.neo4j.io.pagecache.context.CursorContext) StorageEngine(org.neo4j.storageengine.api.StorageEngine) MemoryTracker(org.neo4j.memory.MemoryTracker) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext)

Example 10 with StorageReader

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);
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) DatabaseTracers(org.neo4j.kernel.database.DatabaseTracers) DbmsRuntimeRepository(org.neo4j.dbms.database.DbmsRuntimeRepository) StorageEngine(org.neo4j.storageengine.api.StorageEngine) TestDatabaseIdRepository(org.neo4j.kernel.database.TestDatabaseIdRepository) GlobalProcedures(org.neo4j.kernel.api.procedure.GlobalProcedures) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) SchemaState(org.neo4j.internal.schema.SchemaState) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) DatabaseTransactionEventListeners(org.neo4j.kernel.internal.event.DatabaseTransactionEventListeners) Pool(org.neo4j.collection.pool.Pool) Dependencies(org.neo4j.collection.Dependencies) InternalTransactionCommitProcess(org.neo4j.kernel.impl.api.InternalTransactionCommitProcess) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) TransactionMonitor(org.neo4j.kernel.impl.transaction.TransactionMonitor) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics)

Aggregations

StorageReader (org.neo4j.storageengine.api.StorageReader)12 CommandCreationContext (org.neo4j.storageengine.api.CommandCreationContext)5 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)4 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)4 StorageEngine (org.neo4j.storageengine.api.StorageEngine)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Dependencies (org.neo4j.collection.Dependencies)3 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)3 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 CursorContext (org.neo4j.io.pagecache.context.CursorContext)2 ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)2 TxState (org.neo4j.kernel.impl.api.state.TxState)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 TokenHolders (org.neo4j.token.TokenHolders)2 TokenHolder (org.neo4j.token.api.TokenHolder)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 OpenOption (java.nio.file.OpenOption)1 Path (java.nio.file.Path)1