Search in sources :

Example 11 with TxState

use of org.neo4j.kernel.impl.api.state.TxState 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 12 with TxState

use of org.neo4j.kernel.impl.api.state.TxState in project neo4j by neo4j.

the class KernelTransactionImplementation method txState.

@Override
public TransactionState txState() {
    if (txState == null) {
        leaseClient.ensureValid();
        readOnlyDatabaseChecker.check();
        transactionMonitor.upgradeToWriteTransaction();
        txState = new TxState(collectionsFactory, memoryTracker);
    }
    return txState;
}
Also used : TxState(org.neo4j.kernel.impl.api.state.TxState)

Example 13 with TxState

use of org.neo4j.kernel.impl.api.state.TxState in project neo4j by neo4j.

the class RecordStorageReaderTestBase method createNodeKeyConstraint.

protected void createNodeKeyConstraint(Label label, String propertyKey) throws Exception {
    IndexDescriptor index = createUniqueIndex(label, propertyKey);
    TxState txState = new TxState();
    int labelId = getOrCreateLabelId(label);
    int propertyKeyId = getOrCreatePropertyKeyId(propertyKey);
    NodeKeyConstraintDescriptor constraint = ConstraintDescriptorFactory.nodeKeyForLabel(labelId, propertyKeyId);
    constraint = constraint.withName(index.getName()).withOwnedIndexId(index.getId());
    txState.constraintDoAdd(constraint);
    apply(txState);
}
Also used : NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) TxState(org.neo4j.kernel.impl.api.state.TxState) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 14 with TxState

use of org.neo4j.kernel.impl.api.state.TxState in project neo4j by neo4j.

the class RecordStorageReaderTestBase method createRelPropertyExistenceConstraint.

protected void createRelPropertyExistenceConstraint(RelationshipType relationshipType, String propertyKey) throws Exception {
    TxState txState = new TxState();
    RelExistenceConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForRelType(getOrCreateRelationshipTypeId(relationshipType), getOrCreatePropertyKeyId(propertyKey));
    long id = commitContext.reserveSchema();
    txState.constraintDoAdd(constraint.withId(id).withName("constraint_" + id));
    apply(txState);
}
Also used : TxState(org.neo4j.kernel.impl.api.state.TxState) RelExistenceConstraintDescriptor(org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor)

Example 15 with TxState

use of org.neo4j.kernel.impl.api.state.TxState in project neo4j by neo4j.

the class RecordStorageReaderTestBase method createIndex.

protected IndexDescriptor createIndex(RelationshipType relType, String propertyKey) throws Exception {
    TxState txState = new TxState();
    int relTypeId = getOrCreateRelationshipTypeId(relType);
    int propertyKeyId = getOrCreatePropertyKeyId(propertyKey);
    long id = commitContext.reserveSchema();
    IndexPrototype prototype = IndexPrototype.forSchema(forRelType(relTypeId, propertyKeyId)).withName("index_" + id);
    IndexDescriptor index = prototype.materialise(id);
    txState.indexDoAdd(index);
    apply(txState);
    return index;
}
Also used : TxState(org.neo4j.kernel.impl.api.state.TxState) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Aggregations

TxState (org.neo4j.kernel.impl.api.state.TxState)17 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)5 ArrayList (java.util.ArrayList)3 CommandCreationContext (org.neo4j.storageengine.api.CommandCreationContext)3 StorageCommand (org.neo4j.storageengine.api.StorageCommand)3 Test (org.junit.jupiter.api.Test)2 CursorContext (org.neo4j.io.pagecache.context.CursorContext)2 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)2 IOException (java.io.IOException)1 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)1 List (java.util.List)1 Map (java.util.Map)1 Stream (java.util.stream.Stream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Dependencies (org.neo4j.collection.Dependencies)1