我正在尝试使用 VertxUnitRunner.class 运行 junit 测试用例。我有 35 个测试用例,每次都会为不同的测试用例获取并发异常。我正在使用 jenkins 在 VM 机器上运行这些测试用例。
有谁知道这个的解决方案?
@RunWith(VertxUnitRunner.class)
public class KeyMgmtMainTest {
private Environment env;
private String host;
private int port;
@Before
public void init(TestContext context) {
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "xyz-abc-servlet.xml" });
vertx = Vertx.factory.vertx();
vertx.deployVerticle(new ABC1Verticle(ctx), context.asyncAssertSuccess());
vertx.deployVerticle(new ABC2VerticleTest(ctx), context.asyncAssertSuccess());
vertx.deployVerticle(new ABC3ConsumerVerticleTest(ctx), context.asyncAssertSuccess());
vertx.deployVerticle(new ABC4ConsumerVerticleTest(ctx), context.asyncAssertSuccess());
env = ctx.getBean(Environment.class);
port = Integer.parseInt(env.getProperty("http.server.port"));
host = env.getProperty("cluster.host");
}
@Test
public void testSaveDomain(TestContext context) {
final Async async = context.async();
final String token = "Bearer";
Domain domain = new Domain();
domain.setDomainName("XXX");
domain.setTenantId("YYYY.com");
domain.setCreatedBy("admin");
domain.setUpdatedBy("admin");
vertx.createHttpClient().post(port, host, "/my/url/domain").putHeader("Authorization", token)
.setChunked(true).handler(response -> {
response.bodyHandler(body -> {
context.assertEquals(200, response.statusCode());
JsonObject json = new JsonObject(body.toString());
json = json.getJsonObject("domain");
context.assertTrue(json.getLong("domainId") == 1);
context.assertTrue(json.getString("domainName").equals("Lighting"));
async.complete();
});
}).write(Json.encode(domain)).end();
}
@After
public void tearDown(TestContext context) {
vertx.close(context.asyncAssertSuccess());
}
}