Search in sources :

Example 26 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.

the class CountsComputerTest method shouldCreateACountsStoreWhenThereAreNodesAndRelationshipsInTheDB.

@Test
void shouldCreateACountsStoreWhenThereAreNodesAndRelationshipsInTheDB() throws IOException, KernelException {
    DatabaseManagementService managementService = dbBuilder.build();
    final GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    Label[] labels = null;
    int[] labelIds = null;
    RelationshipType[] relTypes = null;
    int[] relTypeIds = null;
    Node[] nodes = null;
    Relationship[] rels = null;
    try (Transaction tx = db.beginTx()) {
        labels = createLabels(4);
        labelIds = getLabelIdsFrom(tx, labels);
        relTypes = createRelationShipTypes(3);
        relTypeIds = getRelTypeIdsFrom(tx, relTypes);
        nodes = new Node[] { tx.createNode(labels[0]), tx.createNode(labels[1]), tx.createNode(labels[2]), tx.createNode() };
        rels = new Relationship[] { nodes[0].createRelationshipTo(nodes[2], relTypes[0]), nodes[3].createRelationshipTo(nodes[1], relTypes[1]) };
        tx.commit();
    }
    long lastCommittedTransactionId = getLastTxId(db);
    managementService.shutdown();
    rebuildCounts(lastCommittedTransactionId);
    try (GBPTreeCountsStore store = createCountsStore()) {
        softly.assertThat(store.txId()).as("Store Transaction id").isEqualTo(lastCommittedTransactionId);
        softly.assertThat(store.nodeCount(ANY_LABEL, NULL)).as("count: ()").isEqualTo(nodes.length);
        softly.assertThat(store.nodeCount(labelIds[0], NULL)).as("count: (:%s)", labels[0]).isEqualTo(1);
        softly.assertThat(store.nodeCount(labelIds[1], NULL)).as("count: (:%s)", labels[1]).isEqualTo(1);
        softly.assertThat(store.nodeCount(labelIds[2], NULL)).as("count: (:%s)", labels[2]).isEqualTo(1);
        softly.assertThat(store.nodeCount(labelIds[3], NULL)).as("count: (:%s)", labels[3]).isEqualTo(0);
        softly.assertThat(store.relationshipCount(ANY_LABEL, ANY_RELATIONSHIP_TYPE, ANY_LABEL, NULL)).as("()-[]->()").isEqualTo(rels.length);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[0], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[0]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[1], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[1]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[2], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[2]).isEqualTo(0);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[1], labelIds[1], NULL)).as("count: ()-[:%s]->(:%s)", relTypes[1], labels[1]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[0], labelIds[1], NULL)).as("count: ()-[:%s]->(:%s)", relTypes[0], labels[1]).isEqualTo(0);
    }
}
Also used : Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) RelationshipType(org.neo4j.graphdb.RelationshipType) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Relationship(org.neo4j.graphdb.Relationship) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 27 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.

the class CountsComputerTest method shouldCreateACountsStoreWhenThereAreUnusedRelationshipRecordsInTheDB.

@Test
void shouldCreateACountsStoreWhenThereAreUnusedRelationshipRecordsInTheDB() throws IOException, KernelException {
    DatabaseManagementService managementService = dbBuilder.build();
    final GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    Label[] labels = null;
    int[] labelIds = null;
    RelationshipType[] relTypes = null;
    int[] relTypeIds = null;
    Node[] nodes = null;
    Relationship[] rels = null;
    try (Transaction tx = db.beginTx()) {
        labels = createLabels(4);
        labelIds = getLabelIdsFrom(tx, labels);
        relTypes = createRelationShipTypes(2);
        relTypeIds = getRelTypeIdsFrom(tx, relTypes);
        nodes = new Node[] { tx.createNode(labels[0]), tx.createNode(labels[1]) };
        rels = new Relationship[] { nodes[0].createRelationshipTo(nodes[1], relTypes[0]), nodes[1].createRelationshipTo(nodes[0], relTypes[1]) };
        rels[0].delete();
        tx.commit();
    }
    long lastCommittedTransactionId = getLastTxId(db);
    managementService.shutdown();
    rebuildCounts(lastCommittedTransactionId);
    try (GBPTreeCountsStore store = createCountsStore()) {
        softly.assertThat(store.txId()).as("Store Transaction id").isEqualTo(lastCommittedTransactionId);
        softly.assertThat(store.nodeCount(ANY_LABEL, NULL)).as("count: ()").isEqualTo(nodes.length);
        softly.assertThat(store.nodeCount(labelIds[0], NULL)).as("count: (:%s)", labels[0]).isEqualTo(1);
        softly.assertThat(store.nodeCount(labelIds[1], NULL)).as("count: (:%s)", labels[1]).isEqualTo(1);
        softly.assertThat(store.nodeCount(labelIds[2], NULL)).as("count: (:%s)", labels[2]).isEqualTo(0);
        softly.assertThat(store.nodeCount(labelIds[3], NULL)).as("count: (:%s)", labels[3]).isEqualTo(0);
        softly.assertThat(store.relationshipCount(ANY_LABEL, ANY_RELATIONSHIP_TYPE, ANY_LABEL, NULL)).as("()-[]->()").isEqualTo(rels.length - 1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[0], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[0]).isEqualTo(0);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[1], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[1]).isEqualTo(1);
    }
}
Also used : Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) RelationshipType(org.neo4j.graphdb.RelationshipType) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Relationship(org.neo4j.graphdb.Relationship) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 28 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.

