io.vertx.ext.unit.Async类的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(130)

本文整理了Java中io.vertx.ext.unit.Async类的一些代码示例,展示了Async类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Async类的具体详情如下:
包路径:io.vertx.ext.unit.Async
类名称:Async

Async介绍

暂无

代码示例

代码示例来源:origin: io.vertx/vertx-config

@Test
 public void testLoadingFromEnvironmentVariables(TestContext context) {
  Async async = context.async();
  getJsonConfiguration(vertx, store, ar -> {
   assertThat(ar.succeeded()).isTrue();
   assertThat(ar.result().getString(KEY_1)).isEqualTo(VAL_1);
   assertThat(ar.result().getString(KEY_2)).isEqualTo(VAL_2);
   async.complete();
  });
 }
}

代码示例来源:origin: de.braintags/vertx-pojo-mapper-common-test

public static void dropTable(TestContext context, String tableName) {
 Async async = context.async();
 ErrorObject<Void> err = new ErrorObject<Void>(null);
 TestHelper.getDatastoreContainer(context).dropTable(tableName, result -> {
  if (result.failed()) {
   err.setThrowable(result.cause());
  }
  async.complete();
 });
 async.await();
 if (err.isError())
  throw err.getRuntimeException();
}

代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync

@Override
 public void handle(AsyncResult<SQLConnection> sqlConnectionAsyncResult) {
  testContext.assertFalse(sqlConnectionAsyncResult.succeeded());
  async.countDown();
 }
};

代码示例来源:origin: de.braintags/vertx-pojo-mapper-common-test

public static void startKeyGeneratorVerticle(TestContext context) {
 if (keyGenVerticle == null) {
  logger.info("init Keygenerator");
  Async async = context.async();
  keyGenVerticle = createKeyGenerator(context);
  vertx.deployVerticle(keyGenVerticle, result -> {
   if (result.failed()) {
    context.fail(result.cause());
    async.complete();
   } else {
    async.complete();
   }
  });
  async.awaitSuccess();
 }
}

代码示例来源:origin: org.openehealth.ipf.oht.atna/ipf-oht-atna-test

@Override
  public void start() throws Exception {
    NetServer netServer = vertx.createNetServer(nsOptions);
    netServer.connectHandler(netSocket -> netSocket.handler(buffer -> {
      log.debug("================= Received content on " + port + ":" + async.count() +
          " =================== \n" + buffer.toString());
      async.countDown();
    })).listen(port);
  }
}

代码示例来源:origin: io.vertx/vertx-kafka-client

static void close(TestContext ctx, Consumer<Handler<AsyncResult<Void>>> producer) {
 if (producer != null) {
  Async closeAsync = ctx.async();
  producer.accept(v -> {
   closeAsync.complete();
  });
  closeAsync.awaitSuccess(10000);
 }
}

代码示例来源:origin: io.vertx/vertx-config

@Test
public void testWithNonExistingPath(TestContext tc) {
 Async async = tc.async();
 store = factory.create(vertx, new JsonObject().put("path", "src/test/missing")
   .put("filesets", new JsonArray().add(new JsonObject().put("pattern", "*.json"))));
 store.get(ar -> {
  assertThat(ar.succeeded()).isTrue();
  assertThat(ar.result()).isEqualTo(Buffer.buffer("{}"));
  async.complete();
 });
}

代码示例来源:origin: io.vertx/vertx-config

@Test
public void testLoadingFromAJsonArrayFile(TestContext context) {
 Async async = context.async();
 store = factory.create(vertx, new JsonObject().put("path", "src/test/resources/file/array.json"));
 getJsonConfiguration(vertx, store, ar -> {
  assertThat(ar.failed()).isTrue();
  async.complete();
 });
}

代码示例来源:origin: io.vertx/vertx-config

private void testEventBusConfigStore(TestContext tc, Object config, boolean send) {
 store = factory.create(vertx, new JsonObject().put("address", "config"));
 Async async = tc.async(2);
 getJsonConfiguration(vertx, store, ar -> {
  assertThat(ar.result().isEmpty()).isTrue();
  async.countDown();
  if (send) {
   vertx.eventBus().send("config", config);
  } else {
   vertx.eventBus().publish("config", config);
  }
  vertx.setTimer(10, tid -> getConfigAndCheck(tc, async));
 });
}

代码示例来源:origin: io.vertx/vertx-web-templ-pebble

@Test
public void noLocaleShouldUseDefaultLocale(TestContext should) {
 final Async test = should.async();
 Locale.setDefault(Locale.US);
 final TemplateEngine engine = PebbleTemplateEngine.create(vertx);
 engine.render(new JsonObject(), "src/test/filesystemtemplates/test-pebble-template-i18n.peb", render2 -> {
  should.assertTrue(render2.succeeded());
  should.assertEquals("Hi", render2.result().toString());
  test.complete();
 });
 test.await();
}

代码示例来源:origin: io.vertx/vertx-config

@Test
public void testDefaultLoading(TestContext tc) {
 Async async = tc.async();
 vertx.runOnContext(v -> {
  vertx.getOrCreateContext().config().put("hello", "hello");
  System.setProperty("foo", "bar");
  retriever = ConfigRetriever.create(vertx);
  retriever.getConfig(ar -> {
   assertThat(ar.result().getString("foo")).isEqualToIgnoringCase("bar");
   assertThat(ar.result().getString("hello")).isEqualToIgnoringCase("hello");
   assertThat(ar.result().getString("PATH")).isNotNull();
   async.complete();
  });
 });
}

