All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.anarsoft.vmlens.concurrent.example.RaceConditionVolatileCounter Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package com.anarsoft.vmlens.concurrent.example;

import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.anarsoft.vmlens.concurrent.junit.ConcurrentTestRunner;



/**
 * 
 * Shows how to use org.junit.After annotation to check for the result of a computation. 
 * The assertion will fail when run with vmlens.com with
 * "delay synchronization for unit tests" enabled.
 * 
 * 
 * 
 * @author Thomas
 *
 */

@RunWith(ConcurrentTestRunner.class)
public class RaceConditionVolatileCounter {
	
	
	private volatile int i = 0;
	
	@Test
	public void addOne()
	{
		i++;
	}
	
	@After
	public void assertCount()
	{
		assertEquals("4 Threads running addOne in parallel should lead to 4" , 4 , i);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy