Search in sources :

Example 16 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class AllNodesInStoreExistInLabelIndexTest method mustReportMissingLabel.

@Test
void mustReportMissingLabel() throws Exception {
    // given
    List<Pair<Long, Label[]>> nodesInStore = someData();
    Path labelIndexFileCopy = copyLabelIndexFile();
    // when
    try (Transaction tx = db.beginTx()) {
        addLabelToExistingNode(tx, nodesInStore);
        tx.commit();
    }
    // and
    replaceLabelIndexWithCopy(labelIndexFileCopy);
    // then
    ConsistencyCheckService.Result result = fullConsistencyCheck();
    assertFalse(result.isSuccessful(), "Expected consistency check to fail");
}
Also used : Path(java.nio.file.Path) Transaction(org.neo4j.graphdb.Transaction) Label(org.neo4j.graphdb.Label) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) Pair(org.neo4j.internal.helpers.collection.Pair) Test(org.junit.jupiter.api.Test)

Example 17 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class AllNodesInStoreExistInLabelIndexTest method mustReportExtraNode.

@Test
void mustReportExtraNode() throws Exception {
    // given
    List<Pair<Long, Label[]>> nodesInStore = someData();
    Path labelIndexFileCopy = copyLabelIndexFile();
    // when
    try (Transaction tx = db.beginTx()) {
        removeExistingNode(tx, nodesInStore);
        tx.commit();
    }
    // and
    replaceLabelIndexWithCopy(labelIndexFileCopy);
    // then
    ConsistencyCheckService.Result result = fullConsistencyCheck();
    assertFalse(result.isSuccessful(), "Expected consistency check to fail");
}
Also used : Path(java.nio.file.Path) Transaction(org.neo4j.graphdb.Transaction) Label(org.neo4j.graphdb.Label) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) Pair(org.neo4j.internal.helpers.collection.Pair) Test(org.junit.jupiter.api.Test)

Example 18 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class AllNodesInStoreExistInLabelIndexTest method mustReportExtraLabelsOnExistingNode.

@Test
void mustReportExtraLabelsOnExistingNode() throws Exception {
    // given
    List<Pair<Long, Label[]>> nodesInStore = someData();
    Path labelIndexFileCopy = copyLabelIndexFile();
    // when
    try (Transaction tx = db.beginTx()) {
        removeLabelFromExistingNode(tx, nodesInStore);
        tx.commit();
    }
    // and
    replaceLabelIndexWithCopy(labelIndexFileCopy);
    // then
    ConsistencyCheckService.Result result = fullConsistencyCheck();
    assertFalse(result.isSuccessful(), "Expected consistency check to fail");
}
Also used : Path(java.nio.file.Path) Transaction(org.neo4j.graphdb.Transaction) Label(org.neo4j.graphdb.Label) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) Pair(org.neo4j.internal.helpers.collection.Pair) Test(org.junit.jupiter.api.Test)

Example 19 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class IndexConsistencyIT method someData.

void someData(int numberOfModifications) {
    List<Pair<Long, Label[]>> existingNodes;
    existingNodes = new ArrayList<>();
    try (Transaction tx = db.beginTx()) {
        randomModifications(tx, existingNodes, numberOfModifications);
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        tx.schema().indexFor(LABEL_ONE).on(PROPERTY_KEY).create();
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
        tx.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Label(org.neo4j.graphdb.Label) Pair(org.neo4j.internal.helpers.collection.Pair)

Example 20 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class NodeRelationshipCacheTest method shouldCacheMultipleDenseNodeRelationshipHeads.

@Test
public void shouldCacheMultipleDenseNodeRelationshipHeads() {
    // GIVEN
    cache = new NodeRelationshipCache(NumberArrayFactories.HEAP, 1, INSTANCE);
    cache.setNodeCount(10);
    long nodeId = 3;
    cache.setCount(nodeId, 10, /*these do not matter ==>*/
    0, OUTGOING);
    // WHEN
    Map<Pair<Integer, Direction>, Long> firstRelationshipIds = new HashMap<>();
    int typeCount = 3;
    for (int typeId = 0, relationshipId = 0; typeId < typeCount; typeId++) {
        for (Direction direction : Direction.values()) {
            long firstRelationshipId = relationshipId++;
            cache.getAndPutRelationship(nodeId, typeId, direction, firstRelationshipId, true);
            firstRelationshipIds.put(Pair.of(typeId, direction), firstRelationshipId);
        }
    }
    AtomicInteger visitCount = new AtomicInteger();
    NodeRelationshipCache.GroupVisitor visitor = (nodeId1, typeId, out, in, loop) -> {
        visitCount.incrementAndGet();
        assertEquals(firstRelationshipIds.get(Pair.of(typeId, OUTGOING)).longValue(), out);
        assertEquals(firstRelationshipIds.get(Pair.of(typeId, INCOMING)).longValue(), in);
        assertEquals(firstRelationshipIds.get(Pair.of(typeId, BOTH)).longValue(), loop);
        return 0;
    };
    cache.getFirstRel(nodeId, visitor);
    // THEN
    assertEquals(typeCount, visitCount.get());
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Direction(org.neo4j.graphdb.Direction) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) OUTGOING(org.neo4j.graphdb.Direction.OUTGOING) MutableIntObjectMap(org.eclipse.collections.api.map.primitive.MutableIntObjectMap) HashMap(java.util.HashMap) MutableLongObjectMap(org.eclipse.collections.api.map.primitive.MutableLongObjectMap) ArrayList(java.util.ArrayList) IntObjectMaps(org.eclipse.collections.impl.factory.primitive.IntObjectMaps) BOTH(org.neo4j.graphdb.Direction.BOTH) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RandomRule(org.neo4j.test.rule.RandomRule) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) After(org.junit.After) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Parameterized(org.junit.runners.Parameterized) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) INCOMING(org.neo4j.graphdb.Direction.INCOMING) Mockito.verify(org.mockito.Mockito.verify) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) List(java.util.List) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) Math.max(java.lang.Math.max) Pair(org.neo4j.internal.helpers.collection.Pair) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) HashMap(java.util.HashMap) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Direction(org.neo4j.graphdb.Direction) Pair(org.neo4j.internal.helpers.collection.Pair) Test(org.junit.Test)

Aggregations

Pair (org.neo4j.internal.helpers.collection.Pair)39 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)22 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)22 ArrayList (java.util.ArrayList)15 HashSet (java.util.HashSet)12 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)12 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)11 ValueSource (org.junit.jupiter.params.provider.ValueSource)9 TextValue (org.neo4j.values.storable.TextValue)9 PointValue (org.neo4j.values.storable.PointValue)8 Value (org.neo4j.values.storable.Value)8 Values.stringValue (org.neo4j.values.storable.Values.stringValue)8 Values.pointValue (org.neo4j.values.storable.Values.pointValue)7 Test (org.junit.jupiter.api.Test)6 HashMap (java.util.HashMap)5 Label (org.neo4j.graphdb.Label)5 Path (java.nio.file.Path)4 Transaction (org.neo4j.graphdb.Transaction)4 Map (java.util.Map)3