package com.example;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class DataProviderParallelTest {

    @DataProvider(name = "dp", parallel = true)
    public Object[][] provideData() {
        return new Object[][]{
                {"D1"}, {"D2"}, {"D3"}, {"D4"}, {"D5"}, {"D6"}, {"D7"}, {"D8"}
        };
    }

    @Test(dataProvider = "dp")
    public void testMethod1(String data) throws InterruptedException {
        long threadId = Thread.currentThread().getId();
        System.out.println("Start test " + data + " in thread " + threadId);
        Thread.sleep(5000);
        System.out.println("End test " + data + " in thread " + threadId);
    }

    @Test(dataProvider = "dp")
    public void testMethod2(String data) throws InterruptedException {
        long threadId = Thread.currentThread().getId();
        System.out.println("Start test " + data + " in thread " + threadId);
        Thread.sleep(5000);
        System.out.println("End test " + data + " in thread " + threadId);
    }

    @Test(dataProvider = "dp")
    public void testMethod3(String data) throws InterruptedException {
        long threadId = Thread.currentThread().getId();
        System.out.println("Start test " + data + " in thread " + threadId);
        Thread.sleep(5000);
        System.out.println("End test " + data + " in thread " + threadId);
    }

    @Test(dataProvider = "dp")
    public void testMethod4(String data) throws InterruptedException {
        long threadId = Thread.currentThread().getId();
        System.out.println("Start test " + data + " in thread " + threadId);
        Thread.sleep(5000);
        System.out.println("End test " + data + " in thread " + threadId);
    }

    @Test(dataProvider = "dp")
    public void testMethod5(String data) throws InterruptedException {
        long threadId = Thread.currentThread().getId();
        System.out.println("Start test " + data + " in thread " + threadId);
        Thread.sleep(5000);
        System.out.println("End test " + data + " in thread " + threadId);
    }
}