package net.ranides.assira.concurrent;

import net.ranides.assira.junit.ManualTestUtils;
import net.ranides.assira.time.TimeMetric;
import org.junit.Ignore;
import org.junit.Test;

import java.util.TimerTask;

@Ignore("manual")
public class TaskBuilderTest {

    @Test
    public void repeat1() {
        TimeMetric tm = new TimeMetric(true).start();

        new TaskBuilder()
            .repeat(5)
            .interval(500)
            .delay(1000)
            .start(() -> System.out.println("start " + tm.time()))
            .finish(() -> System.out.println("finish " + tm.time()))
            .interval(() -> {
                System.err.println(" - interval " + tm.time());
            })
            .run();

        ManualTestUtils.sleep(6000);
    }

    @Test
    public void repeat2() {
        TimeMetric tm = new TimeMetric(true).start();

        new TaskBuilder()
            .repeat(5)
            .interval(500)
            .delay(1000)
            .interval(() -> {
                System.err.println(" - interval " + tm.time());
            })
            .run();

        ManualTestUtils.sleep(6000);
    }

    @Test
    public void repeat3() {
        TimeMetric tm = new TimeMetric(true).start();

        new TaskBuilder()
            .repeat(5)
            .interval(500)
            .interval(() -> {
                System.err.println(" - interval " + tm.time());
            })
            .run();

        ManualTestUtils.sleep(5000);
    }

    @Test
    public void delay() {
        TimeMetric tm = new TimeMetric(true).start();

        new TaskBuilder()
            .delay(500)
            .start(() -> {
                System.err.println(" - start " + tm.time());
            })
            .finish(() -> {
                System.err.println(" - finish " + tm.time());
            })
            .run();

        ManualTestUtils.sleep(5000);
    }

}