-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Milestone
Description
See matchbox for eventually matcher.
Account account = resultOfSampling(new Sampler<Account>(){
@Override
public Account takeSample() {
return repository.findBy(id);
}
@Override
public boolean isComplete(Account account) {
return account != null;
}
});
assertThat(account.getBalance(), is(300));
public static <T> T resultOfSampling(Sampler<T> sampler) {
return resultOfSampling(sampler, new Duration(200), standardSeconds(30));
}
public static <T> T resultOfSampling(Sampler<T> sampler, Duration sampleInterval, Duration sampleDuration) {
long startTime = System.currentTimeMillis();
long endTime = startTime + sampleDuration.getMillis();
T result;
while(System.currentTimeMillis() < endTime) {
result = sampler.takeSample();
if (sampler.isComplete(result)) {
break;
}
try {
Thread.sleep(sampleInterval.getMillis())
} catch (InterruptedException exception) {
throw new RuntimeException(exception);
}
}
return result;
}
public interface Sampler<T> {
T takeSample();
boolean isComplete(T sample);
}Metadata
Metadata
Assignees
Labels
No labels