javajcstress

Running first JCStress test


I'm new to JCStress and I'm trying to run the "hello world" for JCStress but facing some problems. I think there is some obvious thing that I'm missing.

I'm following this link to learn. And the samples that I'm trying are here.

I started with the template project created from the following public maven archetype:

mvn archetype:generate "-DinteractiveMode=false" "-DarchetypeGroupId=org.openjdk.jcstress" "-DarchetypeArtifactId=jcstress-java-test-archetype" "-DarchetypeVersion=0.4" "-DgroupId=org.sample" "-DartifactId=test" "-Dversion=1.0"

I did a mvn clean install and got the .\target\jcstress.jar. I added MyConcurrencyTest which has the following code in package org.sample


package org.sample;

import org.openjdk.jcstress.annotations.*;
import org.openjdk.jcstress.infra.results.I_Result;


@JCStressTest
@Outcome(id = "1", expect = Expect.ACCEPTABLE_INTERESTING, desc = "One update lost: atomicity failure.")
@Outcome(id = "2", expect = Expect.ACCEPTABLE, desc = "Actors updated independently.")
@State
public class MyConcurrencyTest {

    int v;

    @Actor
    public void actor1() {
        v++;
    }

    @Actor
    public void actor2() {
        v++;
    }

    @Arbiter
    public void arbiter(I_Result r) {
        r.r1 = v;
    }

}

The following is my project structure:

Project Structure

Now I'm trying to run this using this command (my current directory is the project root directory when I execute this command)


java -cp ".\target\classes" -jar .\target\jcstress.jar -v -t org.sample.MyConcurrencyTest

But the org.sample.MyConcurrencyTest don't get executed.

(I understand that if we don't specify the tests using -t <testname> the tests from jcstress.jar/META-INF/TestList are picked up.) I think I'm missing something very obvious. Can someone please help?

(It will be great if someone could share a good starter tutorial on JCStress explaining it's capabilities and functionalities that it has)


Solution

  • Ah, I figured out what I was missing.

    We need to do a mvn clean install to get MyConcurrencyTest into the META-INF/TestList file.

    Now I can run

    java -jar .\target\jcstress.jar -v -t org.sample.MyConcurrencyTest
    

    and my test get executed. If I want to execute all the tests, I need to do

    java -jar .\target\jcstress.jar -v
    

    That's it. Bingo!!

    I was just missing mvn clean install, I thought compiling the classes from Intellij and putting them on classpath will work. But it's not the case. You need to tell the JCStress framework what tests you need to execute, and for that you need to compulsorily do a mvn clean install.