Code Monkey home page Code Monkey logo

thread-weaver's Introduction

This is Weaver, a framework for writing multi-threaded Unit Tests in
Java.

Documentation is available in the docs directory, including a Users'
Guide and a Tutorial.

Post questions to [email protected]

REQUIREMENTS:

Weaver was built with Java 6. (http://java.sun.com/javase/6)

It requires the following components:

 Javassist. (http://www.csg.is.titech.ac.jp/~chiba/javassist). Version 3.8.1 or greater.

 Objenesis. (http://code.google.com/p/objenesis). Version 1.0 or greater.

 Cglib. (http://cglib.sourceforge.net). Version 2.2 or greater.

To build the extensions:

 Easymock/Easymock Class Extension. (http://easymock.org). Version 2.4 or greater.

To run the tests:

 Easymock/Easymock Class Extension.

 JUnit (http://www.junit.org). Version 4.5 or greater.

To run the extensions tests:

 ASM (http://asm.ow2.org). Version 3.0 or greater.

BUILDING:

To build Weaver, edit the build.properties file and fill in the
location of the required jars. The ant target "all" will build the
main jar plus the extensions, and run all the tests.

MAVEN:

The MapDB group have been using Thread Weaver, and have produced a 
Mavenised version. For details of this, and for a discussion of the
issues that they have had with the framework, see 
http://www.mapdb.org/blog/thread_weaver.html

thread-weaver's People

Contributors

alasdair-mackintosh avatar caarlos0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

thread-weaver's Issues

Mockito Support

Are there any plans to make this library work with Mockito?

Non-thread counter doesn't fail

A test that should fail but doesn't.

System under test

public class Counter {
    private int count;
    public void increment() { count++; }
    public int getCount() { return count; }
}

Test class

public class CounterTest {
    private Counter sut;
    @Test
    public void testThreading() {
        AnnotatedTestRunner runner = new AnnotatedTestRunner();
        runner.runTests(this.getClass(), Counter.class);
    }

    @ThreadedBefore
    public void before() {
        sut = new Counter();
    }

    @ThreadedMain
    public void main() {
        sut.increment();
    }

    @ThreadedSecondary
    public void secondary() {
        sut.increment();
    }

    @ThreadedAfter
    public void after() {
        assertEquals(sut.getCount(),2);
    }
}

Expected result
Test fails.
Interweaving should allow for the result to be 1 due to race condition at counter++:

ThreadMain reads 0
             ThreadSecondary reads 0
ThreadMain increments to 1
ThreadMain writes 1
             ThreadSecondary increments to 1
             ThreadSecondary writes 1

Final value for counter 1. Expected value being 2, that should make the test fail.

Actual result
Test passes.

Environment

    <dependency>
      <groupId>com.googlecode.thread-weaver</groupId>
      <artifactId>threadweaver</artifactId>
      <version>0.2</version>
    </dependency>

$ java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

$ uname -a
Darwin hostname.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64

Failing tests cause errors instead of failures

I've modified the first example in a simple fashion. I'm hoping maybe you could incorporate these changes into AnnotatedTestRunner.runTests(...):

    @Test
    public void testThreading() {
        final AnnotatedTestRunner runner = new AnnotatedTestRunner();
        // Run all Weaver tests in this class, using MyList as the Class Under Test.
        try {
            runner.runTests(this.getClass(), MyList.class);
        } catch (final RuntimeException e) {
            final Throwable root = org.apache.commons.lang.exception.ExceptionUtils.ExceptionUtils.getRootCause(e);
            if (root instanceof AssertionError)
                throw (AssertionError) root;
            else
                throw e;
        }
    }

Limiting number of interleavings

Hi,
The code in current shape implies sequential consistency (due to locking after each byte code instruction). This way the analysis is fully reliable only when there are no data races - as defined in JMM https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.4.5

There is work outlining a different approach to interleavings using only locations where the happens-before relation is forced (i.e. lockin / unlocking the same monitor, acess to a volatile variable, etc.). See https://www.cs.rice.edu/~javaplt/papers/ricken-phd-thesis.pdf

This optimization in number of interleavings, enclosing whole critical blocks, could be considered in Thread Weaver - it seems that with already assumed sequential consistency there would be no loss of reliability.
Please, let me know if the above seem a fair statement. I would happily try to tackle this.
Marcin

Maven?

The old google code repo has two tags for Maven releases. Are there plans to update/move this project maven?

Android Support

I'm wondering if the library is able to support Android concurrency testing?

Thank you.

Cannot instrument static methods

Hi,

I tried getting information regarding this but could not find any. It seems I cannot instrument static methods to test them with thread weaver.

Here is a basic example of what I try to achieve:

public class DoClass {
    public static void doTheThing() {
        System.out.println("do");
    }
}
public class DoClassTest {
    @ThreadedBefore
    public void before() {}

    @ThreadedMain
    public void mainThread() {
        DoClass.doTheThing();
    }

    @ThreadedSecondary
    public void secondThread() {
        DoClass.doTheThing();
    }

    @ThreadedAfter
    public void after() {}

    @Test
    public void runThreadedTests() {
        new AnnotatedTestRunner().runTests(DoClassTest.class, DoClass.class);
    }
}

All I end up with is this nasty exception:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:71)
    at com.google.testing.threadtester.BaseThreadedTestRunner.runTests(BaseThreadedTestRunner.java:179)
    at com.google.testing.threadtester.BaseThreadedTestRunner.runTests(BaseThreadedTestRunner.java:143)
    at DoClassTest.runThreadedTests(DoClassTest.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:68)
    ... 13 more
Caused by: java.lang.IllegalArgumentException: Cannot find method public static void DoClass.doTheThing()
    at com.google.testing.threadtester.ClassInstrumentationImpl.getMethod(ClassInstrumentationImpl.java:113)
    at com.google.testing.threadtester.InterleavedRunner.getMainMethod(InterleavedRunner.java:116)
    at com.google.testing.threadtester.InterleavedRunner.doInterleave(InterleavedRunner.java:131)
    at com.google.testing.threadtester.InterleavedRunner.interleave(InterleavedRunner.java:80)
    at com.google.testing.threadtester.AnnotatedTestWrapper.runTestCases(AnnotatedTestWrapper.java:258)
    at com.google.testing.threadtester.AnnotatedTestWrapper.runTests(AnnotatedTestWrapper.java:242)
    ... 16 more

Is this a known issue ? Am I doing something wrong ?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.