10000 GitHub - vmlens/vmlens: VMLens lets you test multi-threaded, concurrent Java
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

vmlens/vmlens

Repository files navigation

VMLens lets you test multi-threaded, concurrent Java

Example

The following example shows how to test multi-threaded, concurrent Java with vmlens:

import com.vmlens.api.AllInterleavings;
public class TestNonVolatileField {
    private int j = 0;
    @Test
    public void testUpdate() throws InterruptedException {
        try(AllInterleavings allInterleavings = new AllInterleavings("testNonVolatileField")) {
            while (allInterleavings.hasNext()) {
                Thread first = new Thread() {
                    @Override
                    public void run() {
                        j++;
                    }
                };
                first.start();
                j++;
                first.join();
            }
        }
    }
}

VMLens detects the data race and generates the following report:

See test-vmlens-maven-plugin for more examples.

Installation

Maven

To use vmlens with Maven, configure a plugin tag to tell Maven that the vmlens plugin should be executed at the test phase. And include the jar com.vmlens.api as test dependency.

<project>
<!-- to include the class AllInterleavings into the test class path.  -->	
<dependency>
  <groupId>com.vmlens</groupId>
  <artifactId>api</artifactId>
  <version>1.2.6</version>
  <scope>test</scope>
</dependency>	
	
<build>
  <plugins>
<!-- to run the vmlens maven plugin during the maven test phase  -->	 
    <plugin>
        <groupId>com.vmlens</groupId>
        <artifactId>vmlens-maven-plugin</artifactId>
	<version>1.2.6</version>
        <executions>
            <execution>
                <id>test</id>
                <goals>
                    <goal>test</goal>
                </goals>
            </execution>
        </executions>
	</plugin>
     ...
    </plugins>
</build>
      ...
</project>

See pom.xml for an example.

Standalone

To use VMLens as a standalone tool:

  1. Include com.vmlens.api from the Maven Repository as a test jar in your project.
  2. Download the jar standalone-1.2.6.jar from the Maven Repository
  3. Run java -jar standalone-1.2.6.jar install. This creates the agent directory and prints the vm parameter to System.out
  4. Add this vm parameter when you run your test
  5. Run java -jar standalone-1.2.6.jar report. This checks for data races and creates the report

Documentation

Read the documentation here.

Questions? Problems? Suggestions?

Contact me at thomas.krieger@vmlens.com

License

Apache License 2.0

About

VMLens lets you test multi-threaded, concurrent Java

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages

0