Merge pull request #10420 from kcacademic/BAEL-4759
Corrected the name of unit test to mark them as manual.
This commit is contained in:
commit
9f581af949
|
@ -10,11 +10,17 @@ import org.openjdk.jcstress.annotations.Outcome;
|
||||||
import org.openjdk.jcstress.annotations.State;
|
import org.openjdk.jcstress.annotations.State;
|
||||||
import org.openjdk.jcstress.infra.results.I_Result;
|
import org.openjdk.jcstress.infra.results.I_Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is defined as a manual test because it tries to simulate the race conditions
|
||||||
|
* in a concurrent program that is poorly designed and hence may fail nondeterministically.
|
||||||
|
* This will help the CI jobs to ignore these tests and a developer to run them manually.
|
||||||
|
*
|
||||||
|
*/
|
||||||
@JCStressTest
|
@JCStressTest
|
||||||
@Outcome(id = "1", expect = ACCEPTABLE_INTERESTING, desc = "One update lost.")
|
@Outcome(id = "1", expect = ACCEPTABLE_INTERESTING, desc = "One update lost.")
|
||||||
@Outcome(id = "2", expect = ACCEPTABLE, desc = "Both updates.")
|
@Outcome(id = "2", expect = ACCEPTABLE, desc = "Both updates.")
|
||||||
@State
|
@State
|
||||||
public class MyCounterJCStressUnitTest {
|
public class MyCounterJCStressManualTest {
|
||||||
|
|
||||||
private MyCounter counter;
|
private MyCounter counter;
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
package com.baeldung.concurrent;
|
package com.baeldung.concurrent;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import edu.umd.cs.mtc.MultithreadedTestCase;
|
import edu.umd.cs.mtc.MultithreadedTestCase;
|
||||||
import edu.umd.cs.mtc.TestFramework;
|
import edu.umd.cs.mtc.TestFramework;
|
||||||
|
|
||||||
public class MyCounterMultithreadedTCUnitTest extends MultithreadedTestCase {
|
/**
|
||||||
|
* This is defined as a manual test because it tries to simulate the race conditions
|
||||||
|
* in a concurrent program that is poorly designed and hence may fail nondeterministically.
|
||||||
|
* This will help the CI jobs to ignore these tests and a developer to run them manually.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MyCounterMultithreadedTCManualTest extends MultithreadedTestCase {
|
||||||
|
|
||||||
private MyCounter counter;
|
private MyCounter counter;
|
||||||
|
|
||||||
|
@ -29,9 +34,8 @@ public class MyCounterMultithreadedTCUnitTest extends MultithreadedTestCase {
|
||||||
assertEquals(2, counter.getCount());
|
assertEquals(2, counter.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@Test
|
@Test
|
||||||
public void testCounter() throws Throwable {
|
public void testCounter() throws Throwable {
|
||||||
TestFramework.runManyTimes(new MyCounterMultithreadedTCUnitTest(), 1000);
|
TestFramework.runManyTimes(new MyCounterMultithreadedTCManualTest(), 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.baeldung.concurrent;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is defined as a manual test because it tries to simulate the race conditions
|
||||||
|
* in a concurrent program that is poorly designed and hence may fail nondeterministically.
|
||||||
|
* This will help the CI jobs to ignore these tests and a developer to run them manually.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MyCounterSimpleManualTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCounter() {
|
||||||
|
MyCounter counter = new MyCounter();
|
||||||
|
for (int i = 0; i < 500; i++)
|
||||||
|
counter.increment();
|
||||||
|
assertEquals(500, counter.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCounterWithConcurrency() throws InterruptedException {
|
||||||
|
int numberOfThreads = 100;
|
||||||
|
ExecutorService service = Executors.newFixedThreadPool(10);
|
||||||
|
CountDownLatch latch = new CountDownLatch(numberOfThreads);
|
||||||
|
MyCounter counter = new MyCounter();
|
||||||
|
for (int i = 0; i < numberOfThreads; i++) {
|
||||||
|
service.execute(() -> {
|
||||||
|
counter.increment();
|
||||||
|
latch.countDown();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
latch.await();
|
||||||
|
assertEquals(numberOfThreads, counter.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSummationWithConcurrencyAndWait() throws InterruptedException {
|
||||||
|
int numberOfThreads = 2;
|
||||||
|
ExecutorService service = Executors.newFixedThreadPool(10);
|
||||||
|
CountDownLatch latch = new CountDownLatch(numberOfThreads);
|
||||||
|
MyCounter counter = new MyCounter();
|
||||||
|
for (int i = 0; i < numberOfThreads; i++) {
|
||||||
|
service.submit(() -> {
|
||||||
|
try {
|
||||||
|
counter.incrementWithWait();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
latch.countDown();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
latch.await();
|
||||||
|
assertEquals(numberOfThreads, counter.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,60 +0,0 @@
|
||||||
package com.baeldung.concurrent;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class MyCounterSimpleUnitTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCounter() {
|
|
||||||
MyCounter counter = new MyCounter();
|
|
||||||
for (int i = 0; i < 500; i++)
|
|
||||||
counter.increment();
|
|
||||||
assertEquals(500, counter.getCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@Test
|
|
||||||
public void testCounterWithConcurrency() throws InterruptedException {
|
|
||||||
int numberOfThreads = 100;
|
|
||||||
ExecutorService service = Executors.newFixedThreadPool(10);
|
|
||||||
CountDownLatch latch = new CountDownLatch(numberOfThreads);
|
|
||||||
MyCounter counter = new MyCounter();
|
|
||||||
for (int i = 0; i < numberOfThreads; i++) {
|
|
||||||
service.execute(() -> {
|
|
||||||
counter.increment();
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
latch.await();
|
|
||||||
assertEquals(numberOfThreads, counter.getCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@Test
|
|
||||||
public void testSummationWithConcurrencyAndWait() throws InterruptedException {
|
|
||||||
int numberOfThreads = 2;
|
|
||||||
ExecutorService service = Executors.newFixedThreadPool(10);
|
|
||||||
CountDownLatch latch = new CountDownLatch(numberOfThreads);
|
|
||||||
MyCounter counter = new MyCounter();
|
|
||||||
for (int i = 0; i < numberOfThreads; i++) {
|
|
||||||
service.submit(() -> {
|
|
||||||
try {
|
|
||||||
counter.incrementWithWait();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
latch.await();
|
|
||||||
assertEquals(numberOfThreads, counter.getCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.baeldung.concurrent;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.code.tempusfugit.concurrency.ConcurrentRule;
|
||||||
|
import com.google.code.tempusfugit.concurrency.RepeatingRule;
|
||||||
|
import com.google.code.tempusfugit.concurrency.annotations.Concurrent;
|
||||||
|
import com.google.code.tempusfugit.concurrency.annotations.Repeating;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is defined as a manual test because it tries to simulate the race conditions
|
||||||
|
* in a concurrent program that is poorly designed and hence may fail nondeterministically.
|
||||||
|
* This will help the CI jobs to ignore these tests and a developer to run them manually.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MyCounterTempusFugitManualTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public ConcurrentRule concurrently = new ConcurrentRule();
|
||||||
|
@Rule
|
||||||
|
public RepeatingRule rule = new RepeatingRule();
|
||||||
|
|
||||||
|
private static MyCounter counter = new MyCounter();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Concurrent(count = 2)
|
||||||
|
@Repeating(repetition = 10)
|
||||||
|
public void runsMultipleTimes() {
|
||||||
|
counter.increment();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void annotatedTestRunsMultipleTimes() throws InterruptedException {
|
||||||
|
assertEquals(counter.getCount(), 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,37 +0,0 @@
|
||||||
package com.baeldung.concurrent;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.google.code.tempusfugit.concurrency.ConcurrentRule;
|
|
||||||
import com.google.code.tempusfugit.concurrency.RepeatingRule;
|
|
||||||
import com.google.code.tempusfugit.concurrency.annotations.Concurrent;
|
|
||||||
import com.google.code.tempusfugit.concurrency.annotations.Repeating;
|
|
||||||
|
|
||||||
public class MyCounterTempusFugitUnitTest {
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ConcurrentRule concurrently = new ConcurrentRule();
|
|
||||||
@Rule
|
|
||||||
public RepeatingRule rule = new RepeatingRule();
|
|
||||||
|
|
||||||
private static MyCounter counter = new MyCounter();
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@Test
|
|
||||||
@Concurrent(count = 2)
|
|
||||||
@Repeating(repetition = 10)
|
|
||||||
public void runsMultipleTimes() {
|
|
||||||
counter.increment();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public static void annotatedTestRunsMultipleTimes() throws InterruptedException {
|
|
||||||
assertEquals(counter.getCount(), 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.baeldung.concurrent;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.testing.threadtester.AnnotatedTestRunner;
|
||||||
|
import com.google.testing.threadtester.ThreadedAfter;
|
||||||
|
import com.google.testing.threadtester.ThreadedBefore;
|
||||||
|
import com.google.testing.threadtester.ThreadedMain;
|
||||||
|
import com.google.testing.threadtester.ThreadedSecondary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is defined as a manual test because it tries to simulate the race conditions
|
||||||
|
* in a concurrent program that is poorly designed and hence may fail nondeterministically.
|
||||||
|
* This will help the CI jobs to ignore these tests and a developer to run them manually.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MyCounterThreadWeaverManualTest {
|
||||||
|
|
||||||
|
private MyCounter counter;
|
||||||
|
|
||||||
|
@ThreadedBefore
|
||||||
|
public void before() {
|
||||||
|
counter = new MyCounter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ThreadedMain
|
||||||
|
public void mainThread() {
|
||||||
|
counter.increment();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ThreadedSecondary
|
||||||
|
public void secondThread() {
|
||||||
|
counter.increment();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ThreadedAfter
|
||||||
|
public void after() {
|
||||||
|
assertEquals(2, counter.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCounter() {
|
||||||
|
new AnnotatedTestRunner().runTests(this.getClass(), MyCounter.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,44 +0,0 @@
|
||||||
package com.baeldung.concurrent;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.google.testing.threadtester.AnnotatedTestRunner;
|
|
||||||
import com.google.testing.threadtester.ThreadedAfter;
|
|
||||||
import com.google.testing.threadtester.ThreadedBefore;
|
|
||||||
import com.google.testing.threadtester.ThreadedMain;
|
|
||||||
import com.google.testing.threadtester.ThreadedSecondary;
|
|
||||||
|
|
||||||
public class MyCounterThreadWeaverUnitTest {
|
|
||||||
|
|
||||||
private MyCounter counter;
|
|
||||||
|
|
||||||
@ThreadedBefore
|
|
||||||
public void before() {
|
|
||||||
counter = new MyCounter();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ThreadedMain
|
|
||||||
public void mainThread() {
|
|
||||||
counter.increment();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ThreadedSecondary
|
|
||||||
public void secondThread() {
|
|
||||||
counter.increment();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ThreadedAfter
|
|
||||||
public void after() {
|
|
||||||
assertEquals(2, counter.getCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@Test
|
|
||||||
public void testCounter() {
|
|
||||||
new AnnotatedTestRunner().runTests(this.getClass(), MyCounter.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue