From d43243620dcba353c718670664d68a18d75f50e1 Mon Sep 17 00:00:00 2001 From: Vadim Faber Date: Mon, 4 Feb 2019 20:21:21 +0300 Subject: [PATCH 1/3] Added an example of running a parameterized linearization test --- .../queue/ConcurrentLinkedQueueTest.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/ConcurrentLinkedQueueTest.java diff --git a/libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/ConcurrentLinkedQueueTest.java b/libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/ConcurrentLinkedQueueTest.java new file mode 100644 index 0000000..44b06d9 --- /dev/null +++ b/libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/ConcurrentLinkedQueueTest.java @@ -0,0 +1,82 @@ +package leti._3303.faber; + +import com.devexperts.dxlab.lincheck.LinChecker; +import com.devexperts.dxlab.lincheck.annotations.Operation; +import com.devexperts.dxlab.lincheck.annotations.Param; +import com.devexperts.dxlab.lincheck.paramgen.IntGen; +import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Random; +import java.util.concurrent.ConcurrentLinkedQueue; + +@RunWith(Parameterized.class) +public class ConcurrentLinkedQueueTest { + private static ArrayList initialValues; + + + public ConcurrentLinkedQueueTest(ArrayList aL, String desc) { + ConcurrentLinkedQueueTest.initialValues = aL; + } + + private static ArrayList generateAL(int bound){ + Random random = new Random(); + ArrayList newAL = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + newAL.add(random.nextInt(bound)); + } + return newAL; + } + + + @Parameterized.Parameters(name = "{1}") + public static Collection testConditions() { + Object[][] data = new Object[][]{ + {generateAL(10), "tens"}, + {generateAL(100), "hundreds"}, + {generateAL(1000), "thousands"} + }; + return Arrays.asList(data); + + } + + @StressCTest(threads = 3) + @Param(name = "newValue", gen = IntGen.class, conf = "1:10") + public static class ConcurrentLinkedQueueLinTest { + private ConcurrentLinkedQueue cLQ = new ConcurrentLinkedQueue<>(initialValues);; + + + @Operation + public void offer(@Param(name = "newValue") int newItem) { + cLQ.offer(newItem); + } + + @Operation + public Integer poll() { + return cLQ.poll(); + } + + @Operation + public Integer peek() { + return cLQ.peek(); + } + + @Operation + public boolean isEmpty() { + return cLQ.isEmpty(); + } + + } + + @Test + public void runner() throws Exception { + LinChecker.check(ConcurrentLinkedQueueLinTest.class); + } + +} From 21d4bf8c49d42514bd6f96ddf0027ad9267a8679 Mon Sep 17 00:00:00 2001 From: faber-v <32452658+faber-v@users.noreply.github.com> Date: Mon, 4 Feb 2019 20:40:24 +0300 Subject: [PATCH 2/3] Changed package --- .../lincheck/tests/custom/queue/ConcurrentLinkedQueueTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/ConcurrentLinkedQueueTest.java b/libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/ConcurrentLinkedQueueTest.java index 44b06d9..4f5dca1 100644 --- a/libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/ConcurrentLinkedQueueTest.java +++ b/libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/ConcurrentLinkedQueueTest.java @@ -1,4 +1,4 @@ -package leti._3303.faber; +com.devexperts.dxlab.lincheck.tests.custom.queue; import com.devexperts.dxlab.lincheck.LinChecker; import com.devexperts.dxlab.lincheck.annotations.Operation; From 7500b76949173eab6b0301ecc539a10fcdd6c1cf Mon Sep 17 00:00:00 2001 From: faber-v <32452658+faber-v@users.noreply.github.com> Date: Mon, 4 Feb 2019 20:41:44 +0300 Subject: [PATCH 3/3] Changed package #2 --- .../lincheck/tests/custom/queue/ConcurrentLinkedQueueTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/ConcurrentLinkedQueueTest.java b/libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/ConcurrentLinkedQueueTest.java index 4f5dca1..fe36a1d 100644 --- a/libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/ConcurrentLinkedQueueTest.java +++ b/libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/ConcurrentLinkedQueueTest.java @@ -1,4 +1,4 @@ -com.devexperts.dxlab.lincheck.tests.custom.queue; +package com.devexperts.dxlab.lincheck.tests.custom.queue; import com.devexperts.dxlab.lincheck.LinChecker; import com.devexperts.dxlab.lincheck.annotations.Operation;