Skip to content

Edges iterable cannot be called more than once for edges Direction IN & BOTH #3152

@astone282

Description

@astone282

Problem
Calling getRelationships() returns an iterable. If looped against (.iterator() invoked) more than once, returns no data on the second iteration. Seems to be only Direction.IN and Direction.BOTH (likely rooted in Direction.IN), but not Direction.OUT. Direction.OUT works fine.

Reproducible unit test below.

Expected Behavior
getEdges() returns an iterable which should return a new version of iterator each time iterator() is called. So looping on the iterable should return the same result set each time.

Cause
Unknown, but from a quick peak it looks like the iterator does try to reset itself but something doesn't get reset I guess, likely focused on the IN portion of the MultiIterator



import static org.junit.Assert.assertEquals;

import com.arcadedb.database.Database;
import com.arcadedb.database.DatabaseFactory;
import com.arcadedb.database.RID;
import com.arcadedb.graph.Edge;
import com.arcadedb.graph.IterableGraph;
import com.arcadedb.graph.MutableVertex;
import com.arcadedb.graph.Vertex;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class RelItrTest
{
    final String typeA = "myTestTypeA";
    final String typeRel = "myTestTypeRel";
    private Database database;

    @Before
    public void setup()
    {
        final DatabaseFactory factory = new DatabaseFactory("./target/databases/ArcadeNodeTest");
        if (factory.exists())
        {
            factory.open().drop();
        }
        database = factory.create();
        database.transaction(() -> {
            database.getSchema().buildVertexType().withName(typeA).withIgnoreIfExists(true).create();
            database.getSchema().buildEdgeType().withName(typeRel).withIgnoreIfExists(true).create();
        });
    }

    @After
    public void cleanup()
    {
        if (database.isTransactionActive())
        {
            database.rollback();
        }
        database.drop();
    }

    @Test
    public void testIterableReuseIn()
    {
        testIterable(Vertex.DIRECTION.IN); // Fails
    }

    @Test
    public void testIterableReuseOut()
    {
        testIterable(Vertex.DIRECTION.OUT); // Works
    }

    @Test
    public void testIterableReuseBoth()
    {
        testIterable(Vertex.DIRECTION.BOTH); // Fails
    }

    public void testIterable(Vertex.DIRECTION direction)
    {
        final RID[] rid = new RID[1];
        database.transaction(() -> {
            MutableVertex nodeA = database.newVertex(typeA);
            MutableVertex nodeB = database.newVertex(typeA);
            MutableVertex nodeC = database.newVertex(typeA);
            MutableVertex nodeD = database.newVertex(typeA);

            nodeA.save();
            nodeB.save();
            nodeC.save();
            nodeD.save();

            nodeA.newEdge(typeRel, nodeB);
            nodeA.newEdge(typeRel, nodeC);
            nodeA.newEdge(typeRel, nodeD);

            rid[0] = nodeA.getIdentity();
        });

        database.transaction(() -> {
            Vertex nodeA = rid[0].asVertex();

            String[] typesSet = new String[] {typeRel};
            IterableGraph<Edge> lIterable = nodeA.getEdges(direction, typesSet);
            int count = 0;
            for (Edge rel : lIterable)
            {
                count++;
            }
            assertEquals(3, count);

            count = 0;
            for (Edge rel : lIterable)
            {
                count++;
            }
            assertEquals(3, count);
        });
    }
}

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions