From 4c04a8c8e1aedbca02b3ba8fd484c26e8b6e2413 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Thu, 29 Jul 2021 19:55:46 +0200 Subject: Data structure cleanup with Sonar --- .../data/map/tests/smoke/CommitSmokeTest.java | 95 +++++++++++ .../data/map/tests/smoke/DiffCursorSmokeTest.java | 103 ++++++++++++ .../smoke/MutableImmutableCompareSmokeTest.java | 88 +++++++++++ .../data/map/tests/smoke/MutableSmokeTest.java | 77 +++++++++ .../data/map/tests/smoke/RestoreSmokeTest.java | 108 +++++++++++++ .../data/map/tests/smoke/fast/CommitSmokeTest.java | 79 ---------- .../map/tests/smoke/fast/DiffCursorSmokeTest.java | 101 ------------ .../fast/MutableImmutableCompareSmokeTest.java | 72 --------- .../map/tests/smoke/fast/MutableSmokeTest.java | 76 --------- .../map/tests/smoke/fast/RestoreSmokeTest.java | 92 ----------- .../data/map/tests/smoke/slow/SlowSmokeTest.java | 77 --------- .../data/map/tests/smoke/utils/SmokeTestUtils.java | 63 ++++++++ .../map/tests/smoke/utils/SmoteTestUtilsTest.java | 33 ++++ .../data/map/tests/smoke/utils/TestPermuter.java | 46 ------ .../map/tests/smoke/utils/TestPermuterTest.java | 33 ---- .../data/map/tests/support/MapTestEnvironment.java | 174 --------------------- .../data/map/tests/utils/MapTestEnvironment.java | 174 +++++++++++++++++++++ 17 files changed, 741 insertions(+), 750 deletions(-) create mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/CommitSmokeTest.java create mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/DiffCursorSmokeTest.java create mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/MutableImmutableCompareSmokeTest.java create mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/MutableSmokeTest.java create mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/RestoreSmokeTest.java delete mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/CommitSmokeTest.java delete mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/DiffCursorSmokeTest.java delete mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/MutableImmutableCompareSmokeTest.java delete mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/MutableSmokeTest.java delete mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/RestoreSmokeTest.java delete mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/slow/SlowSmokeTest.java create mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/SmokeTestUtils.java create mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/SmoteTestUtilsTest.java delete mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuter.java delete mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuterTest.java delete mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/support/MapTestEnvironment.java create mode 100644 model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/utils/MapTestEnvironment.java (limited to 'model-data/src/test/java/org/eclipse/viatra/solver') diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/CommitSmokeTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/CommitSmokeTest.java new file mode 100644 index 00000000..25ad81d2 --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/CommitSmokeTest.java @@ -0,0 +1,95 @@ +package org.eclipse.viatra.solver.data.map.tests.smoke; + +import static org.junit.jupiter.api.Assertions.fail; + +import java.util.Random; +import java.util.stream.Stream; + +import org.eclipse.viatra.solver.data.map.ContinousHashProvider; +import org.eclipse.viatra.solver.data.map.VersionedMapStore; +import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; +import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; +import org.eclipse.viatra.solver.data.map.tests.smoke.utils.SmokeTestUtils; +import org.eclipse.viatra.solver.data.map.tests.utils.MapTestEnvironment; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class CommitSmokeTest { + private void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, int commitFrequency, + boolean evilHash) { + String[] values = MapTestEnvironment.prepareValues(maxValue); + ContinousHashProvider chp = MapTestEnvironment.prepareHashProvider(evilHash); + + VersionedMapStore store = new VersionedMapStoreImpl(chp, values[0]); + VersionedMapImpl sut = (VersionedMapImpl) store.createMap(); + MapTestEnvironment e = new MapTestEnvironment(sut); + + Random r = new Random(seed); + + iterativeRandomPutsAndCommits(scenario, steps, maxKey, values, e, r, commitFrequency); + } + + private void iterativeRandomPutsAndCommits(String scenario, int steps, int maxKey, String[] values, + MapTestEnvironment e, Random r, int commitFrequency) { + int stopAt = -1; + for (int i = 0; i < steps; i++) { + int index = i + 1; + int nextKey = r.nextInt(maxKey); + String nextValue = values[r.nextInt(values.length)]; + if (index == stopAt) { + System.out.println("issue!"); + System.out.println("State before:"); + e.printComparison(); + e.sut.prettyPrint(); + System.out.println("Next: put(" + nextKey + "," + nextValue + ")"); + } + try { + e.put(nextKey, nextValue); + if (index == stopAt) { + e.sut.prettyPrint(); + } + e.checkEquivalence(scenario + ":" + index); + } catch (Exception exception) { + exception.printStackTrace(); + fail(scenario + ":" + index + ": exception happened: " + exception); + } + MapTestEnvironment.printStatus(scenario, index, steps, null); + if (index % commitFrequency == 0) { + e.sut.commit(); + } + } + } + + @ParameterizedTest(name = "Immutable Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") + @MethodSource + @Timeout(value = 10) + @Tag("smoke") + void parametrizedFastSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, + boolean evilHash) { + runSmokeTest("SmokeCommitS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, noKeys, noValues, + commitFrequency, evilHash); + } + + static Stream parametrizedFastSmoke() { + return SmokeTestUtils.permutationWithSize(new Object[] { 1000 }, new Object[] { 3, 32, 32 * 32 }, + new Object[] { 2, 3 }, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, + new Object[] { false, true }); + } + + @ParameterizedTest(name = "Immutable Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") + @MethodSource + @Tag("smoke") + @Tag("slow") + void parametrizedSlowSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, + boolean evilHash) { + runSmokeTest("SmokeCommitS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, noKeys, noValues, + commitFrequency, evilHash); + } + + static Stream parametrizedSlowSmoke() { + return SmokeTestUtils.changeStepCount(parametrizedFastSmoke(), 1); + } +} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/DiffCursorSmokeTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/DiffCursorSmokeTest.java new file mode 100644 index 00000000..c36fac47 --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/DiffCursorSmokeTest.java @@ -0,0 +1,103 @@ +package org.eclipse.viatra.solver.data.map.tests.smoke; + +import static org.junit.jupiter.api.Assertions.fail; + +import java.util.Random; +import java.util.stream.Stream; + +import org.eclipse.viatra.solver.data.map.ContinousHashProvider; +import org.eclipse.viatra.solver.data.map.DiffCursor; +import org.eclipse.viatra.solver.data.map.VersionedMapStore; +import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; +import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; +import org.eclipse.viatra.solver.data.map.tests.smoke.utils.SmokeTestUtils; +import org.eclipse.viatra.solver.data.map.tests.utils.MapTestEnvironment; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class DiffCursorSmokeTest { + private void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, int commitFrequency, + boolean evilHash) { + String[] values = MapTestEnvironment.prepareValues(maxValue); + ContinousHashProvider chp = MapTestEnvironment.prepareHashProvider(evilHash); + + VersionedMapStore store = new VersionedMapStoreImpl(chp, values[0]); + iterativeRandomPutsAndCommitsThenDiffcursor(scenario, store, steps, maxKey, values, seed, commitFrequency); + } + + private void iterativeRandomPutsAndCommitsThenDiffcursor(String scenario, VersionedMapStore store, + int steps, int maxKey, String[] values, int seed, int commitFrequency) { + // 1. build a map with versions + Random r = new Random(seed); + VersionedMapImpl versioned = (VersionedMapImpl) store.createMap(); + int largestCommit = -1; + + for (int i = 0; i < steps; i++) { + int index = i + 1; + int nextKey = r.nextInt(maxKey); + String nextValue = values[r.nextInt(values.length)]; + try { + versioned.put(nextKey, nextValue); + } catch (Exception exception) { + exception.printStackTrace(); + fail(scenario + ":" + index + ": exception happened: " + exception); + } + if (index % commitFrequency == 0) { + long version = versioned.commit(); + largestCommit = (int) version; + } + if (index % 10000 == 0) + System.out.println(scenario + ":" + index + "/" + steps + " building finished"); + } + // 2. create a non-versioned map, + VersionedMapImpl moving = (VersionedMapImpl) store.createMap(); + Random r2 = new Random(seed + 1); + + final int diffTravelFrequency = commitFrequency * 2; + for (int i = 0; i < steps; i++) { + int index = i + 1; + if (index % diffTravelFrequency == 0) { + // difftravel + long travelToVersion = r2.nextInt(largestCommit + 1); + DiffCursor diffCursor = moving.getDiffCursor(travelToVersion); + moving.putAll(diffCursor); + + } else { + // random puts + int nextKey = r2.nextInt(maxKey); + String nextValue = values[r2.nextInt(values.length)]; + try { + moving.put(nextKey, nextValue); + } catch (Exception exception) { + exception.printStackTrace(); + fail(scenario + ":" + index + ": exception happened: " + exception); + } + if (index % commitFrequency == 0) { + versioned.commit(); + } + if (index % 10000 == 0) + System.out.println(scenario + ":" + index + "/" + steps + " building finished"); + } + } + + } + + @ParameterizedTest(name = "Mutable-Immutable Compare Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") + @MethodSource + @Timeout(value = 10) + @Tag("smoke") + void parametrizedSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, + boolean evilHash) { + runSmokeTest("SmokeMutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, + noKeys, noValues, commitFrequency, evilHash); + } + + static Stream parametrizedSmoke() { + return SmokeTestUtils.permutationWithSize(new Object[] { 1000 }, new Object[] { 3, 32, 32 * 32 }, + new Object[] { 2, 3 }, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, + new Object[] { false, true }); + } +} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/MutableImmutableCompareSmokeTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/MutableImmutableCompareSmokeTest.java new file mode 100644 index 00000000..115b1fec --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/MutableImmutableCompareSmokeTest.java @@ -0,0 +1,88 @@ +package org.eclipse.viatra.solver.data.map.tests.smoke; + +import static org.junit.jupiter.api.Assertions.fail; + +import java.util.Random; +import java.util.stream.Stream; + +import org.eclipse.viatra.solver.data.map.ContinousHashProvider; +import org.eclipse.viatra.solver.data.map.VersionedMapStore; +import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; +import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; +import org.eclipse.viatra.solver.data.map.tests.smoke.utils.SmokeTestUtils; +import org.eclipse.viatra.solver.data.map.tests.utils.MapTestEnvironment; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class MutableImmutableCompareSmokeTest { + private void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, int commitFrequency, + boolean evilHash) { + String[] values = MapTestEnvironment.prepareValues(maxValue); + ContinousHashProvider chp = MapTestEnvironment.prepareHashProvider(evilHash); + + VersionedMapStore store = new VersionedMapStoreImpl(chp, values[0]); + VersionedMapImpl immutable = (VersionedMapImpl) store.createMap(); + VersionedMapImpl mutable = (VersionedMapImpl) store.createMap(); + + Random r = new Random(seed); + + iterativeRandomPutsAndCommitsAndCompare(scenario, immutable, mutable, steps, maxKey, values, r, + commitFrequency); + } + + private void iterativeRandomPutsAndCommitsAndCompare(String scenario, VersionedMapImpl immutable, + VersionedMapImpl mutable, int steps, int maxKey, String[] values, Random r, + int commitFrequency) { + for (int i = 0; i < steps; i++) { + int index = i + 1; + int nextKey = r.nextInt(maxKey); + String nextValue = values[r.nextInt(values.length)]; + try { + immutable.put(nextKey, nextValue); + mutable.put(nextKey, nextValue); + } catch (Exception exception) { + exception.printStackTrace(); + fail(scenario + ":" + index + ": exception happened: " + exception); + } + if (index % commitFrequency == 0) { + immutable.commit(); + } + MapTestEnvironment.compareTwoMaps(scenario + ":" + index, immutable, mutable); + + MapTestEnvironment.printStatus(scenario, index, steps, null); + } + } + + @ParameterizedTest(name = "Mutable-Immutable Compare Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") + @MethodSource + @Timeout(value = 10) + @Tag("smoke") + void parametrizedFastSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, + boolean evilHash) { + runSmokeTest("SmokeMutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, + noKeys, noValues, commitFrequency, evilHash); + } + + static Stream parametrizedFastSmoke() { + return SmokeTestUtils.permutationWithSize(new Object[] { 1000 }, new Object[] { 3, 32, 32 * 32 }, + new Object[] { 2, 3 }, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, + new Object[] { false, true }); + } + + @ParameterizedTest(name = "Mutable-Immutable Compare Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") + @MethodSource + @Tag("smoke") + @Tag("slow") + void parametrizedSlowSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, + boolean evilHash) { + runSmokeTest("SmokeMutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, + noKeys, noValues, commitFrequency, evilHash); + } + + static Stream parametrizedSlowSmoke() { + return SmokeTestUtils.changeStepCount(MutableImmutableCompareSmokeTest.parametrizedSlowSmoke(), 1); + } +} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/MutableSmokeTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/MutableSmokeTest.java new file mode 100644 index 00000000..999325f0 --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/MutableSmokeTest.java @@ -0,0 +1,77 @@ +package org.eclipse.viatra.solver.data.map.tests.smoke; + +import static org.junit.jupiter.api.Assertions.fail; + +import java.util.Random; +import java.util.stream.Stream; + +import org.eclipse.viatra.solver.data.map.ContinousHashProvider; +import org.eclipse.viatra.solver.data.map.VersionedMapStore; +import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; +import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; +import org.eclipse.viatra.solver.data.map.tests.smoke.utils.SmokeTestUtils; +import org.eclipse.viatra.solver.data.map.tests.utils.MapTestEnvironment; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class MutableSmokeTest { + private void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, boolean evilHash) { + String[] values = MapTestEnvironment.prepareValues(maxValue); + ContinousHashProvider chp = MapTestEnvironment.prepareHashProvider(evilHash); + + VersionedMapStore store = new VersionedMapStoreImpl(chp, values[0]); + VersionedMapImpl sut = (VersionedMapImpl) store.createMap(); + MapTestEnvironment e = new MapTestEnvironment(sut); + + Random r = new Random(seed); + + iterativeRandomPuts(scenario, steps, maxKey, values, e, r); + } + + private void iterativeRandomPuts(String scenario, int steps, int maxKey, String[] values, + MapTestEnvironment e, Random r) { + int stopAt = -1; + for (int i = 0; i < steps; i++) { + int index = i + 1; + int nextKey = r.nextInt(maxKey); + String nextValue = values[r.nextInt(values.length)]; + if (index == stopAt) { + System.out.println("issue!"); + System.out.println("State before:"); + e.printComparison(); + e.sut.prettyPrint(); + System.out.println("Next: put(" + nextKey + "," + nextValue + ")"); + } + try { + e.put(nextKey, nextValue); + if (index == stopAt) { + e.sut.prettyPrint(); + } + e.checkEquivalence(scenario + ":" + index); + } catch (Exception exception) { + exception.printStackTrace(); + fail(scenario + ":" + index + ": exception happened: " + exception); + } + MapTestEnvironment.printStatus(scenario, index, steps, null); + } + } + + @ParameterizedTest(name = "Mutable Smoke {index}/{0} Steps={1} Keys={2} Values={3} seed={4} evil-hash={5}") + @MethodSource + @Timeout(value = 10) + @Tag("smoke") + void parametrizedSmoke(int test, int steps, int noKeys, int noValues, int seed, boolean evilHash) { + runSmokeTest( + "SmokeS" + steps + "K" + noKeys + "V" + noValues + "s" + seed + "H" + (evilHash ? "Evil" : "Normal"), + seed, steps, noKeys, noValues, evilHash); + } + + static Stream parametrizedSmoke() { + return SmokeTestUtils.permutationWithSize(new Object[] { 1000 }, + new Object[] { 3, 32, 32 * 32, 32 * 32 * 32 * 32 }, new Object[] { 2, 3 }, new Object[] { 1, 2, 3 }, + new Object[] { false, true }); + } +} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/RestoreSmokeTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/RestoreSmokeTest.java new file mode 100644 index 00000000..fa96f0c1 --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/RestoreSmokeTest.java @@ -0,0 +1,108 @@ +package org.eclipse.viatra.solver.data.map.tests.smoke; + +import static org.junit.jupiter.api.Assertions.fail; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import java.util.stream.Stream; + +import org.eclipse.viatra.solver.data.map.ContinousHashProvider; +import org.eclipse.viatra.solver.data.map.VersionedMapStore; +import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; +import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; +import org.eclipse.viatra.solver.data.map.tests.smoke.utils.SmokeTestUtils; +import org.eclipse.viatra.solver.data.map.tests.utils.MapTestEnvironment; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class RestoreSmokeTest { + private void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, int commitFrequency, + boolean evilHash) { + String[] values = MapTestEnvironment.prepareValues(maxValue); + ContinousHashProvider chp = MapTestEnvironment.prepareHashProvider(evilHash); + + VersionedMapStore store = new VersionedMapStoreImpl(chp, values[0]); + + iterativeRandomPutsAndCommitsThenRestore(scenario, store, steps, maxKey, values, seed, commitFrequency); + } + + private void iterativeRandomPutsAndCommitsThenRestore(String scenario, VersionedMapStore store, + int steps, int maxKey, String[] values, int seed, int commitFrequency) { + // 1. build a map with versions + Random r = new Random(seed); + VersionedMapImpl versioned = (VersionedMapImpl) store.createMap(); + Map index2Version = new HashMap<>(); + + for (int i = 0; i < steps; i++) { + int index = i + 1; + int nextKey = r.nextInt(maxKey); + String nextValue = values[r.nextInt(values.length)]; + try { + versioned.put(nextKey, nextValue); + } catch (Exception exception) { + exception.printStackTrace(); + fail(scenario + ":" + index + ": exception happened: " + exception); + } + if (index % commitFrequency == 0) { + long version = versioned.commit(); + index2Version.put(i, version); + } + MapTestEnvironment.printStatus(scenario, index, steps, "building"); + } + // 2. create a non-versioned and + VersionedMapImpl reference = (VersionedMapImpl) store.createMap(); + r = new Random(seed); + + for (int i = 0; i < steps; i++) { + int index = i + 1; + int nextKey = r.nextInt(maxKey); + String nextValue = values[r.nextInt(values.length)]; + try { + reference.put(nextKey, nextValue); + } catch (Exception exception) { + exception.printStackTrace(); + fail(scenario + ":" + index + ": exception happened: " + exception); + } + if (index % commitFrequency == 0) { + versioned.restore(index2Version.get(i)); + MapTestEnvironment.compareTwoMaps(scenario + ":" + index, reference, versioned); + } + MapTestEnvironment.printStatus(scenario, index, steps, "comparison"); + } + + } + + @ParameterizedTest(name = "Restore Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") + @MethodSource + @Timeout(value = 10) + @Tag("smoke") + void parametrizedFastSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, + boolean evilHash) { + runSmokeTest("RestoreS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, noKeys, noValues, + commitFrequency, evilHash); + } + + static Stream parametrizedFastSmoke() { + return SmokeTestUtils.permutationWithSize(new Object[] { 1000 }, new Object[] { 3, 32, 32 * 32 }, + new Object[] { 2, 3 }, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, + new Object[] { false, true }); + } + + @ParameterizedTest(name = "Restore Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") + @MethodSource + @Tag("smoke") + @Tag("slow") + void parametrizedSlowSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, + boolean evilHash) { + runSmokeTest("RestoreS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, noKeys, noValues, + commitFrequency, evilHash); + } + + static Stream parametrizedSlowSmoke() { + return SmokeTestUtils.changeStepCount(RestoreSmokeTest.parametrizedFastSmoke(), 1); + } +} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/CommitSmokeTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/CommitSmokeTest.java deleted file mode 100644 index 5c340090..00000000 --- a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/CommitSmokeTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.eclipse.viatra.solver.data.map.tests.smoke.fast; - -import static org.junit.jupiter.api.Assertions.fail; - -import java.util.Random; -import java.util.stream.Stream; - -import org.eclipse.viatra.solver.data.map.ContinousHashProvider; -import org.eclipse.viatra.solver.data.map.VersionedMapStore; -import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; -import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; -import org.eclipse.viatra.solver.data.map.tests.smoke.utils.TestPermuter; -import org.eclipse.viatra.solver.data.map.tests.support.MapTestEnvironment; -import org.junit.jupiter.api.Timeout; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -public class CommitSmokeTest { - public void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, int commitFrequency, - boolean evilHash) { - String[] values = MapTestEnvironment.prepareValues(maxValue); - ContinousHashProvider chp = MapTestEnvironment.prepareHashProvider(evilHash); - - VersionedMapStore store = new VersionedMapStoreImpl(chp, values[0]); - VersionedMapImpl sut = (VersionedMapImpl) store.createMap(); - MapTestEnvironment e = new MapTestEnvironment(sut); - - Random r = new Random(seed); - - iterativeRandomPutsAndCommits(scenario, steps, maxKey, values, e, r, commitFrequency); - } - - private void iterativeRandomPutsAndCommits(String scenario, int steps, int maxKey, String[] values, - MapTestEnvironment e, Random r, int commitFrequency) { - int stopAt = -1; - for (int i = 0; i < steps; i++) { - int index = i + 1; - int nextKey = r.nextInt(maxKey); - String nextValue = values[r.nextInt(values.length)]; - if (index == stopAt) { - System.out.println("issue!"); - System.out.println("State before:"); - e.printComparison(); - e.sut.prettyPrint(); - System.out.println("Next: put(" + nextKey + "," + nextValue + ")"); - } - try { - e.put(nextKey, nextValue); - if (index == stopAt) { - e.sut.prettyPrint(); - } - e.checkEquivalence(scenario + ":" + index); - } catch (Exception exception) { - exception.printStackTrace(); - fail(scenario + ":" + index + ": exception happened: " + exception); - } - MapTestEnvironment.printStatus(scenario, index, steps, null); - if (index % commitFrequency == 0) { - e.sut.commit(); - } - } - } - - @ParameterizedTest(name = "Immutable Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") - @MethodSource - @Timeout(value = 10) - public void parametrizedSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, - boolean evilHash) { - runSmokeTest("SmokeCommitS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, noKeys, noValues, - commitFrequency, evilHash); - } - - public static Stream parametrizedSmoke() { - return TestPermuter.permutationWithSize(new Object[] { 1000 }, new Object[] { 3, 32, 32 * 32 }, - new Object[] { 2, 3 }, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, - new Object[] { false, true }); - } -} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/DiffCursorSmokeTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/DiffCursorSmokeTest.java deleted file mode 100644 index ef51d05e..00000000 --- a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/DiffCursorSmokeTest.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.eclipse.viatra.solver.data.map.tests.smoke.fast; - -import static org.junit.jupiter.api.Assertions.fail; - -import java.util.Random; -import java.util.stream.Stream; - -import org.eclipse.viatra.solver.data.map.ContinousHashProvider; -import org.eclipse.viatra.solver.data.map.DiffCursor; -import org.eclipse.viatra.solver.data.map.VersionedMapStore; -import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; -import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; -import org.eclipse.viatra.solver.data.map.tests.smoke.utils.TestPermuter; -import org.eclipse.viatra.solver.data.map.tests.support.MapTestEnvironment; -import org.junit.jupiter.api.Timeout; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -public class DiffCursorSmokeTest { - public void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, int commitFrequency, - boolean evilHash) { - String[] values = MapTestEnvironment.prepareValues(maxValue); - ContinousHashProvider chp = MapTestEnvironment.prepareHashProvider(evilHash); - - VersionedMapStore store = new VersionedMapStoreImpl(chp, values[0]); - iterativeRandomPutsAndCommitsThenDiffcursor(scenario, store, steps, maxKey, values, seed, commitFrequency); - } - - void iterativeRandomPutsAndCommitsThenDiffcursor(String scenario, VersionedMapStore store, - int steps, int maxKey, String[] values, int seed, int commitFrequency) { - // 1. build a map with versions - Random r = new Random(seed); - VersionedMapImpl versioned = (VersionedMapImpl) store.createMap(); - int largestCommit = -1; - - for (int i = 0; i < steps; i++) { - int index = i + 1; - int nextKey = r.nextInt(maxKey); - String nextValue = values[r.nextInt(values.length)]; - try { - versioned.put(nextKey, nextValue); - } catch (Exception exception) { - exception.printStackTrace(); - fail(scenario + ":" + index + ": exception happened: " + exception); - } - if (index % commitFrequency == 0) { - long version = versioned.commit(); - largestCommit = (int) version; - } - if (index % 10000 == 0) - System.out.println(scenario + ":" + index + "/" + steps + " building finished"); - } - // 2. create a non-versioned map, - VersionedMapImpl moving = (VersionedMapImpl) store.createMap(); - Random r2 = new Random(seed + 1); - - final int diffTravelFrequency = commitFrequency * 2; - for (int i = 0; i < steps; i++) { - int index = i + 1; - if (index % diffTravelFrequency == 0) { - // difftravel - long travelToVersion = r2.nextInt(largestCommit + 1); - DiffCursor diffCursor = moving.getDiffCursor(travelToVersion); - moving.putAll(diffCursor); - - } else { - // random puts - int nextKey = r2.nextInt(maxKey); - String nextValue = values[r2.nextInt(values.length)]; - try { - moving.put(nextKey, nextValue); - } catch (Exception exception) { - exception.printStackTrace(); - fail(scenario + ":" + index + ": exception happened: " + exception); - } - if (index % commitFrequency == 0) { - versioned.commit(); - } - if (index % 10000 == 0) - System.out.println(scenario + ":" + index + "/" + steps + " building finished"); - } - } - - } - - @ParameterizedTest(name = "Mutable-Immutable Compare Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") - @MethodSource - @Timeout(value = 10) - void parametrizedSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, - boolean evilHash) { - runSmokeTest("SmokeMutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, - noKeys, noValues, commitFrequency, evilHash); - } - - public static Stream parametrizedSmoke() { - return TestPermuter.permutationWithSize(new Object[] { 1000 }, new Object[] { 3, 32, 32 * 32 }, - new Object[] { 2, 3 }, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, - new Object[] { false, true }); - } -} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/MutableImmutableCompareSmokeTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/MutableImmutableCompareSmokeTest.java deleted file mode 100644 index ac5571b3..00000000 --- a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/MutableImmutableCompareSmokeTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.eclipse.viatra.solver.data.map.tests.smoke.fast; - -import static org.junit.jupiter.api.Assertions.fail; - -import java.util.Random; -import java.util.stream.Stream; - -import org.eclipse.viatra.solver.data.map.ContinousHashProvider; -import org.eclipse.viatra.solver.data.map.VersionedMapStore; -import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; -import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; -import org.eclipse.viatra.solver.data.map.tests.smoke.utils.TestPermuter; -import org.eclipse.viatra.solver.data.map.tests.support.MapTestEnvironment; -import org.junit.jupiter.api.Timeout; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -public class MutableImmutableCompareSmokeTest { - public void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, int commitFrequency, - boolean evilHash) { - String[] values = MapTestEnvironment.prepareValues(maxValue); - ContinousHashProvider chp = MapTestEnvironment.prepareHashProvider(evilHash); - - VersionedMapStore store = new VersionedMapStoreImpl(chp, values[0]); - VersionedMapImpl immutable = (VersionedMapImpl) store.createMap(); - VersionedMapImpl mutable = (VersionedMapImpl) store.createMap(); - - Random r = new Random(seed); - - iterativeRandomPutsAndCommitsAndCompare(scenario, immutable, mutable, steps, maxKey, values, r, - commitFrequency); - } - - void iterativeRandomPutsAndCommitsAndCompare(String scenario, VersionedMapImpl immutable, - VersionedMapImpl mutable, int steps, int maxKey, String[] values, Random r, - int commitFrequency) { - for (int i = 0; i < steps; i++) { - int index = i + 1; - int nextKey = r.nextInt(maxKey); - String nextValue = values[r.nextInt(values.length)]; - try { - immutable.put(nextKey, nextValue); - mutable.put(nextKey, nextValue); - } catch (Exception exception) { - exception.printStackTrace(); - fail(scenario + ":" + index + ": exception happened: " + exception); - } - if (index % commitFrequency == 0) { - immutable.commit(); - } - MapTestEnvironment.compareTwoMaps(scenario + ":" + index, immutable, mutable); - - MapTestEnvironment.printStatus(scenario, index, steps, null); - } - } - - @ParameterizedTest(name = "Mutable-Immutable Compare Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") - @MethodSource - @Timeout(value = 10) - void parametrizedSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, - boolean evilHash) { - runSmokeTest("SmokeMutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, - noKeys, noValues, commitFrequency, evilHash); - } - - public static Stream parametrizedSmoke() { - return TestPermuter.permutationWithSize(new Object[] { 1000 }, new Object[] { 3, 32, 32 * 32 }, - new Object[] { 2, 3 }, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, - new Object[] { false, true }); - } -} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/MutableSmokeTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/MutableSmokeTest.java deleted file mode 100644 index c24c220d..00000000 --- a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/MutableSmokeTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.eclipse.viatra.solver.data.map.tests.smoke.fast; - -import static org.junit.jupiter.api.Assertions.fail; - -import java.util.Random; -import java.util.stream.Stream; - -import org.eclipse.viatra.solver.data.map.ContinousHashProvider; -import org.eclipse.viatra.solver.data.map.VersionedMapStore; -import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; -import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; -import org.eclipse.viatra.solver.data.map.tests.smoke.utils.TestPermuter; -import org.eclipse.viatra.solver.data.map.tests.support.MapTestEnvironment; -import org.junit.jupiter.api.Timeout; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -public class MutableSmokeTest { - - public void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, boolean evilHash) { - String[] values = MapTestEnvironment.prepareValues(maxValue); - ContinousHashProvider chp = MapTestEnvironment.prepareHashProvider(evilHash); - - VersionedMapStore store = new VersionedMapStoreImpl(chp, values[0]); - VersionedMapImpl sut = (VersionedMapImpl) store.createMap(); - MapTestEnvironment e = new MapTestEnvironment(sut); - - Random r = new Random(seed); - - iterativeRandomPuts(scenario, steps, maxKey, values, e, r); - } - - void iterativeRandomPuts(String scenario, int steps, int maxKey, String[] values, - MapTestEnvironment e, Random r) { - int stopAt = -1; - for (int i = 0; i < steps; i++) { - int index = i + 1; - int nextKey = r.nextInt(maxKey); - String nextValue = values[r.nextInt(values.length)]; - if (index == stopAt) { - System.out.println("issue!"); - System.out.println("State before:"); - e.printComparison(); - e.sut.prettyPrint(); - System.out.println("Next: put(" + nextKey + "," + nextValue + ")"); - } - try { - e.put(nextKey, nextValue); - if (index == stopAt) { - e.sut.prettyPrint(); - } - e.checkEquivalence(scenario + ":" + index); - } catch (Exception exception) { - exception.printStackTrace(); - fail(scenario + ":" + index + ": exception happened: " + exception); - } - MapTestEnvironment.printStatus(scenario, index, steps, null); - } - } - - @ParameterizedTest(name = "Mutable Smoke {index}/{0} Steps={1} Keys={2} Values={3} seed={4} evil-hash={5}") - @MethodSource - @Timeout(value = 10) - void parametrizedSmoke(int test, int steps, int noKeys, int noValues, int seed, boolean evilHash) { - runSmokeTest( - "SmokeS" + steps + "K" + noKeys + "V" + noValues + "s" + seed + "H" + (evilHash ? "Evil" : "Normal"), - seed, steps, noKeys, noValues, evilHash); - } - - public static Stream parametrizedSmoke() { - return TestPermuter.permutationWithSize(new Object[] { 1000 }, - new Object[] { 3, 32, 32 * 32, 32 * 32 * 32 * 32 }, new Object[] { 2, 3 }, new Object[] { 1, 2, 3 }, - new Object[] { false, true }); - } -} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/RestoreSmokeTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/RestoreSmokeTest.java deleted file mode 100644 index 4ca9b088..00000000 --- a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/RestoreSmokeTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.eclipse.viatra.solver.data.map.tests.smoke.fast; - -import static org.junit.jupiter.api.Assertions.fail; - -import java.util.HashMap; -import java.util.Map; -import java.util.Random; -import java.util.stream.Stream; - -import org.eclipse.viatra.solver.data.map.ContinousHashProvider; -import org.eclipse.viatra.solver.data.map.VersionedMapStore; -import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; -import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; -import org.eclipse.viatra.solver.data.map.tests.smoke.utils.TestPermuter; -import org.eclipse.viatra.solver.data.map.tests.support.MapTestEnvironment; -import org.junit.jupiter.api.Timeout; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -public class RestoreSmokeTest { - public void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, int commitFrequency, - boolean evilHash) { - String[] values = MapTestEnvironment.prepareValues(maxValue); - ContinousHashProvider chp = MapTestEnvironment.prepareHashProvider(evilHash); - - VersionedMapStore store = new VersionedMapStoreImpl(chp, values[0]); - - iterativeRandomPutsAndCommitsThenRestore(scenario, store, steps, maxKey, values, seed, commitFrequency); - } - - void iterativeRandomPutsAndCommitsThenRestore(String scenario, VersionedMapStore store, int steps, - int maxKey, String[] values, int seed, int commitFrequency) { - // 1. build a map with versions - Random r = new Random(seed); - VersionedMapImpl versioned = (VersionedMapImpl) store.createMap(); - Map index2Version = new HashMap<>(); - - for (int i = 0; i < steps; i++) { - int index = i + 1; - int nextKey = r.nextInt(maxKey); - String nextValue = values[r.nextInt(values.length)]; - try { - versioned.put(nextKey, nextValue); - } catch (Exception exception) { - exception.printStackTrace(); - fail(scenario + ":" + index + ": exception happened: " + exception); - } - if (index % commitFrequency == 0) { - long version = versioned.commit(); - index2Version.put(i, version); - } - MapTestEnvironment.printStatus(scenario, index, steps, "building"); - } - // 2. create a non-versioned and - VersionedMapImpl reference = (VersionedMapImpl) store.createMap(); - r = new Random(seed); - - for (int i = 0; i < steps; i++) { - int index = i + 1; - int nextKey = r.nextInt(maxKey); - String nextValue = values[r.nextInt(values.length)]; - try { - reference.put(nextKey, nextValue); - } catch (Exception exception) { - exception.printStackTrace(); - fail(scenario + ":" + index + ": exception happened: " + exception); - } - if (index % commitFrequency == 0) { - versioned.restore(index2Version.get(i)); - MapTestEnvironment.compareTwoMaps(scenario + ":" + index, reference, versioned); - } - MapTestEnvironment.printStatus(scenario, index, steps, "comparison"); - } - - } - - @ParameterizedTest(name = "Mutable-Immutable Compare Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") - @MethodSource - @Timeout(value = 10) - void parametrizedSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, - boolean evilHash) { - runSmokeTest("SmokeMutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, - noKeys, noValues, commitFrequency, evilHash); - } - - public static Stream parametrizedSmoke() { - return TestPermuter.permutationWithSize(new Object[] { 1000 }, new Object[] { 3, 32, 32 * 32 }, - new Object[] { 2, 3 }, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, - new Object[] { false, true }); - } -} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/slow/SlowSmokeTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/slow/SlowSmokeTest.java deleted file mode 100644 index 004d30d9..00000000 --- a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/slow/SlowSmokeTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.eclipse.viatra.solver.data.map.tests.smoke.slow; - -import java.util.Arrays; -import java.util.stream.Stream; - -import org.eclipse.viatra.solver.data.map.tests.smoke.fast.CommitSmokeTest; -import org.eclipse.viatra.solver.data.map.tests.smoke.fast.MutableImmutableCompareSmokeTest; -import org.eclipse.viatra.solver.data.map.tests.smoke.fast.MutableSmokeTest; -import org.eclipse.viatra.solver.data.map.tests.smoke.fast.RestoreSmokeTest; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -@Disabled -public class SlowSmokeTest { - - private static int slowStepCount = 32 * 32 * 32 * 32; - - private static Stream changeStepCount(Stream arguments) { - return arguments.map(x -> Arguments.of(updatedStepCount(x.get()))); - - } - - private static Object[] updatedStepCount(Object[] arguments) { - Object[] copy = Arrays.copyOf(arguments, arguments.length); - copy[1] = slowStepCount; - return copy; - } - - @ParameterizedTest(name = "Mutable Smoke {index}/{0} Steps={1} Keys={2} Values={3} seed={4} evil-hash={5}") - @MethodSource - void smoke1(int test, int steps, int noKeys, int noValues, int seed, boolean evilHash) { - (new MutableSmokeTest()).runSmokeTest( - "SmokeS" + steps + "K" + noKeys + "V" + noValues + "s" + seed + "H" + (evilHash ? "Evil" : "Normal"), - seed, steps, noKeys, noValues, evilHash); - } - - private static Stream smoke1() { - return changeStepCount(MutableSmokeTest.parametrizedSmoke()); - } - - @ParameterizedTest(name = "Immutable Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") - @MethodSource - void smoke2(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, boolean evilHash) { - (new CommitSmokeTest()).runSmokeTest("SmokeCommitS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, - steps, noKeys, noValues, commitFrequency, evilHash); - } - - private static Stream smoke2() { - return changeStepCount(CommitSmokeTest.parametrizedSmoke()); - } - - @ParameterizedTest(name = "Mutable-Immutable Compare Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") - @MethodSource - void smoke3(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, boolean evilHash) { - (new MutableImmutableCompareSmokeTest()).runSmokeTest( - "SmokeMutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, - noKeys, noValues, commitFrequency, evilHash); - } - - private static Stream smoke3() { - return changeStepCount(MutableImmutableCompareSmokeTest.parametrizedSmoke()); - } - - @ParameterizedTest(name = "Mutable-Immutable Compare Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") - @MethodSource - void smoke4(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, boolean evilHash) { - (new RestoreSmokeTest()).runSmokeTest( - "SmokeMutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, - noKeys, noValues, commitFrequency, evilHash); - } - - private static Stream smoke4() { - return changeStepCount(RestoreSmokeTest.parametrizedSmoke()); - } -} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/SmokeTestUtils.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/SmokeTestUtils.java new file mode 100644 index 00000000..9eab854f --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/SmokeTestUtils.java @@ -0,0 +1,63 @@ +package org.eclipse.viatra.solver.data.map.tests.smoke.utils; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.params.provider.Arguments; + +public final class SmokeTestUtils { + private static final int SLOW_STEP_COUNT = 32 * 32 * 32 * 32; + + private SmokeTestUtils() { + throw new IllegalStateException("This is a static utility class and should not be instantiated directly"); + } + + public static Stream changeStepCount(Stream arguments, int parameterIndex) { + return arguments.map(x -> Arguments.of(updatedStepCount(x.get(), parameterIndex))); + } + + public static Object[] updatedStepCount(Object[] arguments, int parameterIndex) { + Object[] copy = Arrays.copyOf(arguments, arguments.length); + copy[parameterIndex] = SLOW_STEP_COUNT; + return copy; + } + + static List> permutationInternal(int from, Object[]... valueOption) { + if (valueOption.length == from) { + return List.of(List.of()); + } else { + Object[] permuteThis = valueOption[from]; + List> otherCombination = permutationInternal(from + 1, valueOption); + List> result = new LinkedList<>(); + for (Object permuteThisElement : permuteThis) { + for (List otherCombinationList : otherCombination) { + List newResult = new LinkedList<>(); + newResult.add(permuteThisElement); + newResult.addAll(otherCombinationList); + result.add(newResult); + } + } + return result; + } + } + + public static Stream permutation(Object[]... valueOption) { + List> permutations = permutationInternal(0, valueOption); + return permutations.stream().map(x -> Arguments.of(x.toArray())); + } + + public static Stream permutationWithSize(Object[]... valueOption) { + int size = 1; + for (int i = 0; i < valueOption.length; i++) { + size *= valueOption[i].length; + } + Object[][] newValueOption = new Object[valueOption.length + 1][]; + newValueOption[0] = new Object[] { size }; + for (int i = 1; i < newValueOption.length; i++) { + newValueOption[i] = valueOption[i - 1]; + } + return permutation(newValueOption); + } +} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/SmoteTestUtilsTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/SmoteTestUtilsTest.java new file mode 100644 index 00000000..376b3e50 --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/SmoteTestUtilsTest.java @@ -0,0 +1,33 @@ +package org.eclipse.viatra.solver.data.map.tests.smoke.utils; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; + +import org.junit.jupiter.api.Test; + +class SmoteTestUtilsTest { + @Test + void permutationInternalTest() { + List> res = SmokeTestUtils.permutationInternal(0, new Object[] { 1, 2, 3 }, + new Object[] { 'a', 'b', 'c' }, new Object[] { "alpha", "beta", "gamma", "delta" }); + assertEquals(3 * 3 * 4, res.size()); + } + + @Test + void permutationTest1() { + var res = SmokeTestUtils.permutation(new Object[] { 1, 2, 3 }, new Object[] { 'a', 'b', 'c' }, + new Object[] { "alpha", "beta", "gamma", "delta" }); + assertEquals(3 * 3 * 4, res.count()); + } + + @Test + void permutationTest2() { + var res = SmokeTestUtils.permutation(new Object[] { 1, 2, 3 }, new Object[] { 'a', 'b', 'c' }, + new Object[] { "alpha", "beta", "gamma", "delta" }); + var arguments = res.findFirst().get().get(); + assertEquals(1, arguments[0]); + assertEquals('a', arguments[1]); + assertEquals("alpha", arguments[2]); + } +} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuter.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuter.java deleted file mode 100644 index 0f7b4642..00000000 --- a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuter.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.eclipse.viatra.solver.data.map.tests.smoke.utils; - -import java.util.LinkedList; -import java.util.List; -import java.util.stream.Stream; - -import org.junit.jupiter.params.provider.Arguments; - -public class TestPermuter { - static List> permutationInternal(int from, Object[]... valueOption) { - if (valueOption.length == from) { - return List.of(List.of()); - } else { - Object[] permuteThis = valueOption[from]; - List> otherCombination = permutationInternal(from + 1, valueOption); - List> result = new LinkedList<>(); - for (Object permuteThisElement : permuteThis) { - for (List otherCombinationList : otherCombination) { - List newResult = new LinkedList<>(); - newResult.add(permuteThisElement); - newResult.addAll(otherCombinationList); - result.add(newResult); - } - } - return result; - } - } - - public static Stream permutation(Object[]... valueOption) { - List> permutations = permutationInternal(0, valueOption); - return permutations.stream().map(x -> Arguments.of(x.toArray())); - } - - public static Stream permutationWithSize(Object[]... valueOption) { - int size = 1; - for (int i = 0; i < valueOption.length; i++) { - size *= valueOption[i].length; - } - Object[][] newValueOption = new Object[valueOption.length + 1][]; - newValueOption[0] = new Object[] { size }; - for (int i = 1; i < newValueOption.length; i++) { - newValueOption[i] = valueOption[i - 1]; - } - return permutation(newValueOption); - } -} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuterTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuterTest.java deleted file mode 100644 index 91f1c2e0..00000000 --- a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuterTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.eclipse.viatra.solver.data.map.tests.smoke.utils; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.List; - -import org.junit.jupiter.api.Test; - -class TestPermuterTest { - @Test - void permutationInternalTest() { - List> res = TestPermuter.permutationInternal(0, new Object[] { 1, 2, 3 }, - new Object[] { 'a', 'b', 'c' }, new Object[] { "alpha", "beta", "gamma", "delta" }); - assertEquals(3 * 3 * 4, res.size()); - } - - @Test - void permutationTest1() { - var res = TestPermuter.permutation(new Object[] { 1, 2, 3 }, new Object[] { 'a', 'b', 'c' }, - new Object[] { "alpha", "beta", "gamma", "delta" }); - assertEquals(3 * 3 * 4, res.count()); - } - - @Test - void permutationTest2() { - var res = TestPermuter.permutation(new Object[] { 1, 2, 3 }, new Object[] { 'a', 'b', 'c' }, - new Object[] { "alpha", "beta", "gamma", "delta" }); - var arguments = res.findFirst().get().get(); - assertEquals(1, arguments[0]); - assertEquals('a', arguments[1]); - assertEquals("alpha", arguments[2]); - } -} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/support/MapTestEnvironment.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/support/MapTestEnvironment.java deleted file mode 100644 index 6c55be62..00000000 --- a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/support/MapTestEnvironment.java +++ /dev/null @@ -1,174 +0,0 @@ -package org.eclipse.viatra.solver.data.map.tests.support; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TreeMap; - -import org.eclipse.viatra.solver.data.map.ContinousHashProvider; -import org.eclipse.viatra.solver.data.map.Cursor; -import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; - -public class MapTestEnvironment { - public static String[] prepareValues(int maxValue) { - String[] values = new String[maxValue]; - values[0] = "DEFAULT"; - for (int i = 1; i < values.length; i++) { - values[i] = "VAL" + i; - } - return values; - } - - public static ContinousHashProvider prepareHashProvider(final boolean evil) { - // Use maxPrime = 2147483629 - - ContinousHashProvider chp = new ContinousHashProvider() { - - @Override - public int getHash(Integer key, int index) { - if (evil && index < 15 && index < key / 3) { - return 7; - } - int result = 1; - final int prime = 31; - - result = prime * result + key; - result = prime * result + index; - - return result; - } - }; - return chp; - } - - public static void printStatus(String scenario, int actual, int max, String stepName) { - if (actual % 10000 == 0) { - String printStepName = stepName == null ? "" : stepName; - System.out.format(scenario + ":%d/%d (%d%%) " + printStepName + "%n", actual, max, actual * 100 / max); - } - - } - - public static void compareTwoMaps(String title, VersionedMapImpl map1, - VersionedMapImpl map2) { - // 1. Comparing cursors. - Cursor cursor1 = map1.getCursor(); - Cursor cursor2 = map2.getCursor(); - while (!cursor1.isTerminated()) { - if (cursor2.isTerminated()) { - fail("cursor 2 terminated before cursor1"); - } - assertEquals(cursor1.getKey(), cursor2.getKey()); - assertEquals(cursor2.getValue(), cursor2.getValue()); - cursor1.move(); - cursor2.move(); - } - if (!cursor2.isTerminated()) - fail("cursor 1 terminated before cursor 2"); - - // 2.1. comparing hash codes - assertEquals(map1.hashCode(), map2.hashCode(), title + ": hash code check"); - assertEquals(map1, map2, title + ": 1.equals(2)"); - assertEquals(map2, map1, title + ": 2.equals(1)"); - } - - public VersionedMapImpl sut; - Map oracle = new HashMap(); - - public MapTestEnvironment(VersionedMapImpl sut) { - this.sut = sut; - } - - public void put(KEY key, VALUE value) { - sut.put(key, value); - if (value != sut.getDefaultValue()) { - oracle.put(key, value); - } else { - oracle.remove(key); - } - } - - public void checkEquivalence(String title) { - // 0. Checking integrity - try { - sut.checkIntegrity(); - } catch (IllegalStateException e) { - fail(title + ": " + e.getMessage()); - } - - // 1. Checking: if Reference contains pair, then SUT contains - // pair. - // Tests get functions - for (Entry entry : oracle.entrySet()) { - VALUE sutValue = sut.get(entry.getKey()); - VALUE oracleValue = entry.getValue(); - if (sutValue != oracleValue) { - printComparison(); - fail(title + ": Non-equivalent get(" + entry.getKey() + ") results: SUT=" + sutValue + ", Oracle=" - + oracleValue + "!"); - } - } - - // 2. Checking: if SUT contains pair, then Reference contains - // pair. - // Tests iterators - // TODO: Counts the number of elements in the entryset - int elementsInSutEntrySet = 0; - Cursor cursor = sut.getCursor(); - while (cursor.move()) { - elementsInSutEntrySet++; - KEY key = cursor.getKey(); - VALUE sutValue = cursor.getValue(); - // System.out.println(key + " -> " + sutValue); - VALUE oracleValue = oracle.get(key); - if (sutValue != oracleValue) { - printComparison(); - fail(title + ": Non-equivalent entry in iterator: SUT=<" + key + "," + sutValue + ">, Oracle=<" + key - + "," + oracleValue + ">!"); - } - - } - - // 3. Checking sizes - // Counting of non-default value pairs. - int oracleSize = oracle.entrySet().size(); - long sutSize = sut.getSize(); - if (oracleSize != sutSize || oracleSize != elementsInSutEntrySet) { - printComparison(); - fail(title + ": Non-eqivalent size() result: SUT.getSize()=" + sutSize + ", SUT.entryset.size=" - + elementsInSutEntrySet + ", Oracle=" + oracleSize + "!"); - } - } - - public void printComparison() { - System.out.println("SUT:"); - printEntrySet(sut.getCursor()); - System.out.println("Oracle:"); - printEntrySet(oracle.entrySet().iterator()); - } - - private void printEntrySet(Iterator> iterator) { - TreeMap treemap = new TreeMap<>(); - while (iterator.hasNext()) { - Entry entry = iterator.next(); - treemap.put(entry.getKey(), entry.getValue()); - } - for (Entry e : treemap.entrySet()) { - System.out.println("\t" + e.getKey() + " -> " + e.getValue()); - } - } - - private void printEntrySet(Cursor cursor) { - TreeMap treemap = new TreeMap<>(); - while (cursor.move()) { - treemap.put(cursor.getKey(), cursor.getValue()); - } - for (Entry e : treemap.entrySet()) { - System.out.println("\t" + e.getKey() + " -> " + e.getValue()); - } - } -} diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/utils/MapTestEnvironment.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/utils/MapTestEnvironment.java new file mode 100644 index 00000000..59e5e913 --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/utils/MapTestEnvironment.java @@ -0,0 +1,174 @@ +package org.eclipse.viatra.solver.data.map.tests.utils; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; + +import org.eclipse.viatra.solver.data.map.ContinousHashProvider; +import org.eclipse.viatra.solver.data.map.Cursor; +import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; + +public class MapTestEnvironment { + public static String[] prepareValues(int maxValue) { + String[] values = new String[maxValue]; + values[0] = "DEFAULT"; + for (int i = 1; i < values.length; i++) { + values[i] = "VAL" + i; + } + return values; + } + + public static ContinousHashProvider prepareHashProvider(final boolean evil) { + // Use maxPrime = 2147483629 + + ContinousHashProvider chp = new ContinousHashProvider() { + + @Override + public int getHash(Integer key, int index) { + if (evil && index < 15 && index < key / 3) { + return 7; + } + int result = 1; + final int prime = 31; + + result = prime * result + key; + result = prime * result + index; + + return result; + } + }; + return chp; + } + + public static void printStatus(String scenario, int actual, int max, String stepName) { + if (actual % 10000 == 0) { + String printStepName = stepName == null ? "" : stepName; + System.out.format(scenario + ":%d/%d (%d%%) " + printStepName + "%n", actual, max, actual * 100 / max); + } + + } + + public static void compareTwoMaps(String title, VersionedMapImpl map1, + VersionedMapImpl map2) { + // 1. Comparing cursors. + Cursor cursor1 = map1.getCursor(); + Cursor cursor2 = map2.getCursor(); + while (!cursor1.isTerminated()) { + if (cursor2.isTerminated()) { + fail("cursor 2 terminated before cursor1"); + } + assertEquals(cursor1.getKey(), cursor2.getKey()); + assertEquals(cursor2.getValue(), cursor2.getValue()); + cursor1.move(); + cursor2.move(); + } + if (!cursor2.isTerminated()) + fail("cursor 1 terminated before cursor 2"); + + // 2.1. comparing hash codes + assertEquals(map1.hashCode(), map2.hashCode(), title + ": hash code check"); + assertEquals(map1, map2, title + ": 1.equals(2)"); + assertEquals(map2, map1, title + ": 2.equals(1)"); + } + + public VersionedMapImpl sut; + Map oracle = new HashMap(); + + public MapTestEnvironment(VersionedMapImpl sut) { + this.sut = sut; + } + + public void put(KEY key, VALUE value) { + sut.put(key, value); + if (value != sut.getDefaultValue()) { + oracle.put(key, value); + } else { + oracle.remove(key); + } + } + + public void checkEquivalence(String title) { + // 0. Checking integrity + try { + sut.checkIntegrity(); + } catch (IllegalStateException e) { + fail(title + ": " + e.getMessage()); + } + + // 1. Checking: if Reference contains pair, then SUT contains + // pair. + // Tests get functions + for (Entry entry : oracle.entrySet()) { + VALUE sutValue = sut.get(entry.getKey()); + VALUE oracleValue = entry.getValue(); + if (sutValue != oracleValue) { + printComparison(); + fail(title + ": Non-equivalent get(" + entry.getKey() + ") results: SUT=" + sutValue + ", Oracle=" + + oracleValue + "!"); + } + } + + // 2. Checking: if SUT contains pair, then Reference contains + // pair. + // Tests iterators + // TODO: Counts the number of elements in the entryset + int elementsInSutEntrySet = 0; + Cursor cursor = sut.getCursor(); + while (cursor.move()) { + elementsInSutEntrySet++; + KEY key = cursor.getKey(); + VALUE sutValue = cursor.getValue(); + // System.out.println(key + " -> " + sutValue); + VALUE oracleValue = oracle.get(key); + if (sutValue != oracleValue) { + printComparison(); + fail(title + ": Non-equivalent entry in iterator: SUT=<" + key + "," + sutValue + ">, Oracle=<" + key + + "," + oracleValue + ">!"); + } + + } + + // 3. Checking sizes + // Counting of non-default value pairs. + int oracleSize = oracle.entrySet().size(); + long sutSize = sut.getSize(); + if (oracleSize != sutSize || oracleSize != elementsInSutEntrySet) { + printComparison(); + fail(title + ": Non-eqivalent size() result: SUT.getSize()=" + sutSize + ", SUT.entryset.size=" + + elementsInSutEntrySet + ", Oracle=" + oracleSize + "!"); + } + } + + public void printComparison() { + System.out.println("SUT:"); + printEntrySet(sut.getCursor()); + System.out.println("Oracle:"); + printEntrySet(oracle.entrySet().iterator()); + } + + private void printEntrySet(Iterator> iterator) { + TreeMap treemap = new TreeMap<>(); + while (iterator.hasNext()) { + Entry entry = iterator.next(); + treemap.put(entry.getKey(), entry.getValue()); + } + for (Entry e : treemap.entrySet()) { + System.out.println("\t" + e.getKey() + " -> " + e.getValue()); + } + } + + private void printEntrySet(Cursor cursor) { + TreeMap treemap = new TreeMap<>(); + while (cursor.move()) { + treemap.put(cursor.getKey(), cursor.getValue()); + } + for (Entry e : treemap.entrySet()) { + System.out.println("\t" + e.getKey() + " -> " + e.getValue()); + } + } +} -- cgit v1.2.3-70-g09d2