Search in sources :

Example 6 with StoreReadLayer

use of org.neo4j.storageengine.api.StoreReadLayer in project neo4j by neo4j.

the class IndexSamplingManagerBeanTest method setup.

@Before
public void setup() {
    dataSource = mock(NeoStoreDataSource.class);
    storeReadLayer = mock(StoreReadLayer.class);
    indexingService = mock(IndexingService.class);
    when(dataSource.getStoreLayer()).thenReturn(storeReadLayer);
    when(storeReadLayer.labelGetForName(EXISTING_LABEL)).thenReturn(LABEL_ID);
    when(storeReadLayer.propertyKeyGetForName(EXISTING_PROPERTY)).thenReturn(PROPERTY_ID);
    when(storeReadLayer.propertyKeyGetForName(NON_EXISTING_PROPERTY)).thenReturn(-1);
    when(storeReadLayer.labelGetForName(NON_EXISTING_LABEL)).thenReturn(-1);
    DependencyResolver resolver = mock(DependencyResolver.class);
    when(resolver.resolveDependency(IndexingService.class)).thenReturn(indexingService);
    when(dataSource.getDependencyResolver()).thenReturn(resolver);
}
Also used : StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Before(org.junit.Before)

Example 7 with StoreReadLayer

use of org.neo4j.storageengine.api.StoreReadLayer in project neo4j by neo4j.

the class KernelTransactionFactory method kernelTransactionWithInternals.

static Instances kernelTransactionWithInternals(SecurityContext securityContext) {
    TransactionHeaderInformation headerInformation = new TransactionHeaderInformation(-1, -1, new byte[0]);
    TransactionHeaderInformationFactory headerInformationFactory = mock(TransactionHeaderInformationFactory.class);
    when(headerInformationFactory.create()).thenReturn(headerInformation);
    StorageEngine storageEngine = mock(StorageEngine.class);
    StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
    StorageStatement storageStatement = mock(StorageStatement.class);
    when(storeReadLayer.newStatement()).thenReturn(storageStatement);
    when(storageEngine.storeReadLayer()).thenReturn(storeReadLayer);
    KernelTransactionImplementation transaction = new KernelTransactionImplementation(mock(StatementOperationContainer.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(), NULL, LockTracer.NONE, PageCursorTracerSupplier.NULL, storageEngine, new CanWrite());
    StatementLocks statementLocks = new SimpleStatementLocks(new NoOpClient());
    transaction.initialize(0, 0, statementLocks, KernelTransaction.Type.implicit, securityContext, 0L);
    return new Instances(transaction, storageEngine, storeReadLayer, storageStatement);
}
Also used : StorageStatement(org.neo4j.storageengine.api.StorageStatement) TransactionHeaderInformation(org.neo4j.kernel.impl.api.TransactionHeaderInformation) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) TransactionHooks(org.neo4j.kernel.impl.api.TransactionHooks) Procedures(org.neo4j.kernel.impl.proc.Procedures) TransactionHeaderInformationFactory(org.neo4j.kernel.impl.transaction.TransactionHeaderInformationFactory) StorageEngine(org.neo4j.storageengine.api.StorageEngine) StatementOperationContainer(org.neo4j.kernel.impl.api.StatementOperationContainer) CanWrite(org.neo4j.kernel.impl.factory.CanWrite) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) SchemaWriteGuard(org.neo4j.kernel.impl.api.SchemaWriteGuard) NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) TransactionRepresentationCommitProcess(org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) StatementLocks(org.neo4j.kernel.impl.locking.StatementLocks) PageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier) Supplier(java.util.function.Supplier) Pool(org.neo4j.collection.pool.Pool) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) TransactionMonitor(org.neo4j.kernel.impl.transaction.TransactionMonitor)

Example 8 with StoreReadLayer

use of org.neo4j.storageengine.api.StoreReadLayer in project neo4j by neo4j.

the class KernelTransactionsTest method newKernelTransactions.

