diff options
Diffstat (limited to 'model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/CommitSmokeTest.java')
-rw-r--r-- | model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/CommitSmokeTest.java | 79 |
1 files changed, 79 insertions, 0 deletions
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 new file mode 100644 index 00000000..5c340090 --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/CommitSmokeTest.java | |||
@@ -0,0 +1,79 @@ | |||
1 | package org.eclipse.viatra.solver.data.map.tests.smoke.fast; | ||
2 | |||
3 | import static org.junit.jupiter.api.Assertions.fail; | ||
4 | |||
5 | import java.util.Random; | ||
6 | import java.util.stream.Stream; | ||
7 | |||
8 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
9 | import org.eclipse.viatra.solver.data.map.VersionedMapStore; | ||
10 | import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; | ||
11 | import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; | ||
12 | import org.eclipse.viatra.solver.data.map.tests.smoke.utils.TestPermuter; | ||
13 | import org.eclipse.viatra.solver.data.map.tests.support.MapTestEnvironment; | ||
14 | import org.junit.jupiter.api.Timeout; | ||
15 | import org.junit.jupiter.params.ParameterizedTest; | ||
16 | import org.junit.jupiter.params.provider.Arguments; | ||
17 | import org.junit.jupiter.params.provider.MethodSource; | ||
18 | |||
19 | public class CommitSmokeTest { | ||
20 | public void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, int commitFrequency, | ||
21 | boolean evilHash) { | ||
22 | String[] values = MapTestEnvironment.prepareValues(maxValue); | ||
23 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | ||
24 | |||
25 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<Integer, String>(chp, values[0]); | ||
26 | VersionedMapImpl<Integer, String> sut = (VersionedMapImpl<Integer, String>) store.createMap(); | ||
27 | MapTestEnvironment<Integer, String> e = new MapTestEnvironment<Integer, String>(sut); | ||
28 | |||
29 | Random r = new Random(seed); | ||
30 | |||
31 | iterativeRandomPutsAndCommits(scenario, steps, maxKey, values, e, r, commitFrequency); | ||
32 | } | ||
33 | |||
34 | private void iterativeRandomPutsAndCommits(String scenario, int steps, int maxKey, String[] values, | ||
35 | MapTestEnvironment<Integer, String> e, Random r, int commitFrequency) { | ||
36 | int stopAt = -1; | ||
37 | for (int i = 0; i < steps; i++) { | ||
38 | int index = i + 1; | ||
39 | int nextKey = r.nextInt(maxKey); | ||
40 | String nextValue = values[r.nextInt(values.length)]; | ||
41 | if (index == stopAt) { | ||
42 | System.out.println("issue!"); | ||
43 | System.out.println("State before:"); | ||
44 | e.printComparison(); | ||
45 | e.sut.prettyPrint(); | ||
46 | System.out.println("Next: put(" + nextKey + "," + nextValue + ")"); | ||
47 | } | ||
48 | try { | ||
49 | e.put(nextKey, nextValue); | ||
50 | if (index == stopAt) { | ||
51 | e.sut.prettyPrint(); | ||
52 | } | ||
53 | e.checkEquivalence(scenario + ":" + index); | ||
54 | } catch (Exception exception) { | ||
55 | exception.printStackTrace(); | ||
56 | fail(scenario + ":" + index + ": exception happened: " + exception); | ||
57 | } | ||
58 | MapTestEnvironment.printStatus(scenario, index, steps, null); | ||
59 | if (index % commitFrequency == 0) { | ||
60 | e.sut.commit(); | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | |||
65 | @ParameterizedTest(name = "Immutable Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") | ||
66 | @MethodSource | ||
67 | @Timeout(value = 10) | ||
68 | public void parametrizedSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, | ||
69 | boolean evilHash) { | ||
70 | runSmokeTest("SmokeCommitS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, noKeys, noValues, | ||
71 | commitFrequency, evilHash); | ||
72 | } | ||
73 | |||
74 | public static Stream<Arguments> parametrizedSmoke() { | ||
75 | return TestPermuter.permutationWithSize(new Object[] { 1000 }, new Object[] { 3, 32, 32 * 32 }, | ||
76 | new Object[] { 2, 3 }, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, | ||
77 | new Object[] { false, true }); | ||
78 | } | ||
79 | } | ||