Search in sources :

Example 6 with KernelTransactionImplementation

use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.

the class FulltextAnalyzerTest method shouldNotReindexNodesWhenDefaultAnalyzerIsChanged.

@Test
void shouldNotReindexNodesWhenDefaultAnalyzerIsChanged() throws Exception {
    long secondID;
    applySetting(FulltextSettings.fulltext_default_analyzer, ENGLISH);
    try (Transaction tx = db.beginTx()) {
        tx.schema().indexFor(LABEL).on(PROP).withIndexType(FULLTEXT).withName("nodes").create();
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexOnline("nodes", 1, TimeUnit.MINUTES);
    }
    try (Transaction tx = db.beginTx()) {
        createNodeIndexableByPropertyValue(tx, LABEL, "Hello and hello again, in the end.");
        secondID = createNodeIndexableByPropertyValue(tx, LABEL, "En apa och en tomte bodde i ett hus.");
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = kernelTransaction(tx);
        assertQueryFindsNothing(ktx, true, "nodes", "and");
        assertQueryFindsNothing(ktx, true, "nodes", "in");
        assertQueryFindsNothing(ktx, true, "nodes", "the");
        assertQueryFindsIds(ktx, true, "nodes", "en", secondID);
        assertQueryFindsIds(ktx, true, "nodes", "och", secondID);
        assertQueryFindsIds(ktx, true, "nodes", "ett", secondID);
    }
    applySetting(FulltextSettings.fulltext_default_analyzer, SWEDISH);
    try (KernelTransactionImplementation ktx = getKernelTransaction()) {
        SchemaRead schemaRead = ktx.schemaRead();
        await(schemaRead.indexGetForName("nodes"));
        // These results should be exactly the same as before the configuration change and restart.
        assertQueryFindsNothing(ktx, true, "nodes", "and");
        assertQueryFindsNothing(ktx, true, "nodes", "in");
        assertQueryFindsNothing(ktx, true, "nodes", "the");
        assertQueryFindsIds(ktx, true, "nodes", "en", secondID);
        assertQueryFindsIds(ktx, true, "nodes", "och", secondID);
        assertQueryFindsIds(ktx, true, "nodes", "ett", secondID);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) Test(org.junit.jupiter.api.Test)

Example 7 with KernelTransactionImplementation

use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.

the class FulltextIndexProviderTest method createAndQueryFulltextRelationshipIndex.

@Test
void createAndQueryFulltextRelationshipIndex() throws Exception {
    IndexDescriptor indexReference;
    try (KernelTransactionImplementation transaction = getKernelTransaction()) {
        SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.RELATIONSHIP, new int[] { labelIdHej, labelIdHa, labelIdHe }, new int[] { propIdHej, propIdHa, propIdHe, propIdHo });
        IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withIndexType(FULLTEXT).withName("fulltext");
        indexReference = transaction.schemaWrite().indexCreate(prototype);
        transaction.success();
    }
    await(indexReference);
    long secondRelId;
    try (Transaction transaction = db.beginTx()) {
        Relationship ho = transaction.getNodeById(node1.getId()).createRelationshipTo(transaction.getNodeById(node2.getId()), RelationshipType.withName("ho"));
        secondRelId = ho.getId();
        ho.setProperty("hej", "villa");
        ho.setProperty("ho", "value3");
        transaction.commit();
    }
    verifyRelationshipData(secondRelId);
    controller.restartDbms();
    verifyRelationshipData(secondRelId);
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) Relationship(org.neo4j.graphdb.Relationship) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 8 with KernelTransactionImplementation

use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.

the class FulltextIndexProviderTest method createAndRetainRelationshipFulltextIndex.

