mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-29 20:48:08 +01:00
Basic concurrency tests for tags
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
6a7497f436
commit
c8ae194f7d
@ -7,3 +7,7 @@ dependencies {
|
|||||||
jcstressImplementation(rootProject)
|
jcstressImplementation(rootProject)
|
||||||
jcstress(libs.jcstress.core)
|
jcstress(libs.jcstress.core)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jcstress {
|
||||||
|
verbose = "true"
|
||||||
|
}
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package net.minestom.server.tag;
|
||||||
|
|
||||||
|
import org.jglrxavpok.hephaistos.nbt.NBT;
|
||||||
|
import org.openjdk.jcstress.annotations.*;
|
||||||
|
import org.openjdk.jcstress.infra.results.L_Result;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.openjdk.jcstress.annotations.Expect.ACCEPTABLE;
|
||||||
|
|
||||||
|
@JCStressTest
|
||||||
|
@Outcome(id = "tag", expect = ACCEPTABLE)
|
||||||
|
@Outcome(id = "tag_path", expect = ACCEPTABLE)
|
||||||
|
@State
|
||||||
|
public class TagPathTest {
|
||||||
|
private static final Tag<Integer> TAG = Tag.Integer("path");
|
||||||
|
private static final Tag<Integer> TAG_PATH = Tag.Integer("key").path("path");
|
||||||
|
|
||||||
|
private final TagHandler handler = TagHandler.newHandler();
|
||||||
|
|
||||||
|
@Actor
|
||||||
|
public void actor1() {
|
||||||
|
handler.setTag(TAG, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Actor
|
||||||
|
public void actor2() {
|
||||||
|
handler.setTag(TAG_PATH, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Arbiter
|
||||||
|
public void arbiter(L_Result r) {
|
||||||
|
var compound = handler.asCompound();
|
||||||
|
if (compound.equals(NBT.Compound(Map.of("path", NBT.Int(1))))) {
|
||||||
|
r.r1 = "tag";
|
||||||
|
} else if (compound.equals(NBT.Compound(Map.of("path", NBT.Compound(Map.of("key", NBT.Int(5))))))) {
|
||||||
|
r.r1 = "tag_path";
|
||||||
|
} else {
|
||||||
|
r.r1 = compound;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package net.minestom.server.tag;
|
||||||
|
|
||||||
|
import org.openjdk.jcstress.annotations.*;
|
||||||
|
import org.openjdk.jcstress.infra.results.L_Result;
|
||||||
|
|
||||||
|
import static org.openjdk.jcstress.annotations.Expect.ACCEPTABLE;
|
||||||
|
import static org.openjdk.jcstress.annotations.Expect.FORBIDDEN;
|
||||||
|
|
||||||
|
@JCStressTest
|
||||||
|
@Outcome(id = "1", expect = ACCEPTABLE)
|
||||||
|
@Outcome(id = "5", expect = ACCEPTABLE)
|
||||||
|
@Outcome(id = "null", expect = FORBIDDEN, desc = "Tag is not seen")
|
||||||
|
@State
|
||||||
|
public class TagTest {
|
||||||
|
private static final Tag<Integer> TAG = Tag.Integer("key");
|
||||||
|
|
||||||
|
private final TagHandler handler = TagHandler.newHandler();
|
||||||
|
|
||||||
|
@Actor
|
||||||
|
public void actor1() {
|
||||||
|
handler.setTag(TAG, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Actor
|
||||||
|
public void actor2() {
|
||||||
|
handler.setTag(TAG, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Arbiter
|
||||||
|
public void arbiter(L_Result r) {
|
||||||
|
r.r1 = handler.getTag(TAG);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user