Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Make JUnit tests run in parallel (#2652)

Koen4ac234438f21
diff --git a/build.gradle b/build.gradle
index 50fd2a4e3..8743cf664 100644
--- a/build.gradle
+++ b/build.gradle
@@ -101,6 +101,10 @@ subprojects {
outputs.upToDateWhen { false }
useJUnitPlatform()
+ systemProperty "junit.jupiter.execution.parallel.enabled", "true"
+ systemProperty "junit.jupiter.execution.parallel.mode.default", "concurrent"
+ systemProperty "junit.jupiter.execution.parallel.mode.classes.default", "concurrent"
+
testLogging {
// set options for log level LIFECYCLE
diff --git a/container/src/test/java/org/openremote/container/timer/PseudoClockTest.java b/container/src/test/java/org/openremote/container/timer/PseudoClockTest.java
index 4ea0d1422..c50d2cd75 100644
--- a/container/src/test/java/org/openremote/container/timer/PseudoClockTest.java
+++ b/container/src/test/java/org/openremote/container/timer/PseudoClockTest.java
@@ -2,6 +2,8 @@ package org.openremote.container.timer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
import java.time.LocalDate;
import java.time.LocalTime;
@@ -9,6 +11,7 @@ import java.time.ZoneId;
import static org.junit.jupiter.api.Assertions.assertEquals;
+@Execution(ExecutionMode.SAME_THREAD)
public class PseudoClockTest {
private TimerService.Clock clock;
diff --git a/model/src/main/java/org/openremote/model/util/JSONSchemaUtil.java b/model/src/main/java/org/openremote/model/util/JSONSchemaUtil.java
index f15904174..b3bb496b6 100644
--- a/model/src/main/java/org/openremote/model/util/JSONSchemaUtil.java
+++ b/model/src/main/java/org/openremote/model/util/JSONSchemaUtil.java
@@ -519,12 +519,12 @@ public class JSONSchemaUtil {
}
private static class JSONSchemaTitleProvider implements CustomDefinitionProviderV2, TypeAttributeOverrideV2 {
- private ResolvedType rootType;
+ private final ThreadLocal<ResolvedType> rootType = new ThreadLocal<>();
@Override
public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, SchemaGenerationContext context) {
- if (this.rootType == null) {
- this.rootType = javaType;
+ if (this.rootType.get() == null) {
+ this.rootType.set(javaType);
}
return null;
}
@@ -539,7 +539,7 @@ public class JSONSchemaUtil {
*/
@Override
public void overrideTypeAttributes(ObjectNode attrs, TypeScope scope, SchemaGenerationContext context) {
- if ((this.rootType == scope.getType() && !attrs.has(context.getKeyword(SchemaKeyword.TAG_TITLE))) ||
+ if ((this.rootType.get() == scope.getType() && !attrs.has(context.getKeyword(SchemaKeyword.TAG_TITLE))) ||
(!attrs.has(context.getKeyword(SchemaKeyword.TAG_TITLE))
&& !scope.getType().isInstanceOf(Map.class)
&& attrs.has(context.getKeyword(SchemaKeyword.TAG_TYPE))
@@ -561,7 +561,7 @@ public class JSONSchemaUtil {
@Override
public void resetAfterSchemaGenerationFinished() {
- this.rootType = null;
+ this.rootType.remove();
}
}
diff --git a/model/src/test/java/org/openremote/model/util/JSONSchemaUtilTest.java b/model/src/test/java/org/openremote/model/util/JSONSchemaUtilTest.java
index c0c3e1ea2..494f68192 100644
--- a/model/src/test/java/org/openremote/model/util/JSONSchemaUtilTest.java
+++ b/model/src/test/java/org/openremote/model/util/JSONSchemaUtilTest.java
@@ -4,8 +4,11 @@ import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import org.json.JSONException;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
@@ -22,8 +25,8 @@ import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
public class JSONSchemaUtilTest {
- @BeforeEach
- void setup() {
+ @BeforeAll
+ static void setup() {
ValueUtil.doInitialise();
}