Java Code Examples for io.vertx.junit5.VertxTestContext#awaitCompletion()
The following examples show how to use
io.vertx.junit5.VertxTestContext#awaitCompletion() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractHealthServiceTest.java From cassandra-sidecar with Apache License 2.0 | 6 votes |
@BeforeEach void setUp() throws InterruptedException { Injector injector = Guice.createInjector(Modules.override(new MainModule()).with(getTestModule())); server = injector.getInstance(HttpServer.class); check = injector.getInstance(MockHealthCheck.class); service = injector.getInstance(HealthService.class); vertx = injector.getInstance(Vertx.class); config = injector.getInstance(Configuration.class); VertxTestContext context = new VertxTestContext(); server.listen(config.getPort(), context.completing()); context.awaitCompletion(5, TimeUnit.SECONDS); }
Example 2
Source File: PlatformFeaturesAvailabilityTest.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
public HttpServer startMockApi(VertxTestContext context, String version, List<String> apis) throws InterruptedException { Checkpoint start = context.checkpoint(); HttpServer server = vertx.createHttpServer().requestHandler(request -> { if (HttpMethod.GET.equals(request.method()) && apis.contains(request.uri())) { request.response().setStatusCode(200).end(); } else if (HttpMethod.GET.equals(request.method()) && "/version".equals(request.uri())) { request.response().setStatusCode(200).end(version); } else { request.response().setStatusCode(404).end(); } }).listen(0, res -> { if (res.succeeded()) { start.flag(); } else { throw new RuntimeException(res.cause()); } }); if (!context.awaitCompletion(60, TimeUnit.SECONDS)) { context.failNow(new Throwable("Test timeout")); } return server; }
Example 3
Source File: TopicOperatorMockTest.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
Topic getFromKafka(VertxTestContext context, String topicName) throws InterruptedException { AtomicReference<Topic> ref = new AtomicReference<>(); Checkpoint async = context.checkpoint(); Future<TopicMetadata> kafkaMetadata = session.kafka.topicMetadata(new TopicName(topicName)); kafkaMetadata.map(metadata -> TopicSerialization.fromTopicMetadata(metadata)).onComplete(fromKafka -> { if (fromKafka.succeeded()) { ref.set(fromKafka.result()); } else { context.failNow(fromKafka.cause()); } async.flag(); }); if (!context.awaitCompletion(60, TimeUnit.SECONDS)) { context.failNow(new Throwable("Test timeout")); } return ref.get(); }
Example 4
Source File: PlatformFeaturesAvailabilityTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
public void stopMockApi(VertxTestContext context, HttpServer server) throws InterruptedException { Checkpoint async = context.checkpoint(); server.close(res -> { if (res.succeeded()) { async.flag(); } else { throw new RuntimeException("Failed to stop Mock HTTP server"); } }); if (!context.awaitCompletion(60, TimeUnit.SECONDS)) { context.failNow(new Throwable("Test timeout")); } }
Example 5
Source File: TopicOperatorMockTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
void reconcile(VertxTestContext context) throws InterruptedException { Checkpoint async = context.checkpoint(); session.topicOperator.reconcileAllTopics("test").onComplete(ar -> { if (!ar.succeeded()) { context.failNow(ar.cause()); } async.flag(); }); if (!context.awaitCompletion(60, TimeUnit.SECONDS)) { context.failNow(new Throwable("Test timeout")); } }