当前位置: 首页 > 知识库问答 >
问题:

在IntelliJ IDEA中从JUnit测试中运行时登录服务器扩展的Neo4j

苏凯
2023-03-14

我使用以下方法获取过程类中的org.neo4j.logging.log对象:

@Context
public Log log;

然后我在方法中使用它:

log.info("Info message...");

当运行neo4j并调用扩展时,这可以很好地工作,但是当使用JUnit测试中创建的服务器实例从Intellij内部运行时,日志是不可见的。

package graphEngine;

import GraphComponents.TestGraphQueries;
import org.junit.Rule;
import org.junit.Test;
import org.neo4j.driver.v1.Config;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.GraphDatabase;
import org.neo4j.driver.v1.Session;
import org.neo4j.harness.junit.Neo4jRule;

public class ComputeTest {

    @Rule
    public Neo4jRule neo4j = new Neo4jRule()
            .withProcedure(Compute.class)
            .withProcedure(TestGraphQueries.class);

    @Test
    public void shouldFindMatchingSystems() throws Throwable {
        try(Driver driver = GraphDatabase.driver( neo4j.boltURI() , Config.build()
                .withEncryptionLevel( Config.EncryptionLevel.NONE ).toConfig() );

            Session session = driver.session() ) {

            session.run("CALL graphEngine.loadGraph");

            session.run("CALL graphEngine.compute(8)");

        }
    }

}

共有1个答案

宰父劲
2023-03-14

我也遇到了同样的问题(Visual Studio Code/Maven/Neo4J CE 3.2.0),并通过以下解决方法解决了它:

定义文件夹,因为必须运行neo4j-server实例,并将日志目录和运行目录的路径设置为规则配置项:

public class TestClass {
...
private static final String basePath = "C:\\Development\\myworkspaces\\myproject\\run";

private static final String serverPath = basePath + "\\neo4j";

private static final String logsPath = basePath + "\\logs";

...

@Rule
public Neo4jRule neo4j = new Neo4jRule(
                              new File(
                                TestClass.serverPath
                              )
                           )
  ...
  .withConfig("dbms.directories.logs", TestClass.logsPath)
  .withConfig("dbms.directories.run", TestClass.basePath)
  .withConfig("dbms.logs.debug.level", "DEBUG")
  ...

实现一个方法来备份当前服务器实例中的日志数据(在类中的每个测试方法之后):

@After
public void backupLogMessages() {
File serverFolder = new File(serverPath);
Arrays.stream(serverFolder.listFiles())
  .filter(f -> f.isDirectory())
    .forEach(d -> 
    {
        Optional<File> logFile = 
          Arrays.stream(d.listFiles())
            .filter(fnd -> !fnd.isDirectory())
            .filter(ff -> ff.getName().indexOf("neo4j") != -1)
            .findFirst();
        logFile.ifPresent(lf -> 
        {
          String parentFolderName 
            = lf.getParent()
              .substring(lf.getParent().lastIndexOf("\\")+1);
          Path logPath 
            = FileSystems
              .getDefault()
              .getPath(TestClass.logsPath);
          String absolutePath 
            = logPath
              .toAbsolutePath().toString();
          try {
            FileUtils.copyFile(
              lf, 
              new File(absolutePath 
                + "\\" + parentFolderName 
                + "_neo4j.log")
            );
          } catch (IOException ioe) {
            ioe.printStackTrace();
          }
  });
});
}
 类似资料:
  • 问题内容: 我正在尝试编写一个集成测试以在本地启动Jetty服务器,然后使用客户端与其余URI进行通信并在下游调用业务逻辑。但是,当我启动码头服务器时,它不会放弃该控件,因此不会执行我的客户端。因此,我使用线程在另一个线程中启动我的码头,但是,该线程在我的客户端调用之前完成,它说连接被拒绝。我可以采取什么方法? 问题答案: 跳过,跳过 该调用将在服务器自己的线程(以及服务器所需的所有其他线程)上启

  • 如果使用重新运行jupiter扩展失败,我将尝试重复选定的测试。它在IntelliJ IDEA中运行良好,但在Jenkins上出现此消息时失败, 根本不执行任何测试,整个测试套件一开始就失败了。

  • 我为我创建的驱动程序的测试创建了一个自定义标记。我正在寻找一种方法,使用新的Junit5 jupiter扩展在beforeach和AfterEach期间初始化和退出这个驱动程序。 我看到有一个AnnotationSupport.class应该可以帮助你获得用特定注释标注的字段,但是没有找到任何例子。 我想要的只是能够使用扩展中用我的注释标注的字段。

  • 我正在使用Camel 2.14.0和Spring 3.2.11。使用Spring DSL和扩展CamelSpringTestSupport的JUnit 4类发布并测试Camel路由。我的问题是,我找不到向注册表添加bean(mock)的方法。我已经重写了createJndiContext()方法,但它从未被调用。测试时如何向注册表添加bean? 你好马特

  • 有没有办法集成测试我的JUnit Jupiter扩展?当然,我可以测试扩展用法的一个很好的例子,但我想测试如下内容: 它没有通过预期的测试吗? 测试结束时写的报告是否正确? 对此有内置的支持吗?

  • 当我为我的项目运行我的bitbucket管道时,我在颤振测试期间得到一个错误: /root/.pub-cache/hosted/pub.dartlang.org/firebase_core-1.24.0/lib/src/firebase_app.dart: 18:25:错误:未找到成员:'FirebaseAppPlatform.verify扩展'。FirebaseAppPlatform.verif