
com.anarsoft.vmlens.concurrent.example.WrongAtomicityStack Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of concurrent-junit Show documentation
Show all versions of concurrent-junit Show documentation
A http://junit.org test runner to run concurrent unit tests.
package com.anarsoft.vmlens.concurrent.example;
import java.util.Stack;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.anarsoft.vmlens.concurrent.junit.ConcurrentTestRunner;
/**
*
* Shows how to use org.junit.Before annotation to create the pre-conditions of a concurrent tests. {@link #addOne} will be only called once, {@link #removeOne} 4 times in parallel.
* When you run this test with vmlens.com with "delay synchronization for unit tests" enabled, {@link #removeOne} will
* throw a java.util.EmptyStackException.
*
*
*
* @author Thomas
*
*/
@RunWith(ConcurrentTestRunner.class)
public class WrongAtomicityStack {
private final Stack stack = new Stack();
@Before
public void addOne() throws Exception
{
stack.push("abcd");
}
@Test
public void removeOne() throws Exception
{
if( ! stack.isEmpty() )
{
stack.pop();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy