Search in sources :

Example 1 with StoreReadLayer

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

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByStringWithIndexQuery.

@Test
public void shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByStringWithIndexQuery() 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.indexUpdatesForRangeSeekByString(index, "Anne", true, "Bill", false)).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.StringRangePredicate rangePredicate = IndexQuery.range(index.schema().getPropertyId(), "Anne", true, "Bill", false);
    when(indexReader.query(rangePredicate)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
    StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
    // When
    PrimitiveLongIterator results = context.indexQuery(statement, index, rangePredicate);
    // 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 2 with StoreReadLayer

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

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekByContainsWithIndexQuery.

@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekByContainsWithIndexQuery() 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.StringContainsPredicate indexQuery = IndexQuery.stringContains(index.schema().getPropertyId(), "contains");
    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 3 with StoreReadLayer

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

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexScanWithIndexQuery.

@Test
public void shouldConsiderTransactionStateDuringIndexScanWithIndexQuery() 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 query = IndexQuery.exists(index.schema().getPropertyId());
    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)

Example 4 with StoreReadLayer

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

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekByPrefix.

@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekByPrefix() 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.indexUpdatesForRangeSeekByPrefix(index, "prefix")).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.StringPrefixPredicate query = IndexQuery.stringPrefix(index.schema().getPropertyId(), "prefix");
    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)

Example 5 with StoreReadLayer

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

the class ReplicatedTokenHolderTest method mockedStorageEngine.

@SuppressWarnings("unchecked")
private StorageEngine mockedStorageEngine() throws Exception {
    StorageEngine storageEngine = mock(StorageEngine.class);
    doAnswer(invocation -> {
        Collection<StorageCommand> target = invocation.getArgumentAt(0, Collection.class);
        ReadableTransactionState txState = invocation.getArgumentAt(1, ReadableTransactionState.class);
        txState.accept(new TxStateVisitor.Adapter() {

            @Override
            public void visitCreatedLabelToken(String name, int id) {
                LabelTokenRecord before = new LabelTokenRecord(id);
                LabelTokenRecord after = before.clone();
                after.setInUse(true);
                target.add(new Command.LabelTokenCommand(before, after));
            }
        });
        return null;
    }).when(storageEngine).createCommands(anyCollection(), any(ReadableTransactionState.class), any(StorageStatement.class), any(ResourceLocker.class), anyLong());
    StoreReadLayer readLayer = mock(StoreReadLayer.class);
    when(readLayer.newStatement()).thenReturn(mock(StorageStatement.class));
    when(storageEngine.storeReadLayer()).thenReturn(readLayer);
    return storageEngine;
}
Also used : TxStateVisitor(org.neo4j.storageengine.api.txstate.TxStateVisitor) 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) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) StorageEngine(org.neo4j.storageengine.api.StorageEngine) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord)

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