代码示例来源:origin: io.vertx/vertx-config

@Test
 public void testLoadingFromEnvironmentVariables(TestContext context) {
  Async async = context.async();
  getJsonConfiguration(vertx, store, ar -> {
   assertThat(ar.succeeded()).isTrue();
   assertThat(ar.result().getInteger(KEY_1)).isEqualTo(Integer.parseInt(VAL_1));
   assertThat(ar.result().getBoolean(KEY_2)).isEqualTo(Boolean.parseBoolean(VAL_2));
   async.complete();
  });
 }
}

代码示例来源:origin: de.braintags/vertx-pojo-mapper-mysql

@Test
public void testQuerySchema(TestContext context) {
 Async async = context.async();
 String queryExpression = "SELECT * FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='test' AND TABLE_NAME='SimpleMapper'; ";
 SqlUtil.query((MySqlDataStore) getDataStore(context), queryExpression, ur -> {
  if (ur.failed()) {
   context.fail(ur.cause().toString());
   async.complete();
  } else {
   ResultSet res = ur.result();
   LOGGER.info("found records: " + res.getNumRows());
   async.complete();
  }
 });
}

代码示例来源:origin: io.vertx/vertx-tcp-eventbus-bridge

@Test
public void testSendVoidMessage(TestContext context) {
 // Send a request and get a response
 NetClient client = vertx.createNetClient();
 final Async async = context.async();
 vertx.eventBus().consumer("test", (Message<JsonObject> msg) -> {
  client.close();
  async.complete();
 });
 client.connect(7000, "localhost", conn -> {
  context.assertFalse(conn.failed());
  NetSocket socket = conn.result();
  FrameHelper.sendFrame("send", "test", new JsonObject().put("value", "vert.x"), socket);
 });
}

代码示例来源:origin: io.vertx/vertx-web-templ-mvel

@Test
public void testNoSuchTemplate(TestContext should) {
 final Async test = should.async();
 TemplateEngine engine = MVELTemplateEngine.create(vertx);
 engine.render(new JsonObject(), "nosuchtemplate.templ", render -> {
  should.assertFalse(render.succeeded());
  test.complete();
 });
 test.await();
}

代码示例来源:origin: io.vertx/vertx-mail-service

@Before
public void startVerticle(TestContext testContext) {
 Async async = testContext.async();
 JsonObject config = new JsonObject("{\"config\":{\"address\":\"vertx.mail\",\"hostname\":\"localhost\",\"port\":1587}}");
 DeploymentOptions deploymentOptions = new DeploymentOptions(config);
 vertx.deployVerticle("io.vertx.ext.mail.MailServiceVerticle", deploymentOptions ,r -> {
  if(r.succeeded()) {
   log.info(r.result());
   async.complete();
  } else {
   log.info("exception", r.cause());
   testContext.fail(r.cause());
  }
 });
}

代码示例来源:origin: io.vertx/vertx-mqtt

@Test
public void connectDisconnect(TestContext context) throws InterruptedException {
 Async async = context.async();
 MqttClient client = MqttClient.create(Vertx.vertx());
 client.connect(TestUtil.BROKER_PORT, TestUtil.BROKER_ADDRESS, c -> {
  assertTrue(c.succeeded());
  client
   .disconnect(ar -> {
    assertTrue(ar.succeeded());
    async.countDown();
   });
 });
 async.await();
}

代码示例来源:origin: io.vertx/vertx-tcp-eventbus-bridge

@Before
public void before(TestContext context) {
 vertx = Vertx.vertx();
 final Async async = context.async();
 vertx.eventBus().consumer("hello", (Message<JsonObject> msg) -> msg.reply(new JsonObject().put("value", "Hello " + msg.body().getString("value"))));
 TcpEventBusBridge bridge = TcpEventBusBridge.create(
     vertx,
     new BridgeOptions()
         .addInboundPermitted(new PermittedOptions())
         .addOutboundPermitted(new PermittedOptions()));
 bridge.listen(7000, res -> {
  context.assertTrue(res.succeeded());
  async.complete();
 });
}

代码示例来源:origin: de.braintags/vertx-util

protected void undeployVerticle(TestContext context, AbstractVerticle verticle) {
 LOGGER.debug("undeploying verticle " + verticle.deploymentID());
 Async async = context.async();
 vertx.undeploy(verticle.deploymentID(), result -> {
  if (result.failed()) {
   LOGGER.error(result.cause());
   context.fail(result.cause());
   async.complete();
  } else {
   LOGGER.debug("succeeded undeploying verticle " + verticle.deploymentID());
   async.complete();
  }
 });
 async.awaitSuccess();
 LOGGER.debug("finished undeploying verticle " + verticle.deploymentID());
}

代码示例来源:origin: io.vertx/vertx-mail-client

@Test
public final void testClosedSend(TestContext testContext) {
 Async async = testContext.async();
 MailClient mailClient = new MailClientImpl(vertx, new MailConfig(), "foo");
 mailClient.close();
 mailClient.sendMail(new MailMessage(), result -> {
  if (result.succeeded()) {
   log.info(result.result().toString());
   testContext.fail("this test should throw an Exception");
  } else {
   log.warn("got exception", result.cause());
   async.complete();
  }
 });
}

相关文章