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

net.openhft.chronicle.testframework.internal.VanillaFlakyTestRunnerBuilder Maven / Gradle / Ivy

There is a newer version: 2.27ea0
Show newest version
package net.openhft.chronicle.testframework.internal;

import net.openhft.chronicle.testframework.FlakyTestRunner;
import org.jetbrains.annotations.NotNull;

import java.util.function.Consumer;

import static java.util.Objects.requireNonNull;

public final class VanillaFlakyTestRunnerBuilder implements FlakyTestRunner.Builder {

    final FlakyTestRunner.RunnableThrows action;
    boolean flakyOnThisArchitecture = true;
    int maxIterations = 1;
    long delayMs = 500;
    boolean interIterationGc = true;
    Consumer infoLogger = System.out::println;
    Consumer errorLogger = System.err::println;
    private boolean built = false;

    public VanillaFlakyTestRunnerBuilder(@NotNull final FlakyTestRunner.RunnableThrows action) {
        this.action = requireNonNull(action);
    }

    @Override
    public FlakyTestRunner.Builder withFlakyOnThisArchitecture(boolean flakyOnThisArchitecture) {
        this.flakyOnThisArchitecture = flakyOnThisArchitecture;
        return this;
    }

    @Override
    public FlakyTestRunner.Builder withMaxIterations(int maxIterations) {
        if (maxIterations < 0)
            throw new IllegalArgumentException("maxIterations is negative: " + maxIterations);
        this.maxIterations = maxIterations;
        return this;
    }

    @Override
    public FlakyTestRunner.Builder withIterationDelay(long delayMs) {
        if (delayMs < 0)
            throw new IllegalArgumentException("delayMs is negative: " + delayMs);
        this.delayMs = delayMs;
        return this;
    }

    @Override
    public FlakyTestRunner.Builder withInterIterationGc(boolean interIterationGc) {
        this.interIterationGc = interIterationGc;
        return this;
    }

    @Override
    public FlakyTestRunner.Builder withInfoLogger(Consumer infoLogger) {
        this.infoLogger = requireNonNull(infoLogger);
        return this;
    }

    @Override
    public FlakyTestRunner.Builder withErrorLogger(Consumer errorLogger) {
        this.errorLogger = requireNonNull(errorLogger);
        return this;
    }

    @Override
    public FlakyTestRunner.RunnableThrows build() {
        if (built)
            throw new IllegalStateException("Builder already used");
        built = true;
        return new VanillaFlakyTestRunner<>(this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy