Skip to content

Commit

Permalink
Revert "Add 'locks from provider' cases to 'NodeTreeWalkerIntegration…
Browse files Browse the repository at this point in the history
…Tests'."

This reverts commit ff3c786.

Issue: junit-team#2677
  • Loading branch information
VladimirDmitrienko committed Aug 12, 2024
1 parent 7d894c5 commit 1f8a6d0
Showing 1 changed file with 28 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,15 @@
import static org.junit.platform.engine.support.hierarchical.Node.ExecutionMode.SAME_THREAD;
import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;

import java.lang.reflect.Method;
import java.util.List;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.function.Function;
import java.util.stream.Stream;

import org.junit.jupiter.api.Named;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceAccessMode;
import org.junit.jupiter.api.parallel.ResourceLock;
import org.junit.jupiter.api.parallel.ResourceLocksFrom;
import org.junit.jupiter.api.parallel.ResourceLocksProvider;
import org.junit.jupiter.engine.JupiterTestEngine;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.UniqueId;

Expand All @@ -48,19 +40,9 @@ class NodeTreeWalkerIntegrationTests {
LockManager lockManager = new LockManager();
NodeTreeWalker nodeTreeWalker = new NodeTreeWalker(lockManager);

static Stream<?> pullUpExclusiveChildResourcesToTestClassCases() {
// @formatter:off
return Stream.of(
Named.of("locks from annotation", TestCaseWithResourceLockFromAnnotation.class),
Named.of("locks from provider", TestCaseWithResourceLockFromProvider.class)
);
// @formatter:on
}

@ParameterizedTest
@MethodSource("pullUpExclusiveChildResourcesToTestClassCases")
void pullUpExclusiveChildResourcesToTestClass(Class<?> testCase) {
var engineDescriptor = discover(testCase);
@Test
void pullUpExclusiveChildResourcesToTestClass() {
var engineDescriptor = discover(TestCaseWithResourceLock.class);

var advisor = nodeTreeWalker.walk(engineDescriptor);

Expand All @@ -74,19 +56,9 @@ void pullUpExclusiveChildResourcesToTestClass(Class<?> testCase) {
assertThat(advisor.getForcedExecutionMode(testMethodDescriptor)).contains(SAME_THREAD);
}

static Stream<?> setsForceExecutionModeForChildrenWithWriteLocksOnClassCases() {
// @formatter:off
return Stream.of(
Named.of("locks from annotation", TestCaseWithResourceWriteLockOnClassFromAnnotation.class),
Named.of("locks from provider", TestCaseWithResourceWriteLockOnClassFromProvider.class)
);
// @formatter:on
}

@ParameterizedTest
@MethodSource("setsForceExecutionModeForChildrenWithWriteLocksOnClassCases")
void setsForceExecutionModeForChildrenWithWriteLocksOnClass(Class<?> testCase) {
var engineDescriptor = discover(testCase);
@Test
void setsForceExecutionModeForChildrenWithWriteLocksOnClass() {
var engineDescriptor = discover(TestCaseWithResourceWriteLockOnClass.class);

var advisor = nodeTreeWalker.walk(engineDescriptor);

Expand All @@ -100,19 +72,9 @@ void setsForceExecutionModeForChildrenWithWriteLocksOnClass(Class<?> testCase) {
assertThat(advisor.getForcedExecutionMode(testMethodDescriptor)).contains(SAME_THREAD);
}

static Stream<?> doesntSetForceExecutionModeForChildrenWithReadLocksOnClassCases() {
// @formatter:off
return Stream.of(
Named.of("locks from annotation", TestCaseWithResourceReadLockOnClassFromAnnotation.class),
Named.of("locks from provider", TestCaseWithResourceReadLockOnClassFromProvider.class)
);
// @formatter:on
}

@ParameterizedTest
@MethodSource("doesntSetForceExecutionModeForChildrenWithReadLocksOnClassCases")
void doesntSetForceExecutionModeForChildrenWithReadLocksOnClass(Class<?> testCase) {
var engineDescriptor = discover(testCase);
@Test
void doesntSetForceExecutionModeForChildrenWithReadLocksOnClass() {
var engineDescriptor = discover(TestCaseWithResourceReadLockOnClass.class);

var advisor = nodeTreeWalker.walk(engineDescriptor);

Expand All @@ -126,23 +88,9 @@ void doesntSetForceExecutionModeForChildrenWithReadLocksOnClass(Class<?> testCas
assertThat(advisor.getForcedExecutionMode(testMethodDescriptor)).isEmpty();
}

static Stream<?> setsForceExecutionModeForChildrenWithReadLocksOnClassAndWriteLockOnTestCases() {
// @formatter:off
return Stream.of(
Named.of("locks from annotation",
TestCaseWithResourceReadLockOnClassAndWriteClockOnTestCaseFromAnnotation.class
),
Named.of("locks from provider",
TestCaseWithResourceReadLockOnClassAndWriteClockOnTestCaseFromProvider.class
)
);
// @formatter:on
}

@ParameterizedTest
@MethodSource("setsForceExecutionModeForChildrenWithReadLocksOnClassAndWriteLockOnTestCases")
void setsForceExecutionModeForChildrenWithReadLocksOnClassAndWriteLockOnTest(Class<?> testCase) {
var engineDescriptor = discover(testCase);
@Test
void setsForceExecutionModeForChildrenWithReadLocksOnClassAndWriteLockOnTest() {
var engineDescriptor = discover(TestCaseWithResourceReadLockOnClassAndWriteClockOnTestCase.class);

var advisor = nodeTreeWalker.walk(engineDescriptor);

Expand All @@ -156,23 +104,9 @@ void setsForceExecutionModeForChildrenWithReadLocksOnClassAndWriteLockOnTest(Cla
assertThat(advisor.getForcedExecutionMode(testMethodDescriptor)).contains(SAME_THREAD);
}

static Stream<?> doesntSetForceExecutionModeForChildrenWithReadLocksOnClassAndReadLockOnTestCases() {
// @formatter:off
return Stream.of(
Named.of("locks from annotation",
TestCaseWithResourceReadLockOnClassAndReadClockOnTestCaseFromAnnotation.class
),
Named.of("locks from provider",
TestCaseWithResourceReadLockOnClassAndReadClockOnTestCaseFromProvider.class
)
);
// @formatter:on
}

@ParameterizedTest
@MethodSource("doesntSetForceExecutionModeForChildrenWithReadLocksOnClassAndReadLockOnTestCases")
void doesntSetForceExecutionModeForChildrenWithReadLocksOnClassAndReadLockOnTest(Class<?> testCase) {
var engineDescriptor = discover(testCase);
@Test
void doesntSetForceExecutionModeForChildrenWithReadLocksOnClassAndReadLockOnTest() {
var engineDescriptor = discover(TestCaseWithResourceReadLockOnClassAndReadClockOnTestCase.class);

var advisor = nodeTreeWalker.walk(engineDescriptor);

Expand All @@ -186,19 +120,9 @@ void doesntSetForceExecutionModeForChildrenWithReadLocksOnClassAndReadLockOnTest
assertThat(advisor.getForcedExecutionMode(testMethodDescriptor)).isEmpty();
}

static Stream<?> leavesResourceLockOnTestMethodWhenClassDoesNotUseResourceCases() {
// @formatter:off
return Stream.of(
Named.of("locks from annotation", TestCaseWithoutResourceLockFromAnnotation.class),
Named.of("locks from provider", TestCaseWithoutResourceLockFromProvider.class)
);
// @formatter:on
}

@ParameterizedTest
@MethodSource("leavesResourceLockOnTestMethodWhenClassDoesNotUseResourceCases")
void leavesResourceLockOnTestMethodWhenClassDoesNotUseResource(Class<?> testCase) {
var engineDescriptor = discover(testCase);
@Test
void leavesResourceLockOnTestMethodWhenClassDoesNotUseResource() {
var engineDescriptor = discover(TestCaseWithoutResourceLock.class);

var advisor = nodeTreeWalker.walk(engineDescriptor);

Expand All @@ -224,19 +148,9 @@ void leavesResourceLockOnTestMethodWhenClassDoesNotUseResource(Class<?> testCase
assertThat(advisor.getForcedExecutionMode(nestedTestMethodDescriptor)).contains(SAME_THREAD);
}

static Stream<?> coarsensGlobalLockToEngineDescriptorChildCases() {
// @formatter:off
return Stream.of(
Named.of("locks from annotation", TestCaseWithGlobalLockRequiringChildFromAnnotation.class),
Named.of("locks from provider", TestCaseWithGlobalLockRequiringChildFromProvider.class)
);
// @formatter:on
}

@ParameterizedTest
@MethodSource("coarsensGlobalLockToEngineDescriptorChildCases")
void coarsensGlobalLockToEngineDescriptorChild(Class<?> testCase) {
var engineDescriptor = discover(testCase);
@Test
void coarsensGlobalLockToEngineDescriptorChild() {
var engineDescriptor = discover(TestCaseWithGlobalLockRequiringChild.class);

var advisor = nodeTreeWalker.walk(engineDescriptor);

Expand Down Expand Up @@ -278,33 +192,14 @@ private TestDescriptor discover(Class<?> testClass) {
}

@ResourceLock("a")
static class TestCaseWithResourceLockFromAnnotation {
static class TestCaseWithResourceLock {
@Test
@ResourceLock("b")
void test() {
}
}

@ResourceLocksFrom(TestCaseWithResourceLockFromProvider.Provider.class)
static class TestCaseWithResourceLockFromProvider {
@Test
void test() {
}

static final class Provider implements ResourceLocksProvider {
@Override
public Set<Lock> provideForClass(Class<?> testClass) {
return Set.of(new Lock("a"));
}

@Override
public Set<Lock> provideForMethod(Class<?> testClass, Method testMethod) {
return Set.of(new Lock("b"));
}
}
}

static class TestCaseWithoutResourceLockFromAnnotation {
static class TestCaseWithoutResourceLock {
@Test
@ResourceLock("a")
void test() {
Expand All @@ -320,41 +215,7 @@ void test() {
}
}

@ResourceLocksFrom(TestCaseWithoutResourceLockFromProvider.Provider.class)
static class TestCaseWithoutResourceLockFromProvider {
@Test
void test() {
}

@Nested
@ResourceLocksFrom(TestCaseWithoutResourceLockFromProvider.Provider.class)
class NestedTestCaseWithResourceLock {
@Test
void test() {
}
}

static final class Provider implements ResourceLocksProvider {

@Override
public Set<Lock> provideForNestedClass(Class<?> testClass) {
return Set.of(new Lock("c"));
}

@Override
public Set<Lock> provideForMethod(Class<?> testClass, Method testMethod) {
if (testClass == TestCaseWithoutResourceLockFromProvider.class) {
return Set.of(new Lock("a"));
}
else if (testClass == TestCaseWithoutResourceLockFromProvider.NestedTestCaseWithResourceLock.class) {
return Set.of(new Lock("b"));
}
return Set.of();
}
}
}

static class TestCaseWithGlobalLockRequiringChildFromAnnotation {
static class TestCaseWithGlobalLockRequiringChild {
@Nested
class NestedTestCaseWithResourceLock {
@Test
Expand All @@ -364,117 +225,33 @@ void test() {
}
}

static class TestCaseWithGlobalLockRequiringChildFromProvider {
@Nested
@ResourceLocksFrom(TestCaseWithGlobalLockRequiringChildFromProvider.Provider.class)
class NestedTestCaseWithResourceLock {
@Test
void test() {
}
}

static final class Provider implements ResourceLocksProvider {
@Override
public Set<Lock> provideForMethod(Class<?> testClass, Method testMethod) {
return Set.of(new Lock(ExclusiveResource.GLOBAL_KEY));
}
}
}

@ResourceLock("a")
static class TestCaseWithResourceWriteLockOnClassFromAnnotation {
static class TestCaseWithResourceWriteLockOnClass {
@Test
void test() {
}
}

@ResourceLocksFrom(TestCaseWithResourceWriteLockOnClassFromProvider.Provider.class)
static class TestCaseWithResourceWriteLockOnClassFromProvider {
@Test
void test() {
}

static final class Provider implements ResourceLocksProvider {
@Override
public Set<Lock> provideForClass(Class<?> testClass) {
return Set.of(new Lock("a"));
}
}
}

@ResourceLock(value = "a", mode = ResourceAccessMode.READ)
static class TestCaseWithResourceReadLockOnClassFromAnnotation {
static class TestCaseWithResourceReadLockOnClass {
@Test
void test() {
}
}

@ResourceLocksFrom(TestCaseWithResourceReadLockOnClassFromProvider.Provider.class)
static class TestCaseWithResourceReadLockOnClassFromProvider {
@Test
void test() {
}

static final class Provider implements ResourceLocksProvider {
@Override
public Set<Lock> provideForClass(Class<?> testClass) {
return Set.of(new Lock("a", ResourceAccessMode.READ));
}
}
}

@ResourceLock(value = "a", mode = ResourceAccessMode.READ)
static class TestCaseWithResourceReadLockOnClassAndWriteClockOnTestCaseFromAnnotation {
static class TestCaseWithResourceReadLockOnClassAndWriteClockOnTestCase {
@Test
@ResourceLock("a")
void test() {
}
}

@ResourceLocksFrom(TestCaseWithResourceReadLockOnClassAndWriteClockOnTestCaseFromProvider.Provider.class)
static class TestCaseWithResourceReadLockOnClassAndWriteClockOnTestCaseFromProvider {
@Test
void test() {
}

static final class Provider implements ResourceLocksProvider {
@Override
public Set<Lock> provideForClass(Class<?> testClass) {
return Set.of(new Lock("a", ResourceAccessMode.READ));
}

@Override
public Set<Lock> provideForMethod(Class<?> testClass, Method testMethod) {
return Set.of(new Lock("a"));
}
}
}

@ResourceLock(value = "a", mode = ResourceAccessMode.READ)
static class TestCaseWithResourceReadLockOnClassAndReadClockOnTestCaseFromAnnotation {
static class TestCaseWithResourceReadLockOnClassAndReadClockOnTestCase {
@Test
@ResourceLock(value = "b", mode = ResourceAccessMode.READ)
void test() {
}
}

@ResourceLocksFrom(TestCaseWithResourceReadLockOnClassAndReadClockOnTestCaseFromProvider.Provider.class)
static class TestCaseWithResourceReadLockOnClassAndReadClockOnTestCaseFromProvider {
@Test
void test() {
}

static final class Provider implements ResourceLocksProvider {
@Override
public Set<Lock> provideForClass(Class<?> testClass) {
return Set.of(new Lock("a", ResourceAccessMode.READ));
}

@Override
public Set<Lock> provideForMethod(Class<?> testClass, Method testMethod) {
return Set.of(new Lock("b", ResourceAccessMode.READ));
}
}
}

}

0 comments on commit 1f8a6d0

Please sign in to comment.