the class IndexTxStateLookupTest method shouldRemoveDeletedRelationshipCreatedInSameTransactionFromIndexTxStateEvenWithMultipleProperties.

@ParameterizedTest(name = "store=<{0}> lookup=<{1}>")
@MethodSource("argumentsProvider")
void shouldRemoveDeletedRelationshipCreatedInSameTransactionFromIndexTxStateEvenWithMultipleProperties(Object store, Object lookup) {
    init(store, lookup);
    try (Transaction tx = db.beginTx()) {
        // given
        RelationshipType type = RelationshipType.withName("Rel");
        String key = "prop";
        String key2 = "prop2";
        Relationship relationship = tx.createNode().createRelationshipTo(tx.createNode(), type);
        relationship.setProperty(key, this.store);
        relationship.setProperty(key2, this.store);
        assertTrue(tx.findRelationships(type, key, this.lookup).hasNext());
        // when
        relationship.delete();
        // then
        assertFalse(tx.findRelationships(type, key, this.lookup).hasNext());
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 29 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.

the class FulltextIndexConsistencyCheckIT method mustBeAbleToConsistencyCheckRelationshipIndexWithOneRelationshipTypeAndMultipleProperties.

@Test
void mustBeAbleToConsistencyCheckRelationshipIndexWithOneRelationshipTypeAndMultipleProperties() throws Exception {
    GraphDatabaseService db = createDatabase();
    RelationshipType relationshipType = RelationshipType.withName("R1");
    try (Transaction tx = db.beginTx()) {
        tx.execute(format(RELATIONSHIP_CREATE, "rels", asStrList("R1"), asStrList("p1", "p2"))).close();
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
        Node node = tx.createNode();
        Relationship r1 = node.createRelationshipTo(node, relationshipType);
        r1.setProperty("p1", "value");
        r1.setProperty("p2", "value");
        // This relationship will have a different id value than the node.
        Relationship r2 = node.createRelationshipTo(node, relationshipType);
        r2.setProperty("p1", "value");
        r2.setProperty("p2", "value");
        node.createRelationshipTo(node, relationshipType).setProperty("p1", "value");
        node.createRelationshipTo(node, relationshipType).setProperty("p2", "value");
        tx.commit();
    }
    managementService.shutdown();
    assertIsConsistent(checkConsistency());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.jupiter.api.Test)

Example 30 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.

the class FulltextIndexConsistencyCheckIT method mustBeAbleToConsistencyCheckRelationshipIndexWithMultipleRelationshipTypesAndOneProperty.

@Test
void mustBeAbleToConsistencyCheckRelationshipIndexWithMultipleRelationshipTypesAndOneProperty() throws Exception {
    GraphDatabaseService db = createDatabase();
    RelationshipType relType1 = RelationshipType.withName("R1");
    RelationshipType relType2 = RelationshipType.withName("R2");
    try (Transaction tx = db.beginTx()) {
        tx.execute(format(RELATIONSHIP_CREATE, "rels", asStrList("R1", "R2"), asStrList("p1"))).close();
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
        Node n1 = tx.createNode();
        Node n2 = tx.createNode();
        n1.createRelationshipTo(n1, relType1).setProperty("p1", "value");
        n1.createRelationshipTo(n1, relType2).setProperty("p1", "value");
        n2.createRelationshipTo(n2, relType1).setProperty("p1", "value");
        n2.createRelationshipTo(n2, relType2).setProperty("p1", "value");
        tx.commit();
    }
    managementService.shutdown();
    assertIsConsistent(checkConsistency());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.jupiter.api.Test)

Aggregations

RelationshipType (org.neo4j.graphdb.RelationshipType)147 Node (org.neo4j.graphdb.Node)84 Relationship (org.neo4j.graphdb.Relationship)59 Transaction (org.neo4j.graphdb.Transaction)52 Test (org.junit.Test)35 Test (org.junit.jupiter.api.Test)32 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)20 Direction (org.neo4j.graphdb.Direction)19 Label (org.neo4j.graphdb.Label)18 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)15 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)15 ArrayList (java.util.ArrayList)13 NotFoundException (org.neo4j.graphdb.NotFoundException)10 Traverser (org.neo4j.graphdb.Traverser)10 HashSet (java.util.HashSet)9 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)7 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)7 Collection (java.util.Collection)6 HashMap (java.util.HashMap)6 LinkedList (java.util.LinkedList)6