All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.ext.unit.impl.TestContextTask Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR3
Show newest version
package io.vertx.ext.unit.impl;

import io.vertx.core.Handler;
import io.vertx.ext.unit.TestContext;

import java.util.Map;
import java.util.function.Function;

/**
 * @author Julien Viet
 */
public class TestContextTask implements Task {

  private final TestContextImpl testContext;
  private final Handler callback;
  private Function> next;
  private final long timeout;

  public TestContextTask(TestContextImpl testContext, Handler callback, Task next, long timeout) {
    this.testContext = testContext;
    this.callback = callback;
    this.next = result -> next;
    this.timeout = timeout;
  }

  public TestContextTask(TestContextImpl testContext, Handler callback, Function> next, long timeout) {
    this.testContext = testContext;
    this.callback = callback;
    this.next = next;
    this.timeout = timeout;
  }

  @Override
  public void execute(Result prev, ExecutionContext context) {
    long beginTime;
    if (prev != null) {
      beginTime = prev.beginTime;
    } else {
      beginTime = System.currentTimeMillis();
    }
    testContext.run(prev != null ? prev.failure : null, timeout, callback, failed -> {
      long endTime = System.currentTimeMillis();
      Result result = new Result(beginTime, endTime, failed);
      context.run(next.apply(result), result);
    });
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy