1 package test.thread; 2 3 import org.testng.annotations.BeforeClass; 4 import org.testng.annotations.DataProvider; 5 import org.testng.annotations.Test; 6 7 public class DataProviderThreadPoolSizeSampleTest extends BaseThreadTest { 8 @BeforeClass(alwaysRun = true) 9 public void setUp() { 10 log(getClass().getName(), "Init log ids"); 11 initThreadLog(); 12 } 13 14 @DataProvider(parallel = true) 15 public Object[][] parallelDataProvider() { 16 return createArray(); 17 } 18 19 @DataProvider 20 public Object[][] sequentialDataProvider() { 21 return createArray(); 22 } 23 24 private Object[][] createArray() { 25 int i = 0; 26 return new Object[][] { 27 new Object[] { i++ }, 28 new Object[] { i++ }, 29 new Object[] { i++ }, 30 new Object[] { i++ }, 31 new Object[] { i++ }, 32 new Object[] { i++ }, 33 new Object[] { i++ }, 34 new Object[] { i++ }, 35 new Object[] { i++ }, 36 new Object[] { i++ }, 37 new Object[] { i++ }, 38 new Object[] { i++ }, 39 new Object[] { i++ }, 40 new Object[] { i++ }, 41 new Object[] { i++ }, 42 new Object[] { i++ }, 43 new Object[] { i++ }, 44 new Object[] { i++ }, 45 new Object[] { i++ }, 46 new Object[] { i++ }, 47 }; 48 } 49 50 @Test(dataProvider = "sequentialDataProvider", groups = "sequential") 51 public void fSequential(Integer p) { 52 long n = Thread.currentThread().getId(); 53 log(getClass().getName(), "Sequential"); 54 logThread(n); 55 } 56 57 @Test(dataProvider = "parallelDataProvider", groups = "parallel") 58 public void fParallel(Integer p) { 59 long n = Thread.currentThread().getId(); 60 log(getClass().getName(), "Parallel"); 61 logThread(n); 62 } 63 64 // @Test(dependsOnMethods = {"f1"}) 65 // public void verify() { 66 // int expected = 3; 67 // Assert.assertEquals(m_threadIds.size(), expected, 68 // "Should have run on " + expected + " threads but ran on " + m_threadIds.size()); 69 // } 70 } 71