一起使用mariadb4j和vertx.io单元测试

时间:2018-03-25 15:22:10

标签: java junit mariadb vert.x

我正在尝试mariadb4j,我正在尝试在我的VertxUnit测试中使用它。 mariadb4j看起来容易,但我面临一些奇怪的行为。在我的@BeforeAll方法中,我设置了一个mariadb4j实例,创建了一个数据库并用表填充它。然后在每个测试中,我截断感兴趣的表并用前置条行填充它。前提条件行以某些.sql资源表示,因此,在每个测试中,我只需运行db.source("precondition_rows_about_this_test.sql", "root", "", "dbstuff");命令。但测试挂起在日志中显示此消息:

2018-03-25 16:48:07 INFO  ManagedProcess:144 - Starting Program [C:\Users\myname\AppData\Local\Temp\MariaDB4j\base\bin\mysql.exe, -uroot, -p, -Ddbstuff, --port=52733] (in working directory C:\Users\myname\AppData\Local\Temp\MariaDB4j\base)
2018-03-25 16:48:07 INFO  ManagedProcess:383 - Thread is now going to wait for this process to terminate itself: Program [C:\Users\myname\AppData\Local\Temp\MariaDB4j\base\bin\mysql.exe, -uroot, -p, -Ddbstuff, --port=52733] (in working directory C:\Users\myname\AppData\Local\Temp\MariaDB4j\base)

这是我的测试:

@BeforeClass
public static void initAll() throws Exception {
  DBConfigurationBuilder dbConfBuilder = DBConfigurationBuilder.newBuilder();
  dbConfBuilder.setPort(0);
  dbConf = dbConfBuilder.build();
  db = DB.newEmbeddedDB(dbConf);
  db.start();
  db.createDB("dbstuff");
  db.source("dbstuff.sql", "root", null, "dbstuff");
}

@Before
public void initTest(TestContext ctx) throws Exception {
  db.run("use dbstuff; truncate table stuff");
  query = new JsonObject();
  VertxOptions vertxOptions = new VertxOptions();
  vertxOptions.setMaxEventLoopExecuteTime(Long.MAX_VALUE);
  vertx = new VertxFactoryImpl().vertx(vertxOptions);

  DeploymentOptions dbDeploymentOptions = new DeploymentOptions();
  dbDeploymentOptions.setConfig(new JsonObject());
  dbDeploymentOptions.getConfig().put("url", "jdbc:mariadb://localhost:" + dbConf.getPort() + "/dbstuff");
  dbDeploymentOptions.getConfig().put("user", "root");
  dbDeploymentOptions.getConfig().put("password", "");

  vertx.deployVerticle(RecipesPlanner.class, dbDeploymentOptions, ctx.asyncAssertSuccess());
}

@Test
public void recipePlannerComputeRecipePlanAbout10AllQueryPlanAndThereIsOnly1RecipeInDb(TestContext ctx)
    throws Exception {
  Async async = ctx.async();
  db.source("1goodstuff.sql", "root", "", "dbstuff");
  vertx.eventBus().send("givestuff", query, new DeliveryOptions().addHeader("action", "get-stuff"),
    msg -> {
        if (msg.failed())
          log.error(msg.cause());
        ctx.assertTrue(msg.succeeded());
        log.info(msg.result().body().toString());
        JsonArray stuff = new JsonArray(msg.result().body().toString());
        ctx.assertEquals(10, stuf.size());
        async.complete();
    });
}

好吧,在@Test方法中,测试在db.source行上挂起。当然我确定.sql文件是正确的。我正在使用vertx.io 3.5.1mariadb4j 2.2.3。我错过了什么?

0 个答案:

没有答案