Giter Site home page Giter Site logo

Comments (2)

vga91 avatar vga91 commented on June 25, 2024

Isolated test case

Note that the issue occurs also with a test container and with a real Neo4j instance

import apoc.util.TestUtil;
import org.junit.*;
import org.neo4j.graphdb.*;
import org.neo4j.procedure.*;
import org.neo4j.test.rule.*;

import java.util.Map;
import java.util.stream.Stream;

public class PendingTest {

    public static class MockProcedure {
        public record MockResult(String value) {}

        @Context public GraphDatabaseService db;

        @Procedure(name = "my.proc", mode = Mode.SCHEMA)
        public Stream<MockResult> myProcedure() {
            // should throw an EquivalentSchemaRuleAlreadyExistsException,
            // instead it remains in pending
            db.executeTransactionally("CREATE CONSTRAINT FOR (n:Person) REQUIRE n.name IS UNIQUE", Map.of(), Result::resultAsString);
            return Stream.of(new MockResult("test"));
        }
    }

    @ClassRule
    public static DbmsRule db = new ImpermanentDbmsRule();

    @BeforeClass
    public static void setUp() {
        TestUtil.registerProcedure(db, MockProcedure.class);
    }

    @Test
    public void test() {
        db.executeTransactionally("CREATE CONSTRAINT FOR (n:Person) REQUIRE n.name IS UNIQUE");

        try {
            db.executeTransactionally("CALL my.proc()", Map.of(), Result::resultAsString);
        } catch (Exception e) {
            Assert.assertTrue(e.getMessage().contains("equivalent constraint already exists"));
        }
    }
}

NOTE: By changing the MockProcedure class to the following, solves the problem:

    public static class MockProcedure {
        public record MockResult(String value) {}

        @Context public Transaction tx;

        @Procedure(name = "my.proc", mode = Mode.SCHEMA)
        public Stream<MockResult> myProcedure() {
            tx.execute("CREATE CONSTRAINT FOR (n:Person) REQUIRE n.name IS UNIQUE", Map.of()).resultAsString();
            return Stream.of(new MockResult("test"));
        }
    }

from neo4j-apoc-procedures.

vga91 avatar vga91 commented on June 25, 2024

Since it might be a Neo4j issue, I also created a similar issue in the main repository

\cc @jexp

from neo4j-apoc-procedures.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.