io.hyperfoil.core.steps.AwaitDelayStep Maven / Gradle / Ivy
package io.hyperfoil.core.steps;
import java.util.Collections;
import java.util.List;
import org.kohsuke.MetaInfServices;
import io.hyperfoil.api.config.InitFromParam;
import io.hyperfoil.api.config.Name;
import io.hyperfoil.api.config.StepBuilder;
import io.hyperfoil.api.session.Access;
import io.hyperfoil.api.session.Session;
import io.hyperfoil.api.config.Step;
import io.hyperfoil.core.builders.BaseStepBuilder;
import io.hyperfoil.core.session.SessionFactory;
public class AwaitDelayStep implements Step {
private final Access key;
public AwaitDelayStep(Object key) {
this.key = SessionFactory.access(key);
}
@Override
public boolean invoke(Session session) {
ScheduleDelayStep.Timestamp blockedUntil = (ScheduleDelayStep.Timestamp) key.getObject(session);
return System.currentTimeMillis() >= blockedUntil.timestamp;
}
/**
* Block this sequence until referenced delay point.
*/
@MetaInfServices(StepBuilder.class)
@Name("awaitDelay")
public static class Builder extends BaseStepBuilder implements InitFromParam {
private Object key;
/**
* @param param Delay point created in scheduleDelay.key
.
* @return Self.
*/
@Override
public Builder init(String param) {
return key(param);
}
/**
* Delay point created in scheduleDelay.key
.
*
* @param key Key.
* @return Self.
*/
public Builder key(String key) {
this.key = key;
return this;
}
@Override
public List build() {
return Collections.singletonList(new AwaitDelayStep(key));
}
}
}