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);
}
}
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);
}
}
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());
}
}
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());
}
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());
}
Aggregations