-
Notifications
You must be signed in to change notification settings - Fork 45
Wrappers for concurrency classes #1535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6dfb131
Added wrappers for Thread and ThreadGroup
Damtev bbd6d39
Added a wrapper for CompletableFuture
Damtev 69fac2e
Added preconditionCheck for wrappers for Thread and ThreadGroup
Damtev a2c6751
Added a wrapper for ExecutorService
Damtev 190656c
Fixed wrappers for Thread and ExecutorService
Damtev f99b521
Added a wrapper for CountDownLatch
Damtev afac549
Fixed hierarchy incompability with UtThread and added missed fields
Damtev d48e113
Added tests for other wrappers
Damtev dd38cb5
Added missing quotes
Damtev fe0c3e6
Fixed a substitution static fields with unbounded variables
Damtev e5ac4c4
Added CompletableFuture.supplyAsync mock implementation
Damtev ab27cab
Fixed review issues
Damtev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
23 changes: 23 additions & 0 deletions
23
...t-framework-test/src/test/kotlin/org/utbot/examples/threads/CountDownLatchExamplesTest.kt
This file contains hidden or 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,23 @@ | ||
| package org.utbot.examples.threads | ||
|
|
||
| import org.junit.jupiter.api.Test | ||
| import org.utbot.testcheckers.eq | ||
| import org.utbot.testing.AtLeast | ||
| import org.utbot.testing.UtValueTestCaseChecker | ||
|
|
||
| class CountDownLatchExamplesTest : UtValueTestCaseChecker(testClass = CountDownLatchExamples::class) { | ||
| @Test | ||
| fun testGetAndDown() { | ||
| check( | ||
| CountDownLatchExamples::getAndDown, | ||
| eq(2), | ||
| { countDownLatch, l -> countDownLatch.count == 0L && l == 0L }, | ||
| { countDownLatch, l -> | ||
| val firstCount = countDownLatch.count | ||
|
|
||
| firstCount != 0L && l == firstCount - 1 | ||
| }, | ||
| coverage = AtLeast(83) | ||
| ) | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
...-framework-test/src/test/kotlin/org/utbot/examples/threads/ExecutorServiceExamplesTest.kt
This file contains hidden or 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,40 @@ | ||
| package org.utbot.examples.threads | ||
|
|
||
| import org.junit.jupiter.api.Test | ||
| import org.utbot.testcheckers.withoutConcrete | ||
| import org.utbot.testing.AtLeast | ||
| import org.utbot.testing.UtValueTestCaseChecker | ||
| import org.utbot.testing.ignoreExecutionsNumber | ||
| import org.utbot.testing.isException | ||
|
|
||
| // IMPORTANT: most of the these tests test only the symbolic engine | ||
| // and should not be used for testing conrete or code generation since they are possibly flaky in the concrete execution | ||
| // (see https://github.com/UnitTestBot/UTBotJava/issues/1610) | ||
| class ExecutorServiceExamplesTest : UtValueTestCaseChecker(testClass = ExecutorServiceExamples::class) { | ||
| @Test | ||
| fun testExceptionInExecute() { | ||
| withoutConcrete { | ||
| withEnabledTestingCodeGeneration(false) { | ||
| checkWithException( | ||
| ExecutorServiceExamples::throwingInExecute, | ||
| ignoreExecutionsNumber, | ||
| { r -> r.isException<IllegalStateException>() } | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun testChangingCollectionInExecute() { | ||
| withoutConcrete { | ||
| withEnabledTestingCodeGeneration(false) { | ||
| check( | ||
| ExecutorServiceExamples::changingCollectionInExecute, | ||
| ignoreExecutionsNumber, | ||
| { r -> r == 42 }, | ||
| coverage = AtLeast(78) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } |
60 changes: 60 additions & 0 deletions
60
utbot-framework-test/src/test/kotlin/org/utbot/examples/threads/FutureExamplesTest.kt
This file contains hidden or 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,60 @@ | ||
| package org.utbot.examples.threads | ||
|
|
||
| import org.junit.jupiter.api.Test | ||
| import org.utbot.testcheckers.eq | ||
| import org.utbot.testcheckers.withoutConcrete | ||
| import org.utbot.testing.AtLeast | ||
| import org.utbot.testing.UtValueTestCaseChecker | ||
| import org.utbot.testing.isException | ||
| import java.util.concurrent.ExecutionException | ||
|
|
||
| // IMPORTANT: most of the these tests test only the symbolic engine | ||
| // and should not be used for testing conrete or code generation since they are possibly flaky in the concrete execution | ||
| // (see https://github.com/UnitTestBot/UTBotJava/issues/1610) | ||
| class FutureExamplesTest : UtValueTestCaseChecker(testClass = FutureExamples::class) { | ||
| @Test | ||
| fun testThrowingRunnable() { | ||
| withoutConcrete { | ||
| checkWithException( | ||
| FutureExamples::throwingRunnableExample, | ||
| eq(1), | ||
| { r -> r.isException<ExecutionException>() }, | ||
| coverage = AtLeast(71) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun testResultFromGet() { | ||
| check( | ||
| FutureExamples::resultFromGet, | ||
| eq(1), | ||
| { r -> r == 42 }, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun testChangingCollectionInFuture() { | ||
| withEnabledTestingCodeGeneration(false) { | ||
| check( | ||
| FutureExamples::changingCollectionInFuture, | ||
| eq(1), | ||
| { r -> r == 42 }, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun testChangingCollectionInFutureWithoutGet() { | ||
| withoutConcrete { | ||
| withEnabledTestingCodeGeneration(false) { | ||
| check( | ||
| FutureExamples::changingCollectionInFutureWithoutGet, | ||
| eq(1), | ||
| { r -> r == 42 }, | ||
| coverage = AtLeast(78) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
utbot-framework-test/src/test/kotlin/org/utbot/examples/threads/ThreadExamplesTest.kt
This file contains hidden or 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,54 @@ | ||
| package org.utbot.examples.threads | ||
|
|
||
| import org.junit.jupiter.api.Test | ||
| import org.utbot.testcheckers.withoutConcrete | ||
| import org.utbot.testing.AtLeast | ||
| import org.utbot.testing.UtValueTestCaseChecker | ||
| import org.utbot.testing.ignoreExecutionsNumber | ||
| import org.utbot.testing.isException | ||
|
|
||
| // IMPORTANT: most of the these tests test only the symbolic engine | ||
| // and should not be used for testing conrete or code generation since they are possibly flaky in the concrete execution | ||
| // (see https://github.com/UnitTestBot/UTBotJava/issues/1610) | ||
| class ThreadExamplesTest : UtValueTestCaseChecker(testClass = ThreadExamples::class) { | ||
| @Test | ||
| fun testExceptionInStart() { | ||
| withoutConcrete { | ||
| withEnabledTestingCodeGeneration(false) { | ||
| checkWithException( | ||
| ThreadExamples::explicitExceptionInStart, | ||
| ignoreExecutionsNumber, | ||
| { r -> r.isException<IllegalStateException>() } | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun testChangingCollectionInThread() { | ||
| withoutConcrete { | ||
| withEnabledTestingCodeGeneration(false) { | ||
| check( | ||
| ThreadExamples::changingCollectionInThread, | ||
| ignoreExecutionsNumber, | ||
| { r -> r == 42 }, | ||
| coverage = AtLeast(81) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun testChangingCollectionInThreadWithoutStart() { | ||
| withoutConcrete { | ||
| withEnabledTestingCodeGeneration(false) { | ||
| checkWithException( | ||
| ThreadExamples::changingCollectionInThreadWithoutStart, | ||
| ignoreExecutionsNumber, | ||
| { r -> r.isException<IndexOutOfBoundsException>() }, | ||
| coverage = AtLeast(81) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
30 changes: 30 additions & 0 deletions
30
utbot-framework/src/main/java/org/utbot/engine/overrides/threads/CompletableFuture.java
This file contains hidden or 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,30 @@ | ||
| package org.utbot.engine.overrides.threads; | ||
|
|
||
| import org.utbot.api.annotation.UtClassMock; | ||
|
|
||
| import java.util.concurrent.Executor; | ||
| import java.util.function.Supplier; | ||
|
|
||
| @UtClassMock(target = java.util.concurrent.CompletableFuture.class, internalUsage = true) | ||
| public class CompletableFuture { | ||
| public static java.util.concurrent.CompletableFuture<Void> runAsync(Runnable runnable) { | ||
| java.util.concurrent.CompletableFuture<Void> future = new java.util.concurrent.CompletableFuture<>(); | ||
|
|
||
| return future.thenRun(runnable); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static java.util.concurrent.CompletableFuture<Void> runAsync(Runnable runnable, Executor ignoredExecutor) { | ||
| return runAsync(runnable); | ||
| } | ||
|
|
||
| public static <U> java.util.concurrent.CompletableFuture<U> supplyAsync(Supplier<U> supplier) { | ||
| try { | ||
| final U value = supplier.get(); | ||
|
|
||
| return new UtCompletableFuture<>(value).toCompletableFuture(); | ||
| } catch (Throwable e) { | ||
| return new UtCompletableFuture<U>(e).toCompletableFuture(); | ||
| } | ||
| } | ||
| } | ||
120 changes: 120 additions & 0 deletions
120
utbot-framework/src/main/java/org/utbot/engine/overrides/threads/Executors.java
This file contains hidden or 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,120 @@ | ||
| package org.utbot.engine.overrides.threads; | ||
|
|
||
| import org.utbot.api.annotation.UtClassMock; | ||
| import org.utbot.api.mock.UtMock; | ||
|
|
||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
| import java.util.concurrent.ThreadFactory; | ||
|
|
||
| @UtClassMock(target = java.util.concurrent.Executors.class, internalUsage = true) | ||
| public class Executors { | ||
| public static ExecutorService newFixedThreadPool(int nThreads) { | ||
| if (nThreads <= 0) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
|
|
||
| return new UtExecutorService(); | ||
| } | ||
|
|
||
| public static ExecutorService newWorkStealingPool() { | ||
| return new UtExecutorService(); | ||
| } | ||
|
|
||
| public static ExecutorService newWorkStealingPool(int parallelism) { | ||
| if (parallelism <= 0) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
|
|
||
| return new UtExecutorService(); | ||
| } | ||
|
|
||
| public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory) { | ||
| if (threadFactory == null) { | ||
| throw new NullPointerException(); | ||
| } | ||
|
|
||
| return newFixedThreadPool(nThreads); | ||
| } | ||
|
|
||
| public static ExecutorService newSingleThreadExecutor() { | ||
| return new UtExecutorService(); | ||
| } | ||
|
|
||
| public static ExecutorService newSingleThreadExecutor(ThreadFactory threadFactory) { | ||
| if (threadFactory == null) { | ||
| throw new NullPointerException(); | ||
| } | ||
|
|
||
| return new UtExecutorService(); | ||
| } | ||
|
|
||
| public static ExecutorService newCachedThreadPool() { | ||
| return new UtExecutorService(); | ||
| } | ||
|
|
||
| public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) { | ||
| if (threadFactory == null) { | ||
| throw new NullPointerException(); | ||
| } | ||
|
|
||
| return new UtExecutorService(); | ||
| } | ||
|
|
||
| public static ScheduledExecutorService newSingleThreadScheduledExecutor() { | ||
| return new UtExecutorService(); | ||
| } | ||
|
|
||
| public static ScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory) { | ||
| if (threadFactory == null) { | ||
| throw new NullPointerException(); | ||
| } | ||
|
|
||
| return new UtExecutorService(); | ||
| } | ||
|
|
||
| public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize) { | ||
| if (corePoolSize < 0) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
|
|
||
| return new UtExecutorService(); | ||
| } | ||
|
|
||
| public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize, ThreadFactory threadFactory) { | ||
| if (corePoolSize < 0) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
|
|
||
| if (threadFactory == null) { | ||
| throw new NullPointerException(); | ||
| } | ||
|
|
||
| return new UtExecutorService(); | ||
| } | ||
|
|
||
| public static ExecutorService unconfigurableExecutorService(ExecutorService executor) { | ||
| if (executor == null) { | ||
| throw new NullPointerException(); | ||
| } | ||
|
|
||
| return new UtExecutorService(); | ||
| } | ||
|
|
||
| public static ScheduledExecutorService unconfigurableScheduledExecutorService(ScheduledExecutorService executor) { | ||
| if (executor == null) { | ||
| throw new NullPointerException(); | ||
| } | ||
|
|
||
| return new UtExecutorService(); | ||
| } | ||
|
|
||
| public static ThreadFactory defaultThreadFactory() { | ||
| // TODO make a wrapper? | ||
| return UtMock.makeSymbolic(); | ||
| } | ||
|
|
||
| public static ThreadFactory privilegedThreadFactory() { | ||
| return defaultThreadFactory(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.