Search in sources :

Example 96 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class ConstraintTestBase method shouldFindAllConstraints.

@Test
void shouldFindAllConstraints() throws Exception {
    // GIVEN
    addConstraints("FOO", "prop1", "BAR", "prop2", "BAZ", "prop3");
    try (KernelTransaction tx = beginTransaction()) {
        // WHEN
        List<ConstraintDescriptor> constraints = asList(tx.schemaRead().constraintsGetAll());
        // THEN
        assertThat(constraints).hasSize(3);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Example 97 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class ConstraintTestBase method shouldFindConstraintsBySchema.

@Test
void shouldFindConstraintsBySchema() throws Exception {
    // GIVEN
    addConstraints("FOO", "prop");
    try (KernelTransaction tx = beginTransaction()) {
        int label = tx.tokenWrite().labelGetOrCreateForName("FOO");
        int prop = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");
        LabelSchemaDescriptor descriptor = labelSchemaDescriptor(label, prop);
        // WHEN
        List<ConstraintDescriptor> constraints = asList(tx.schemaRead().constraintsGetForSchema(descriptor));
        // THEN
        assertThat(constraints).hasSize(1);
        assertThat(constraints.get(0).schema().getPropertyId()).isEqualTo(prop);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 98 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class ParallelNodeCursorTransactionStateTestBase method createNodes.

private MutableLongSet createNodes(int size) throws TransactionFailureException, InvalidTransactionTypeKernelException {
    MutableLongSet nodes = LongSets.mutable.empty();
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        for (int i = 0; i < size; i++) {
            nodes.add(write.nodeCreate());
        }
        tx.commit();
    }
    return nodes;
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet)

Example 99 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class ParallelNodeLabelScanTestBase method createTestGraph.

@Override
public void createTestGraph(GraphDatabaseService graphDb) {
    MutableLongSet fooNodes = LongSets.mutable.empty();
    MutableLongSet barNodes = LongSets.mutable.empty();
    try (KernelTransaction tx = beginTransaction()) {
        TokenWrite tokenWrite = tx.tokenWrite();
        FOO_LABEL = tokenWrite.labelGetOrCreateForName("foo");
        BAR_LABEL = tokenWrite.labelGetOrCreateForName("bar");
        Write write = tx.dataWrite();
        for (int i = 0; i < NUMBER_OF_NODES; i++) {
            long node = write.nodeCreate();
            if (i % 2 == 0) {
                write.nodeAddLabel(node, FOO_LABEL);
                fooNodes.add(node);
            } else {
                write.nodeAddLabel(node, BAR_LABEL);
                barNodes.add(node);
            }
        }
        FOO_NODES = fooNodes;
        BAR_NODES = barNodes;
        tx.commit();
    } catch (KernelException e) {
        throw new AssertionError(e);
    }
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) KernelException(org.neo4j.exceptions.KernelException)

Example 100 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class ParallelNodeLabelScanTransactionStateTestBase method scanShouldSeeAddedNodes.

@Test
void scanShouldSeeAddedNodes() throws Exception {
    int size = 64;
    int label = label("L");
    MutableLongSet existing = LongSets.mutable.withAll(createNodesWithLabel(label, size));
    try (KernelTransaction tx = beginTransaction()) {
        MutableLongSet added = LongSets.mutable.withAll(createNodesWithLabel(tx.dataWrite(), label, size));
        try (NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
            Scan<NodeLabelIndexCursor> scan = tx.dataRead().nodeLabelScan(label);
            Set<Long> seen = new HashSet<>();
            while (scan.reserveBatch(cursor, 64)) {
                while (cursor.next()) {
                    long nodeId = cursor.nodeReference();
                    assertTrue(seen.add(nodeId), format("%d was seen multiple times", nodeId));
                    assertTrue(existing.remove(nodeId) || added.remove(nodeId));
                }
            }
            // make sure we have seen all nodes
            assertTrue(existing.isEmpty());
            assertTrue(added.isEmpty());
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

KernelTransaction (org.neo4j.kernel.api.KernelTransaction)581 Test (org.junit.jupiter.api.Test)349 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)74 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)66 Transaction (org.neo4j.graphdb.Transaction)64 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)62 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)57 Write (org.neo4j.internal.kernel.api.Write)51 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)47 TokenRead (org.neo4j.internal.kernel.api.TokenRead)42 ArrayList (java.util.ArrayList)37 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)35 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)34 PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)33 Node (org.neo4j.graphdb.Node)31 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)30 MethodSource (org.junit.jupiter.params.provider.MethodSource)28 Read (org.neo4j.internal.kernel.api.Read)28 RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)28 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)25