001/**
002 * Powerunit - A JDK1.8 test framework
003 * Copyright (C) 2014 Mathieu Boretti.
004 *
005 * This file is part of Powerunit
006 *
007 * Powerunit is free software: you can redistribute it and/or modify
008 * it under the terms of the GNU General Public License as published by
009 * the Free Software Foundation, either version 3 of the License, or
010 * (at your option) any later version.
011 *
012 * Powerunit is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015 * GNU General Public License for more details.
016 *
017 * You should have received a copy of the GNU General Public License
018 * along with Powerunit. If not, see <http://www.gnu.org/licenses/>.
019 */
020package ch.powerunit.extensions.async.lang;
021
022import java.util.concurrent.CompletableFuture;
023
024/**
025 * Third Step of the builder of {@link CompletableFuture} to specify the maximal
026 * number of retry.
027 * 
028 * @param <T>
029 *            The type of result of the {@link CompletableFuture}
030 *
031 */
032public interface WaitResultBuilder3<T> {
033
034        /**
035         * Specify a retry clause.
036         * <p>
037         * The goal is here to define somewhere in the test a constant with this clause
038         * and reuse it in the test.
039         * 
040         * @param retry
041         *            the retry clause.
042         * @return {@link WaitResultBuilder5 the final step of the builder}
043         * @since 1.0.0
044         * @see RetryPolicies
045         */
046        WaitResultBuilder5<T> repeat(RetryPolicy retry);
047
048        /**
049         * Specify the maximal number of retry.
050         * 
051         * @param count
052         *            the number of retry
053         * @return {@link WaitResultBuilder4 the next step of the builder}
054         */
055        default WaitResultBuilder4<T> repeat(int count) {
056                return value -> repeat(RetryPolicies.of(count, value));
057        }
058
059        /**
060         * Specify that only one retry will be done (so only one execution and one
061         * validation).
062         * 
063         * @return {@link WaitResultBuilder5 the final step of the builder}
064         */
065        default WaitResultBuilder5<T> repeatOnlyOnce() {
066                return repeat(RetryPolicies.RETRY_ONLY_ONCE);
067        }
068
069        /**
070         * Specify that only two retry will be done.
071         * 
072         * @return {@link WaitResultBuilder4 the next step of the builder}
073         * @since 1.0.0
074         */
075        default WaitResultBuilder4<T> repeatTwice() {
076                return repeat(2);
077        }
078}