-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Introduced @ResourceLock(target = SELF | CHILDREN)
#3220
Closed
anatolyD
wants to merge
7
commits into
junit-team:main
from
anatolyD:3102_target_mode_for_resource_locks
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
43605a2
Introduced `@ResourceLock(target = SELF | CHILDREN)`
anatolyD e6801ff
Updated Demo Class
anatolyD b559ee5
Only two threads for read only are mandatory
anatolyD a23cae2
Merge branch 'main' into 3102_target_mode_for_resource_locks
anatolyD 95b323a
Leaving platform ignorant about new ResourceLock api
anatolyD 9fe9dca
style changes
anatolyD baccd68
parent will take care if its parent
anatolyD 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 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
70 changes: 70 additions & 0 deletions
70
documentation/src/test/java/example/SharedResourcesChildrenTargetDemo.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,70 @@ | ||
/* | ||
* Copyright 2015-2023 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package example; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT; | ||
import static org.junit.jupiter.api.parallel.ResourceAccessMode.READ; | ||
import static org.junit.jupiter.api.parallel.ResourceAccessMode.READ_WRITE; | ||
import static org.junit.jupiter.api.parallel.Resources.SYSTEM_PROPERTIES; | ||
import static org.junit.jupiter.api.parallel.Resources.TIME_ZONE; | ||
|
||
import java.util.Properties; | ||
import java.util.TimeZone; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
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.ResourceLock; | ||
import org.junit.jupiter.api.parallel.ResourceLockTarget; | ||
|
||
// tag::user_guide[] | ||
@Execution(CONCURRENT) | ||
@ResourceLock(value = TIME_ZONE, mode = READ, target = ResourceLockTarget.CHILDREN) | ||
class SharedResourcesChildrenTargetDemo { | ||
|
||
private Properties backup; | ||
|
||
@BeforeEach | ||
void backup() { | ||
backup = new Properties(); | ||
backup.putAll(System.getProperties()); | ||
} | ||
|
||
@AfterEach | ||
void restore() { | ||
System.setProperties(backup); | ||
} | ||
|
||
@Test | ||
@ResourceLock(value = SYSTEM_PROPERTIES, mode = READ) | ||
void usePropertiesAndTimeZoneWithoutModification() { | ||
assertNull(System.getProperty("my.prop")); | ||
} | ||
|
||
@Test | ||
@ResourceLock(value = SYSTEM_PROPERTIES, mode = READ) | ||
void usePropertiesAndTimeZoneWithoutModificationAgain() { | ||
assertNull(System.getProperty("my.prop")); | ||
} | ||
|
||
@Test | ||
@ResourceLock(value = SYSTEM_PROPERTIES, mode = READ_WRITE) | ||
void canSetCustomPropertyToTimeZone() { | ||
String timezone = TimeZone.getDefault().getDisplayName(); | ||
System.setProperty("my.timezone", timezone); | ||
assertEquals(timezone, System.getProperty("my.timezone")); | ||
} | ||
|
||
} | ||
// end::user_guide[] |
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
36 changes: 36 additions & 0 deletions
36
junit-jupiter-api/src/main/java/org/junit/jupiter/api/parallel/ResourceLockTarget.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,36 @@ | ||
/* | ||
* Copyright 2015-2023 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.api.parallel; | ||
|
||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* Indicates the target of a {@link ResourceLock}. | ||
* | ||
* @since 5.10 | ||
* @see ResourceLock | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.10") | ||
public enum ResourceLockTarget { | ||
|
||
/** | ||
* Point to the test descriptor itself | ||
*/ | ||
SELF, | ||
|
||
/** | ||
* Skip the test descriptor itself and apply annotation {@link ResourceLock} to its direct children | ||
*/ | ||
CHILDREN | ||
|
||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if a class has a
@ResourceLock
annotation with targetCHILDREN
and a method has one for the same resource? Does the one from the method override the one from the class? This should be documented here.