@Test
void createAndRetainRelationshipFulltextIndex() throws Exception {
    IndexDescriptor indexReference;
    try (KernelTransactionImplementation transaction = getKernelTransaction()) {
        SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.RELATIONSHIP, new int[] { labelIdHej, labelIdHa, labelIdHe }, new int[] { propIdHej, propIdHa, propIdHe, propIdHo });
        IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withIndexType(FULLTEXT).withName("fulltext");
        indexReference = transaction.schemaWrite().indexCreate(prototype);
        transaction.success();
    }
    await(indexReference);
    controller.restartDbms();
    verifyThatFulltextIndexIsPresent(indexReference);
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 9 with KernelTransactionImplementation

use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.

the class FulltextIndexProviderTest method validateMustThrowIfSchemaIsNotFulltext.

@Test
void validateMustThrowIfSchemaIsNotFulltext() throws Exception {
    try (KernelTransactionImplementation transaction = getKernelTransaction()) {
        int[] propertyIds = { propIdHa };
        SchemaDescriptor schema = SchemaDescriptor.forLabel(labelIdHa, propertyIds);
        IndexPrototype prototype = IndexPrototype.forSchema(schema).withIndexType(FULLTEXT).withName(NAME);
        SchemaWrite schemaWrite = transaction.schemaWrite();
        var e = assertThrows(IllegalArgumentException.class, () -> schemaWrite.indexCreate(prototype));
        assertThat(e.getMessage()).contains("schema is not a full-text index schema");
        transaction.success();
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Test(org.junit.jupiter.api.Test)

Example 10 with KernelTransactionImplementation

use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.

the class PlainOperationsTest method shouldAcquireTxStateBeforeAllocatingRelationshipId.

@Test
void shouldAcquireTxStateBeforeAllocatingRelationshipId() throws EntityNotFoundException {
    // 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);
    when(ktx.securityContext()).thenReturn(SecurityContext.AUTH_DISABLED);
    when(ktx.securityAuthorizationHandler()).thenReturn(new SecurityAuthorizationHandler(CommunitySecurityLog.NULL_LOG));
    CommandCreationContext commandCreationContext = mock(CommandCreationContext.class);
    AllStoreHolder allStoreHolder = mock(AllStoreHolder.class);
    when(allStoreHolder.nodeExists(anyLong())).thenReturn(true);
    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), mock(IndexingProvidersService.class), Config.defaults(), INSTANCE, () -> KernelVersion.LATEST, mock(DbmsRuntimeRepository.class));
    // when
    operations.relationshipCreate(0, 1, 2);
    // then
    InOrder inOrder = inOrder(ktx, commandCreationContext);
    inOrder.verify(ktx).txState();
    inOrder.verify(commandCreationContext).reserveRelationship();
    inOrder.verifyNoMoreInteractions();
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) ConstraintSemantics(org.neo4j.kernel.impl.constraints.ConstraintSemantics) IndexingProvidersService(org.neo4j.kernel.impl.api.index.IndexingProvidersService) InOrder(org.mockito.InOrder) DbmsRuntimeRepository(org.neo4j.dbms.database.DbmsRuntimeRepository) Locks(org.neo4j.kernel.impl.locking.Locks) SecurityAuthorizationHandler(org.neo4j.internal.kernel.api.security.SecurityAuthorizationHandler) 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)

Aggregations

KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)35 Test (org.junit.jupiter.api.Test)20 ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)13 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)12 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)8 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)7 StorageReader (org.neo4j.storageengine.api.StorageReader)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)6 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)6 DbmsRuntimeRepository (org.neo4j.dbms.database.DbmsRuntimeRepository)5 Transaction (org.neo4j.graphdb.Transaction)5 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)5 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)5 CommandCreationContext (org.neo4j.storageengine.api.CommandCreationContext)5 InOrder (org.mockito.InOrder)4 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)4 Test (org.junit.Test)3 SecurityAuthorizationHandler (org.neo4j.internal.kernel.api.security.SecurityAuthorizationHandler)3 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)3 IndexingProvidersService (org.neo4j.kernel.impl.api.index.IndexingProvidersService)3