-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
192 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
testng-core/src/main/java/org/testng/internal/thread/Async.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.testng.internal.thread; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutorService; | ||
import org.testng.ITestResult; | ||
import org.testng.internal.invokers.TestMethodWithDataProviderMethodWorker; | ||
|
||
public final class Async { | ||
|
||
private Async() { | ||
// Defeat instantiation | ||
} | ||
|
||
public static CompletableFuture<List<ITestResult>> run( | ||
TestMethodWithDataProviderMethodWorker worker, ExecutorService service) { | ||
AsyncTask asyncTask = new AsyncTask(worker); | ||
service.execute(asyncTask); | ||
return asyncTask.result; | ||
} | ||
|
||
private static class AsyncTask implements Runnable, Comparable<AsyncTask> { | ||
private final CompletableFuture<List<ITestResult>> result = new CompletableFuture<>(); | ||
private final TestMethodWithDataProviderMethodWorker worker; | ||
|
||
public AsyncTask(TestMethodWithDataProviderMethodWorker worker) { | ||
this.worker = worker; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
if (!result.isDone()) { | ||
result.complete(worker.call()); | ||
} | ||
} catch (Throwable t) { | ||
result.completeExceptionally(t); | ||
} | ||
} | ||
|
||
@Override | ||
public int compareTo(AsyncTask o) { | ||
return worker.compareTo(o.worker); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
testng-core/src/test/java/test/dataprovider/issue3081/NoOpMethodInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package test.dataprovider.issue3081; | ||
|
||
import java.util.List; | ||
import org.testng.IMethodInstance; | ||
import org.testng.IMethodInterceptor; | ||
import org.testng.ITestContext; | ||
|
||
public class NoOpMethodInterceptor implements IMethodInterceptor { | ||
@Override | ||
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) { | ||
return methods; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
testng-core/src/test/java/test/dataprovider/issue3081/TestClassSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package test.dataprovider.issue3081; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.Collections; | ||
import java.util.Random; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.IntStream; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
public class TestClassSample { | ||
private static final Set<Long> logs = ConcurrentHashMap.newKeySet(); | ||
private static final Random random = new SecureRandom(); | ||
|
||
public static Set<Long> getLogs() { | ||
return Collections.unmodifiableSet(logs); | ||
} | ||
|
||
public static void clear() { | ||
logs.clear(); | ||
} | ||
|
||
@DataProvider(parallel = true) | ||
public static Object[] parallelDpStrings() { | ||
return IntStream.rangeClosed(0, 99).mapToObj(it -> "string " + it).toArray(String[]::new); | ||
} | ||
|
||
@Test(dataProvider = "parallelDpStrings") | ||
public void testStrings(String ignored) throws InterruptedException { | ||
print(); | ||
TimeUnit.MILLISECONDS.sleep(random.nextInt(500)); | ||
} | ||
|
||
private static void print() { | ||
logs.add(Thread.currentThread().getId()); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
testng-core/src/test/java/test/dataprovider/issue3081/TestClassWithPrioritiesSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package test.dataprovider.issue3081; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.Collections; | ||
import java.util.Random; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.IntStream; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
public class TestClassWithPrioritiesSample { | ||
private static final Set<Long> logs = ConcurrentHashMap.newKeySet(); | ||
private static final Random random = new SecureRandom(); | ||
|
||
public static Set<Long> getLogs() { | ||
return Collections.unmodifiableSet(logs); | ||
} | ||
|
||
public static void clear() { | ||
logs.clear(); | ||
} | ||
|
||
@DataProvider(parallel = true) | ||
public static Object[] parallelDpStrings() { | ||
return IntStream.rangeClosed(0, 99).mapToObj(it -> "string " + it).toArray(String[]::new); | ||
} | ||
|
||
@Test(dataProvider = "parallelDpStrings", priority = 1) | ||
public void testStrings(String ignored) throws InterruptedException { | ||
print(); | ||
TimeUnit.MILLISECONDS.sleep(random.nextInt(500)); | ||
} | ||
|
||
@Test(priority = 2) | ||
public void anotherTest() {} | ||
|
||
private static void print() { | ||
logs.add(Thread.currentThread().getId()); | ||
} | ||
} |