<commit_before>/*
 * Copyright 2017 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.retrier;


import org.junit.Test;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import static io.retrier.Retriers.*;
import static io.retrier.Retry.*;

public class TestDefaultRetrier {

    @Test
    public void testRetrier() throws Exception {
        Retrier retrier = create(withRetryCount(3),
                withTimeout(Duration.of(5, ChronoUnit.SECONDS)),
                withExpBackoff(Duration.of(4, ChronoUnit.SECONDS), Duration.of(2, ChronoUnit.SECONDS)),
                withTrace(System.out::println));

        retrier.retry(on(Exception.class), () -> {
            System.out.println("Hello");
            throw new IllegalArgumentException("123");
        });
    }
}<commit_msg>Asserting in TestDefaultRetrier.<commit_after>/*
 * Copyright 2017 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.retrier;


import org.junit.Test;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.concurrent.atomic.AtomicInteger;

import static io.retrier.Retriers.*;
import static io.retrier.Retry.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

public class TestDefaultRetrier {

    @Test
    public void testRetrier() throws Exception {
        Retrier retrier = create(withRetryCount(3),
                withTimeout(Duration.of(5, ChronoUnit.SECONDS)),
                withExpBackoff(Duration.of(4, ChronoUnit.SECONDS), Duration.of(3, ChronoUnit.SECONDS)),
                withTrace(System.out::println));

        AtomicInteger count = new AtomicInteger(0);

        try {
            retrier.retry(on(Exception.class), () -> {
                count.incrementAndGet();
                System.out.println("Hello");
                throw new IllegalArgumentException("123");
            });
            fail("Should have got IllegalArgumentException.");
        } catch (Exception e) {
            assertThat(e.getClass(), is(equalTo(IllegalArgumentException.class)));
            assertThat(e.getMessage(), is("123"));
        }

        assertThat(count.get(), is(2));
    }
}
{'fraction_non_alphanumeric': 0.10417928528164748, 'fraction_numerical': 0.010599636583888553, 'mean_word_length': 3.1082089552238807, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7551194', 'n_tokens_mistral': 917, 'n_tokens_neox': 885, 'n_words': 275}