Search in sources :

Example 6 with CommandCreationContext

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

the class PlainOperationsTest method shouldAcquireTxStateBeforeAllocatingSchemaId.

@Test
void shouldAcquireTxStateBeforeAllocatingSchemaId() throws KernelException {
    // given
    KernelTransactionImplementation ktx = mock(KernelTransactionImplementation.class);
    when(ktx.txState()).thenReturn(mock(TransactionState.class));
    Locks.Client lockClient = mock(Locks.Client.class);
    when(ktx.lockClient()).thenReturn(lockClient);
    CommandCreationContext commandCreationContext = mock(CommandCreationContext.class);
    IndexingProvidersService indexingProvidersService = mock(IndexingProvidersService.class);
    when(indexingProvidersService.getDefaultProvider()).thenReturn(mock(IndexProviderDescriptor.class));
    AllStoreHolder allStoreHolder = mock(AllStoreHolder.class);
    when(allStoreHolder.index(any())).thenReturn(Iterators.emptyResourceIterator());
    when(allStoreHolder.indexGetForName(any())).thenReturn(IndexDescriptor.NO_INDEX);
    when(allStoreHolder.constraintsGetForSchema(any())).thenReturn(Iterators.emptyResourceIterator());
    Operations operations = new Operations(allStoreHolder, mock(StorageReader.class), mock(IndexTxStateUpdater.class), commandCreationContext, ktx, mock(KernelToken.class), mock(DefaultPooledCursors.class), mock(ConstraintIndexCreator.class), mock(ConstraintSemantics.class), indexingProvidersService, Config.defaults(), INSTANCE, () -> KernelVersion.LATEST, mock(DbmsRuntimeRepository.class));
    // when
    operations.indexCreate(IndexPrototype.forSchema(schema).withName("name"));
    // then
    InOrder inOrder = inOrder(ktx, commandCreationContext);
    inOrder.verify(ktx).txState();
    inOrder.verify(commandCreationContext).reserveSchema();
    inOrder.verifyNoMoreInteractions();
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) IndexingProvidersService(org.neo4j.kernel.impl.api.index.IndexingProvidersService) ConstraintSemantics(org.neo4j.kernel.impl.constraints.ConstraintSemantics) InOrder(org.mockito.InOrder) DbmsRuntimeRepository(org.neo4j.dbms.database.DbmsRuntimeRepository) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) Locks(org.neo4j.kernel.impl.locking.Locks) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) Test(org.junit.jupiter.api.Test)

Example 7 with CommandCreationContext

use of org.neo4j.storageengine.api.CommandCreationContext 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 8 with CommandCreationContext

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

the class NeoStoresTest method commitTx.

private void commitTx() throws Exception {
    try (CommandCreationContext commandCreationContext = storageEngine.newCommandCreationContext(INSTANCE)) {
        CursorContext cursorContext = NULL;
        commandCreationContext.initialize(cursorContext);
        List<StorageCommand> commands = new ArrayList<>();
        storageEngine.createCommands(commands, transactionState, storageReader, commandCreationContext, IGNORE, NONE, storageEngine.testAccessNeoStores().getMetaDataStore().getLastClosedTransactionId(), tx -> tx, cursorContext, INSTANCE);
        PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(commands);
        tx.setHeader(EMPTY_BYTE_ARRAY, -1, -1, -1, -1, AUTH_DISABLED);
        storageEngine.apply(new TransactionToApply(tx, cursorContext), INTERNAL);
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) CursorContext(org.neo4j.io.pagecache.context.CursorContext) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Aggregations

CommandCreationContext (org.neo4j.storageengine.api.CommandCreationContext)8 Test (org.junit.jupiter.api.Test)6 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)6 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)5 StorageReader (org.neo4j.storageengine.api.StorageReader)5 InOrder (org.mockito.InOrder)4 DbmsRuntimeRepository (org.neo4j.dbms.database.DbmsRuntimeRepository)4 IndexingProvidersService (org.neo4j.kernel.impl.api.index.IndexingProvidersService)4 ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)4 ConstraintSemantics (org.neo4j.kernel.impl.constraints.ConstraintSemantics)4 ArrayList (java.util.ArrayList)3 SecurityAuthorizationHandler (org.neo4j.internal.kernel.api.security.SecurityAuthorizationHandler)3 CursorContext (org.neo4j.io.pagecache.context.CursorContext)3 Locks (org.neo4j.kernel.impl.locking.Locks)3 StorageCommand (org.neo4j.storageengine.api.StorageCommand)3 TxState (org.neo4j.kernel.impl.api.state.TxState)2 IOException (java.io.IOException)1 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)1 List (java.util.List)1 Stream (java.util.stream.Stream)1