Search in sources :

Example 6 with RelationshipData

use of org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData in project neo4j by neo4j.

the class RelationshipModifierTest method shouldCreateAndDelete.

// ... other known cases ...
@RepeatedTest(20)
void shouldCreateAndDelete() {
    // given and initial state
    long node = createEmptyNode();
    IntSupplier typeStrategy = randomTypes(10);
    Supplier<RelationshipDirection> directionStrategy = RANDOM_DIRECTION;
    LongSupplier otherNodeStrategy = this::createEmptyNode;
    int maxRelationships = 100;
    List<RelationshipData> expectedRelationships = generateRelationshipData(random.nextInt(0, maxRelationships), node, typeStrategy, otherNodeStrategy, directionStrategy);
    createRelationships(expectedRelationships);
    // ... a set of relationships to create and delete
    List<RelationshipData> relationshipsToCreate = generateRelationshipData((int) random.among(new long[] { 0, 1, 10, 100 }), node, typeStrategy, otherNodeStrategy, directionStrategy);
    int numRelationshipsToDelete = min((int) random.among(new long[] { 0, 1, 10, maxRelationships }), expectedRelationships.size());
    RelationshipData[] relationshipsToDelete = random.selection(expectedRelationships.toArray(RelationshipData[]::new), numRelationshipsToDelete, numRelationshipsToDelete, false);
    // ... and rules for how the world changes "concurrently" while we perform these modifications
    // on locked
    monitors.addMonitorListener(new ResourceTypeLockOrderVerifier());
    // on read
    monitors.addMonitorListener(new ChangeWorldOnReadMonitor(node, typeStrategy, otherNodeStrategy, directionStrategy, expectedRelationships));
    // when
    RelationshipModifications modifications = modifications(relationshipsToCreate.toArray(RelationshipData[]::new), relationshipsToDelete);
    modify(modifications);
    applyModificationsToExpectedRelationships(modifications, expectedRelationships);
    // then
    assertThat(readRelationshipsFromStore(node, store)).isEqualTo(asSet(expectedRelationships));
}
Also used : RelationshipData(org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData) RelationshipModifications(org.neo4j.storageengine.api.txstate.RelationshipModifications) RelationshipDirection(org.neo4j.storageengine.api.RelationshipDirection) IntSupplier(java.util.function.IntSupplier) LongSupplier(java.util.function.LongSupplier) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Aggregations

RelationshipData (org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData)6 ArrayList (java.util.ArrayList)3 RepeatedTest (org.junit.jupiter.api.RepeatedTest)3 Test (org.junit.jupiter.api.Test)3 RelationshipDirection (org.neo4j.storageengine.api.RelationshipDirection)3 IntSupplier (java.util.function.IntSupplier)2 LongSupplier (java.util.function.LongSupplier)2 RelationshipModifications (org.neo4j.storageengine.api.txstate.RelationshipModifications)2 Integer.min (java.lang.Integer.min)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Consumer (java.util.function.Consumer)1