Basic concurrency tests for tags

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-04-26 14:36:42 +02:00
parent 6a7497f436
commit c8ae194f7d
3 changed files with 80 additions and 1 deletions

View File

@ -6,4 +6,8 @@ plugins {
dependencies {
jcstressImplementation(rootProject)
jcstress(libs.jcstress.core)
}
}
jcstress {
verbose = "true"
}

View File

@ -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;
}
}
}

View File

@ -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);
}
}