forked from junit-team/junit5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce adding 'resource locks' programmatically.
Issue: junit-team#2677
- Loading branch information
1 parent
539df08
commit 745f989
Showing
7 changed files
with
178 additions
and
7 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
junit-jupiter-api/src/main/java/org/junit/jupiter/api/parallel/ResourceLocksFrom.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,31 @@ | ||
/* | ||
* Copyright 2015-2024 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.STABLE; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
@API(status = STABLE, since = "5.10") | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@Inherited | ||
public @interface ResourceLocksFrom { | ||
|
||
Class<? extends ResourceLocksProvider>[] value(); | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
junit-jupiter-api/src/main/java/org/junit/jupiter/api/parallel/ResourceLocksProvider.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,85 @@ | ||
/* | ||
* Copyright 2015-2024 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 java.util.Collections.emptySet; | ||
import static org.apiguardian.api.API.Status.STABLE; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import org.apiguardian.api.API; | ||
import org.junit.platform.commons.util.Preconditions; | ||
import org.junit.platform.commons.util.ToStringBuilder; | ||
|
||
@API(status = STABLE, since = "5.10") | ||
public interface ResourceLocksProvider { | ||
default Set<Lock> provideForClass(Class<?> testClass) { | ||
return emptySet(); | ||
} | ||
|
||
default Set<Lock> provideForNestedClass(Class<?> testClass) { | ||
return emptySet(); | ||
} | ||
|
||
default Set<Lock> provideForMethod(Class<?> testClass, Method testMethod) { | ||
return emptySet(); | ||
} | ||
|
||
final class Lock { | ||
|
||
private final String key; | ||
|
||
private final ResourceAccessMode accessMode; | ||
|
||
public Lock(String key) { | ||
this(key, ResourceAccessMode.READ_WRITE); | ||
} | ||
|
||
public Lock(String key, ResourceAccessMode accessMode) { | ||
this.key = Preconditions.notBlank(key, "key must not be blank"); | ||
this.accessMode = Preconditions.notNull(accessMode, "accessMode must not be null"); | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public ResourceAccessMode getAccessMode() { | ||
return accessMode; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
Lock lock = (Lock) o; | ||
return Objects.equals(key, lock.key) && accessMode == lock.accessMode; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(key, accessMode); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) // | ||
.append("key", key) // | ||
.append("accessMode", accessMode) // | ||
.toString(); | ||
} | ||
} | ||
|
||
} |
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
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