use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class FulltextIndexConsistencyCheckIT method consistencyCheckerMustBeAbleToRunOnStoreWithFulltextIndexes.
@Test
void consistencyCheckerMustBeAbleToRunOnStoreWithFulltextIndexes() throws Exception {
GraphDatabaseService db = createDatabase();
Label[] labels = IntStream.range(1, 7).mapToObj(i -> Label.label("LABEL" + i)).toArray(Label[]::new);
RelationshipType[] relTypes = IntStream.range(1, 5).mapToObj(i -> RelationshipType.withName("REL" + i)).toArray(RelationshipType[]::new);
String[] propertyKeys = IntStream.range(1, 7).mapToObj(i -> "PROP" + i).toArray(String[]::new);
RandomValues randomValues = random.randomValues();
try (Transaction tx = db.beginTx()) {
int nodeCount = 1000;
List<Node> nodes = new ArrayList<>(nodeCount);
for (int i = 0; i < nodeCount; i++) {
Label[] nodeLabels = random.ints(random.nextInt(labels.length), 0, labels.length).distinct().mapToObj(x -> labels[x]).toArray(Label[]::new);
Node node = tx.createNode(nodeLabels);
Stream.of(propertyKeys).forEach(p -> node.setProperty(p, random.nextBoolean() ? p : randomValues.nextValue().asObject()));
nodes.add(node);
int localRelCount = Math.min(nodes.size(), 5);
random.ints(localRelCount, 0, localRelCount).distinct().mapToObj(x -> node.createRelationshipTo(nodes.get(x), relTypes[random.nextInt(relTypes.length)])).forEach(r -> Stream.of(propertyKeys).forEach(p -> r.setProperty(p, random.nextBoolean() ? p : randomValues.nextValue().asObject())));
}
tx.commit();
}
try (Transaction tx = db.beginTx()) {
for (int i = 1; i < labels.length; i++) {
tx.execute(format(NODE_CREATE, "nodes" + i, asStrList(Arrays.stream(labels).limit(i).map(Label::name).toArray(String[]::new)), asStrList(Arrays.copyOf(propertyKeys, i)))).close();
}
for (int i = 1; i < relTypes.length; i++) {
tx.execute(format(RELATIONSHIP_CREATE, "rels" + i, asStrList(Arrays.stream(relTypes).limit(i).map(RelationshipType::name).toArray(String[]::new)), asStrList(Arrays.copyOf(propertyKeys, i)))).close();
}
tx.commit();
}
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
tx.commit();
}
managementService.shutdown();
assertIsConsistent(checkConsistency());
}
use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class FulltextIndexConsistencyCheckIT method mustBeAbleToConsistencyCheckRelationshipIndexWithMultipleRelationshipTypesAndMultipleProperties.
@Test
void mustBeAbleToConsistencyCheckRelationshipIndexWithMultipleRelationshipTypesAndMultipleProperties() 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", "p2"))).close();
tx.commit();
}
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
Node n1 = tx.createNode();
Node n2 = tx.createNode();
Relationship r1 = n1.createRelationshipTo(n1, relType1);
r1.setProperty("p1", "value");
r1.setProperty("p2", "value");
Relationship r2 = n1.createRelationshipTo(n1, relType2);
r2.setProperty("p1", "value");
r2.setProperty("p2", "value");
Relationship r3 = n2.createRelationshipTo(n2, relType1);
r3.setProperty("p1", "value");
r3.setProperty("p2", "value");
Relationship r4 = n2.createRelationshipTo(n2, relType2);
r4.setProperty("p1", "value");
r4.setProperty("p2", "value");
n1.createRelationshipTo(n2, relType1).setProperty("p1", "value");
n1.createRelationshipTo(n2, relType2).setProperty("p1", "value");
n1.createRelationshipTo(n2, relType1).setProperty("p2", "value");
n1.createRelationshipTo(n2, relType2).setProperty("p2", "value");
tx.commit();
}
managementService.shutdown();
assertIsConsistent(checkConsistency());
}
use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class StartOldDbOnCurrentVersionAndCreateFusionIndexIT method shouldOpenOldDbAndCreateAndWorkWithSomeFusionIndexes.
private void shouldOpenOldDbAndCreateAndWorkWithSomeFusionIndexes(String zippedDbName, Provider highestProviderInOldVersion) throws Exception {
// given
Path targetDirectory = databaseLayout.databaseDirectory();
unzip(getClass(), zippedDbName, targetDirectory);
IndexRecoveryTracker indexRecoveryTracker = new IndexRecoveryTracker();
// when
Path storeDir = testDirectory.homePath();
managementService = setupDb(storeDir, indexRecoveryTracker);
GraphDatabaseAPI db = getDefaultDatabase();
// then
Provider[] providers = providersUpToAndIncluding(highestProviderInOldVersion);
Provider[] providersIncludingSubject = concat(providers, DEFAULT_PROVIDER);
int fulltextIndexes = 4;
int lookupIndexes = 1;
int expectedNumberOfIndexes = fulltextIndexes + lookupIndexes + providers.length * 2;
try {
// All indexes needs to be rebuilt:
verifyInitialState(indexRecoveryTracker, expectedNumberOfIndexes, InternalIndexState.POPULATING);
// Wait for all populating indexes to finish, so we can verify their contents:
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(10, TimeUnit.MINUTES);
tx.commit();
}
// then
for (Provider provider : providers) {
verifyIndexes(db, provider.label);
}
// when
createIndexesAndData(db, DEFAULT_PROVIDER.label);
// then
verifyIndexes(db, DEFAULT_PROVIDER.label);
// when
for (Provider provider : providersIncludingSubject) {
additionalUpdates(db, provider.label);
// then
verifyAfterAdditionalUpdate(db, provider.label);
}
// then
try (Transaction tx = db.beginTx()) {
IndexDefinition fts1 = tx.schema().getIndexByName("fts1");
Iterator<Label> fts1labels = fts1.getLabels().iterator();
assertTrue(fts1labels.hasNext());
assertEquals(fts1labels.next().name(), "Fts1");
assertFalse(fts1labels.hasNext());
Iterator<String> fts1props = fts1.getPropertyKeys().iterator();
assertTrue(fts1props.hasNext());
assertEquals("prop1", fts1props.next());
assertFalse(fts1props.hasNext());
IndexDefinition fts2 = tx.schema().getIndexByName("fts2");
Iterator<Label> fts2labels = fts2.getLabels().iterator();
assertTrue(fts2labels.hasNext());
assertEquals(fts2labels.next().name(), "Fts2");
assertTrue(fts2labels.hasNext());
assertEquals(fts2labels.next().name(), "Fts3");
assertFalse(fts2labels.hasNext());
Iterator<String> fts2props = fts2.getPropertyKeys().iterator();
assertTrue(fts2props.hasNext());
assertEquals("prop1", fts2props.next());
assertTrue(fts2props.hasNext());
assertEquals("prop2", fts2props.next());
assertFalse(fts2props.hasNext());
IndexDefinition fts3 = tx.schema().getIndexByName("fts3");
Iterator<Label> fts3labels = fts3.getLabels().iterator();
assertTrue(fts3labels.hasNext());
assertEquals(fts3labels.next().name(), "Fts4");
assertFalse(fts3labels.hasNext());
Iterator<String> fts3props = fts3.getPropertyKeys().iterator();
assertTrue(fts3props.hasNext());
assertEquals("prop1", fts3props.next());
assertFalse(fts3props.hasNext());
// TODO verify the index configuration of 'fts3' -- it is eventually consistent.
IndexDefinition fts4 = tx.schema().getIndexByName("fts4");
Iterator<RelationshipType> fts4relTypes = fts4.getRelationshipTypes().iterator();
assertTrue(fts4relTypes.hasNext());
assertEquals(fts4relTypes.next().name(), "FtsRel1");
assertTrue(fts4relTypes.hasNext());
assertEquals(fts4relTypes.next().name(), "FtsRel2");
assertFalse(fts4relTypes.hasNext());
Iterator<String> fts4props = fts4.getPropertyKeys().iterator();
assertTrue(fts4props.hasNext());
assertEquals("prop1", fts4props.next());
assertTrue(fts4props.hasNext());
assertEquals("prop2", fts4props.next());
assertFalse(fts4props.hasNext());
try (var result = tx.execute("CALL db.index.fulltext.queryNodes( 'fts1', 'abc' )").stream()) {
assertEquals(result.count(), 1L);
}
try (var result = tx.execute("CALL db.index.fulltext.queryNodes( 'fts2', 'abc' )").stream()) {
assertEquals(result.count(), 1L);
}
try (var result = tx.execute("CALL db.index.fulltext.queryNodes( 'fts3', 'abc' )").stream()) {
assertEquals(result.count(), 1L);
}
try (var result = tx.execute("CALL db.index.fulltext.queryRelationships( 'fts4', 'abc' )").stream()) {
assertEquals(result.count(), 2L);
}
tx.commit();
}
// and finally
for (Provider provider : providersIncludingSubject) {
verifyExpectedProvider(db, provider.label, provider.descriptor);
}
} finally {
managementService.shutdown();
}
// when
indexRecoveryTracker = new IndexRecoveryTracker();
managementService = setupDb(storeDir, indexRecoveryTracker);
try {
int numberNewIndexes = 2;
verifyInitialState(indexRecoveryTracker, expectedNumberOfIndexes + numberNewIndexes + NUMBER_OF_SYSTEM_INDEXES, InternalIndexState.ONLINE);
} finally {
managementService.shutdown();
}
}
use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class SingleSourceShortestPathBFS method processNextNode.
/**
* Iterator-style "next" method.
* @return True if evaluate was made. False if no more computation could be
* done.
*/
public boolean processNextNode() {
// finished with current layer? increase depth
if (currentLayer.isEmpty()) {
if (nextLayer.isEmpty()) {
return false;
}
currentLayer = nextLayer;
nextLayer = new LinkedList<>();
++depth;
}
Node node = currentLayer.poll();
// times, just process it once
if (distances.containsKey(node)) {
return true;
}
// Put it in distances
distances.put(node, (int) depth);
// Follow all edges
for (RelationshipType relationshipType : relationShipTypes) {
for (Relationship relationship : node.getRelationships(relationShipDirection, relationshipType)) {
Node targetNode = relationship.getOtherNode(node);
// That would be more expensive.
if (!distances.containsKey(targetNode)) {
// Put this into the next layer and the predecessors
nextLayer.add(targetNode);
List<Relationship> targetPreds = predecessors.computeIfAbsent(targetNode, k -> new LinkedList<>());
targetPreds.add(relationship);
}
}
}
return true;
}
use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class ParallelBatchImporterTest method assertDegrees.
private static void assertDegrees(Node node) {
for (RelationshipType type : node.getRelationshipTypes()) {
for (Direction direction : Direction.values()) {
long degree = node.getDegree(type, direction);
long actualDegree = count(node.getRelationships(direction, type));
assertEquals(actualDegree, degree);
}
}
}
Aggregations