Skip to content

Commit 1172872

Browse files
authored
Wrappers for concurrency classes (#1535)
1 parent fc87c58 commit 1172872

File tree

29 files changed

+2291
-16
lines changed

29 files changed

+2291
-16
lines changed

.github/workflows/framework-tests-matrix.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
{
2424
"PART_NAME": "examples-part2",
25-
"TESTS_TO_RUN": "--tests \"org.utbot.examples.exceptions.*\" --tests \"org.utbot.examples.invokes.*\" --tests \"org.utbot.examples.lambda.*\" --tests \"org.utbot.examples.make.symbolic.*\" --tests \"org.utbot.examples.math.*\" --tests \"org.utbot.examples.mixed.*\" --tests \"org.utbot.examples.mock.*\" --tests \"org.utbot.examples.models.*\" --tests \"org.utbot.examples.natives.*\" --tests \"org.utbot.examples.objects.*\" --tests \"org.utbot.examples.reflection.*\""
25+
"TESTS_TO_RUN": "--tests \"org.utbot.examples.exceptions.*\" --tests \"org.utbot.examples.invokes.*\" --tests \"org.utbot.examples.lambda.*\" --tests \"org.utbot.examples.make.symbolic.*\" --tests \"org.utbot.examples.math.*\" --tests \"org.utbot.examples.mixed.*\" --tests \"org.utbot.examples.mock.*\" --tests \"org.utbot.examples.models.*\" --tests \"org.utbot.examples.natives.*\" --tests \"org.utbot.examples.objects.*\" --tests \"org.utbot.examples.reflection.*\" --tests \"org.utbot.examples.threads.*\""
2626
},
2727
{
2828
"PART_NAME": "examples-part3",

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/visible/UtStreamConsumingException.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package org.utbot.framework.plugin.api.visible
33
/**
44
* An artificial exception that stores an exception that would be thrown in case of consuming stream by invoking terminal operations.
55
* [innerException] stores this possible exception (null if [UtStreamConsumingException] was constructed by the engine).
6+
*
7+
* NOTE: this class should be visible in almost all parts of the tool - Soot, engine, concrete execution and code generation,
8+
* that's the reason why this class is placed in this module and this package is called `visible`.
69
*/
710
data class UtStreamConsumingException(private val innerException: Exception?) : RuntimeException() {
811
/**

utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/NotNullAnnotationTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.utbot.examples.annotations
33
import org.junit.jupiter.api.Disabled
44
import org.junit.jupiter.api.Test
55
import org.utbot.testcheckers.eq
6+
import org.utbot.testing.AtLeast
67
import org.utbot.testing.UtValueTestCaseChecker
78

89
internal class NotNullAnnotationTest : UtValueTestCaseChecker(testClass = NotNullAnnotation::class) {
@@ -68,7 +69,8 @@ internal class NotNullAnnotationTest : UtValueTestCaseChecker(testClass = NotNul
6869
checkStatics(
6970
NotNullAnnotation::notNullStaticField,
7071
eq(1),
71-
{ statics, result -> result == statics.values.single().value }
72+
{ statics, result -> result == statics.values.single().value },
73+
coverage = AtLeast(66)
7274
)
7375
}
7476

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.utbot.examples.threads
2+
3+
import org.junit.jupiter.api.Test
4+
import org.utbot.testcheckers.eq
5+
import org.utbot.testing.AtLeast
6+
import org.utbot.testing.UtValueTestCaseChecker
7+
8+
class CountDownLatchExamplesTest : UtValueTestCaseChecker(testClass = CountDownLatchExamples::class) {
9+
@Test
10+
fun testGetAndDown() {
11+
check(
12+
CountDownLatchExamples::getAndDown,
13+
eq(2),
14+
{ countDownLatch, l -> countDownLatch.count == 0L && l == 0L },
15+
{ countDownLatch, l ->
16+
val firstCount = countDownLatch.count
17+
18+
firstCount != 0L && l == firstCount - 1
19+
},
20+
coverage = AtLeast(83)
21+
)
22+
}
23+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.utbot.examples.threads
2+
3+
import org.junit.jupiter.api.Test
4+
import org.utbot.testcheckers.withoutConcrete
5+
import org.utbot.testing.AtLeast
6+
import org.utbot.testing.UtValueTestCaseChecker
7+
import org.utbot.testing.ignoreExecutionsNumber
8+
import org.utbot.testing.isException
9+
10+
// IMPORTANT: most of the these tests test only the symbolic engine
11+
// and should not be used for testing conrete or code generation since they are possibly flaky in the concrete execution
12+
// (see https://github.com/UnitTestBot/UTBotJava/issues/1610)
13+
class ExecutorServiceExamplesTest : UtValueTestCaseChecker(testClass = ExecutorServiceExamples::class) {
14+
@Test
15+
fun testExceptionInExecute() {
16+
withoutConcrete {
17+
withEnabledTestingCodeGeneration(false) {
18+
checkWithException(
19+
ExecutorServiceExamples::throwingInExecute,
20+
ignoreExecutionsNumber,
21+
{ r -> r.isException<IllegalStateException>() }
22+
)
23+
}
24+
}
25+
}
26+
27+
@Test
28+
fun testChangingCollectionInExecute() {
29+
withoutConcrete {
30+
withEnabledTestingCodeGeneration(false) {
31+
check(
32+
ExecutorServiceExamples::changingCollectionInExecute,
33+
ignoreExecutionsNumber,
34+
{ r -> r == 42 },
35+
coverage = AtLeast(78)
36+
)
37+
}
38+
}
39+
}
40+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.utbot.examples.threads
2+
3+
import org.junit.jupiter.api.Test
4+
import org.utbot.testcheckers.eq
5+
import org.utbot.testcheckers.withoutConcrete
6+
import org.utbot.testing.AtLeast
7+
import org.utbot.testing.UtValueTestCaseChecker
8+
import org.utbot.testing.isException
9+
import java.util.concurrent.ExecutionException
10+
11+
// IMPORTANT: most of the these tests test only the symbolic engine
12+
// and should not be used for testing conrete or code generation since they are possibly flaky in the concrete execution
13+
// (see https://github.com/UnitTestBot/UTBotJava/issues/1610)
14+
class FutureExamplesTest : UtValueTestCaseChecker(testClass = FutureExamples::class) {
15+
@Test
16+
fun testThrowingRunnable() {
17+
withoutConcrete {
18+
checkWithException(
19+
FutureExamples::throwingRunnableExample,
20+
eq(1),
21+
{ r -> r.isException<ExecutionException>() },
22+
coverage = AtLeast(71)
23+
)
24+
}
25+
}
26+
27+
@Test
28+
fun testResultFromGet() {
29+
check(
30+
FutureExamples::resultFromGet,
31+
eq(1),
32+
{ r -> r == 42 },
33+
)
34+
}
35+
36+
@Test
37+
fun testChangingCollectionInFuture() {
38+
withEnabledTestingCodeGeneration(false) {
39+
check(
40+
FutureExamples::changingCollectionInFuture,
41+
eq(1),
42+
{ r -> r == 42 },
43+
)
44+
}
45+
}
46+
47+
@Test
48+
fun testChangingCollectionInFutureWithoutGet() {
49+
withoutConcrete {
50+
withEnabledTestingCodeGeneration(false) {
51+
check(
52+
FutureExamples::changingCollectionInFutureWithoutGet,
53+
eq(1),
54+
{ r -> r == 42 },
55+
coverage = AtLeast(78)
56+
)
57+
}
58+
}
59+
}
60+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.utbot.examples.threads
2+
3+
import org.junit.jupiter.api.Test
4+
import org.utbot.testcheckers.withoutConcrete
5+
import org.utbot.testing.AtLeast
6+
import org.utbot.testing.UtValueTestCaseChecker
7+
import org.utbot.testing.ignoreExecutionsNumber
8+
import org.utbot.testing.isException
9+
10+
// IMPORTANT: most of the these tests test only the symbolic engine
11+
// and should not be used for testing conrete or code generation since they are possibly flaky in the concrete execution
12+
// (see https://github.com/UnitTestBot/UTBotJava/issues/1610)
13+
class ThreadExamplesTest : UtValueTestCaseChecker(testClass = ThreadExamples::class) {
14+
@Test
15+
fun testExceptionInStart() {
16+
withoutConcrete {
17+
withEnabledTestingCodeGeneration(false) {
18+
checkWithException(
19+
ThreadExamples::explicitExceptionInStart,
20+
ignoreExecutionsNumber,
21+
{ r -> r.isException<IllegalStateException>() }
22+
)
23+
}
24+
}
25+
}
26+
27+
@Test
28+
fun testChangingCollectionInThread() {
29+
withoutConcrete {
30+
withEnabledTestingCodeGeneration(false) {
31+
check(
32+
ThreadExamples::changingCollectionInThread,
33+
ignoreExecutionsNumber,
34+
{ r -> r == 42 },
35+
coverage = AtLeast(81)
36+
)
37+
}
38+
}
39+
}
40+
41+
@Test
42+
fun testChangingCollectionInThreadWithoutStart() {
43+
withoutConcrete {
44+
withEnabledTestingCodeGeneration(false) {
45+
checkWithException(
46+
ThreadExamples::changingCollectionInThreadWithoutStart,
47+
ignoreExecutionsNumber,
48+
{ r -> r.isException<IndexOutOfBoundsException>() },
49+
coverage = AtLeast(81)
50+
)
51+
}
52+
}
53+
}
54+
}

utbot-framework/src/main/java/org/utbot/engine/overrides/security/UtSecurityManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.utbot.engine.overrides.security;
22

3+
import org.utbot.api.mock.UtMock;
4+
35
import java.security.Permission;
46

57
/**
@@ -13,4 +15,8 @@ public void checkPermission(Permission perm) {
1315
public void checkPackageAccess(String pkg) {
1416
// Do nothing to allow everything
1517
}
18+
19+
public ThreadGroup getThreadGroup() {
20+
return new ThreadGroup(UtMock.makeSymbolic());
21+
}
1622
}

utbot-framework/src/main/java/org/utbot/engine/overrides/strings/UtString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import static org.utbot.engine.overrides.UtOverrideMock.visit;
1414
import static java.lang.Math.min;
1515

16-
@SuppressWarnings({"ConstantConditions", "unused"})
16+
@SuppressWarnings("unused")
1717
public class UtString implements java.io.Serializable, Comparable<String>, CharSequence {
1818
char[] value;
1919
int length;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.utbot.engine.overrides.threads;
2+
3+
import org.utbot.api.annotation.UtClassMock;
4+
5+
import java.util.concurrent.Executor;
6+
import java.util.function.Supplier;
7+
8+
@UtClassMock(target = java.util.concurrent.CompletableFuture.class, internalUsage = true)
9+
public class CompletableFuture {
10+
public static java.util.concurrent.CompletableFuture<Void> runAsync(Runnable runnable) {
11+
java.util.concurrent.CompletableFuture<Void> future = new java.util.concurrent.CompletableFuture<>();
12+
13+
return future.thenRun(runnable);
14+
}
15+
16+
@SuppressWarnings("unused")
17+
public static java.util.concurrent.CompletableFuture<Void> runAsync(Runnable runnable, Executor ignoredExecutor) {
18+
return runAsync(runnable);
19+
}
20+
21+
public static <U> java.util.concurrent.CompletableFuture<U> supplyAsync(Supplier<U> supplier) {
22+
try {
23+
final U value = supplier.get();
24+
25+
return new UtCompletableFuture<>(value).toCompletableFuture();
26+
} catch (Throwable e) {
27+
return new UtCompletableFuture<U>(e).toCompletableFuture();
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)