private static KernelTransactions newKernelTransactions(boolean testKernelTransactions, TransactionCommitProcess commitProcess, StorageStatement firstStoreStatements, StorageStatement... otherStorageStatements) throws Throwable {
    Locks locks = mock(Locks.class);
    when(locks.newClient()).thenReturn(mock(Locks.Client.class));
    StoreReadLayer readLayer = mock(StoreReadLayer.class);
    when(readLayer.newStatement()).thenReturn(firstStoreStatements, otherStorageStatements);
    StorageEngine storageEngine = mock(StorageEngine.class);
    when(storageEngine.storeReadLayer()).thenReturn(readLayer);
    doAnswer(invocation -> {
        invocation.getArgumentAt(0, Collection.class).add(mock(StorageCommand.class));
        return null;
    }).when(storageEngine).createCommands(anyCollection(), any(ReadableTransactionState.class), any(StorageStatement.class), any(ResourceLocker.class), anyLong());
    return newKernelTransactions(locks, storageEngine, commitProcess, testKernelTransactions);
}
Also used : StorageStatement(org.neo4j.storageengine.api.StorageStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ResourceLocker(org.neo4j.storageengine.api.lock.ResourceLocker) Collection(java.util.Collection) Matchers.anyCollection(org.mockito.Matchers.anyCollection) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) Locks(org.neo4j.kernel.impl.locking.Locks) StorageEngine(org.neo4j.storageengine.api.StorageEngine)

Example 9 with StoreReadLayer

use of org.neo4j.storageengine.api.StoreReadLayer in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekBySuffixWithIndexQuery.

@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekBySuffixWithIndexQuery() throws Exception {
    // Given
    TransactionState txState = mock(TransactionState.class);
    KernelStatement statement = mock(KernelStatement.class);
    when(statement.hasTxStateWithChanges()).thenReturn(true);
    when(statement.txState()).thenReturn(txState);
    when(txState.indexUpdatesForScan(index)).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
    when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
    StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
    IndexReader indexReader = addMockedIndexReader(statement);
    IndexQuery.StringSuffixPredicate indexQuery = IndexQuery.stringSuffix(index.schema().getPropertyId(), "suffix");
    when(indexReader.query(indexQuery)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
    StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
    // When
    PrimitiveLongIterator results = context.indexQuery(statement, index, indexQuery);
    // Then
    assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Example 10 with StoreReadLayer

use of org.neo4j.storageengine.api.StoreReadLayer in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexSeekWithIndexQuery.

@Test
public void shouldConsiderTransactionStateDuringIndexSeekWithIndexQuery() throws Exception {
    // Given
    TransactionState txState = mock(TransactionState.class);
    KernelStatement statement = mock(KernelStatement.class);
    when(statement.hasTxStateWithChanges()).thenReturn(true);
    when(statement.txState()).thenReturn(txState);
    when(txState.indexUpdatesForSeek(index, OrderedPropertyValues.ofUndefined("value"))).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
    when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
    StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
    IndexReader indexReader = addMockedIndexReader(statement);
    IndexQuery.ExactPredicate query = IndexQuery.exact(index.schema().getPropertyId(), "value");
    when(indexReader.query(query)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
    StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
    // When
    PrimitiveLongIterator results = context.indexQuery(statement, index, query);
    // Then
    assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Aggregations

StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)12 Test (org.junit.Test)8 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)8 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)8 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)8 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)8 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)8 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)8 StorageStatement (org.neo4j.storageengine.api.StorageStatement)4 StorageEngine (org.neo4j.storageengine.api.StorageEngine)3 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 ResourceLocker (org.neo4j.storageengine.api.lock.ResourceLocker)2 ReadableTransactionState (org.neo4j.storageengine.api.txstate.ReadableTransactionState)2 Collection (java.util.Collection)1 Supplier (java.util.function.Supplier)1 Before (org.junit.Before)1 Matchers.anyCollection (org.mockito.Matchers.anyCollection)1 Pool (org.neo4j.collection.pool.Pool)1 Cursor (org.neo4j.cursor.Cursor)1 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1