2

当我想在 setUp() 方法中创建 GraphDatabaseService 时,如下所示:

      private GraphDatabaseService graphDb;

      @BeforeMethod
      public void setUp() throws Exception {
        graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
      }

我得到错误:

java.lang.AbstractMethodError: org.neo4j.test.impl.EphemeralFileSystemAbstraction.autoCreatePath(Ljava/io/File;)V
    at org.neo4j.kernel.StoreLocker.lock(StoreLocker.java:73)
    at org.neo4j.kernel.InternalAbstractGraphDatabase.create(InternalAbstractGraphDatabase.java:287)
    at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:227)
    at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:79)
    at org.neo4j.test.ImpermanentGraphDatabase.<init>(ImpermanentGraphDatabase.java:78)
    at org.neo4j.test.TestGraphDatabaseFactory$1.newDatabase(TestGraphDatabaseFactory.java:46)
    at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:205)
    at org.neo4j.test.TestGraphDatabaseFactory.newImpermanentDatabase(TestGraphDatabaseFactory.java:36)
    at pl.piotr0123456.neo4j.operations.GraphOperationsTest.setUp(GraphOperationsTest.java:29)

作为解决方法,我使用:

     graphDb = new TestGraphDatabaseFactory().newEmbeddedDatabase("target/testGraph/test1");

带有事务回滚。但我认为这不是一个好的解决方案。

是否可以为内存中的每个单元测试清洁图创建?

4

1 回答 1

2

在幕后,ImpermanentGraphDatabase 在文件系统上使用test-data/impermanent-db(在 1.9.RC2 中)。你也可以

  • 确保test-data/impermanent-db有足够的权限
  • 不使用工厂直接实例化 ImpermanentGraphDatabase: new org.neo4j.test.ImpermanentGraphDatabase(myStoreDirectory)myStoreDirectory例如,可能是一个临时目录。

请注意,如果您并行运行多个测试。在这种情况下,您应该使用第二种方法,因为不允许多个 ImpermanentGraphDatabase 实例共享同一个存储目录。

于 2013-05-05T08:54:42.907 回答