diff options
Diffstat (limited to 'model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/DiffCursorSmokeTest.java')
-rw-r--r-- | model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/DiffCursorSmokeTest.java | 101 |
1 files changed, 0 insertions, 101 deletions
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 @@ | |||
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.DiffCursor; | ||
10 | import org.eclipse.viatra.solver.data.map.VersionedMapStore; | ||
11 | import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; | ||
12 | import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; | ||
13 | import org.eclipse.viatra.solver.data.map.tests.smoke.utils.TestPermuter; | ||
14 | import org.eclipse.viatra.solver.data.map.tests.support.MapTestEnvironment; | ||
15 | import org.junit.jupiter.api.Timeout; | ||
16 | import org.junit.jupiter.params.ParameterizedTest; | ||
17 | import org.junit.jupiter.params.provider.Arguments; | ||
18 | import org.junit.jupiter.params.provider.MethodSource; | ||
19 | |||
20 | public class DiffCursorSmokeTest { | ||
21 | public void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, int commitFrequency, | ||
22 | boolean evilHash) { | ||
23 | String[] values = MapTestEnvironment.prepareValues(maxValue); | ||
24 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | ||
25 | |||
26 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<Integer, String>(chp, values[0]); | ||
27 | iterativeRandomPutsAndCommitsThenDiffcursor(scenario, store, steps, maxKey, values, seed, commitFrequency); | ||
28 | } | ||
29 | |||
30 | void iterativeRandomPutsAndCommitsThenDiffcursor(String scenario, VersionedMapStore<Integer, String> store, | ||
31 | int steps, int maxKey, String[] values, int seed, int commitFrequency) { | ||
32 | // 1. build a map with versions | ||
33 | Random r = new Random(seed); | ||
34 | VersionedMapImpl<Integer, String> versioned = (VersionedMapImpl<Integer, String>) store.createMap(); | ||
35 | int largestCommit = -1; | ||
36 | |||
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 | try { | ||
42 | versioned.put(nextKey, nextValue); | ||
43 | } catch (Exception exception) { | ||
44 | exception.printStackTrace(); | ||
45 | fail(scenario + ":" + index + ": exception happened: " + exception); | ||
46 | } | ||
47 | if (index % commitFrequency == 0) { | ||
48 | long version = versioned.commit(); | ||
49 | largestCommit = (int) version; | ||
50 | } | ||
51 | if (index % 10000 == 0) | ||
52 | System.out.println(scenario + ":" + index + "/" + steps + " building finished"); | ||
53 | } | ||
54 | // 2. create a non-versioned map, | ||
55 | VersionedMapImpl<Integer, String> moving = (VersionedMapImpl<Integer, String>) store.createMap(); | ||
56 | Random r2 = new Random(seed + 1); | ||
57 | |||
58 | final int diffTravelFrequency = commitFrequency * 2; | ||
59 | for (int i = 0; i < steps; i++) { | ||
60 | int index = i + 1; | ||
61 | if (index % diffTravelFrequency == 0) { | ||
62 | // difftravel | ||
63 | long travelToVersion = r2.nextInt(largestCommit + 1); | ||
64 | DiffCursor<Integer, String> diffCursor = moving.getDiffCursor(travelToVersion); | ||
65 | moving.putAll(diffCursor); | ||
66 | |||
67 | } else { | ||
68 | // random puts | ||
69 | int nextKey = r2.nextInt(maxKey); | ||
70 | String nextValue = values[r2.nextInt(values.length)]; | ||
71 | try { | ||
72 | moving.put(nextKey, nextValue); | ||
73 | } catch (Exception exception) { | ||
74 | exception.printStackTrace(); | ||
75 | fail(scenario + ":" + index + ": exception happened: " + exception); | ||
76 | } | ||
77 | if (index % commitFrequency == 0) { | ||
78 | versioned.commit(); | ||
79 | } | ||
80 | if (index % 10000 == 0) | ||
81 | System.out.println(scenario + ":" + index + "/" + steps + " building finished"); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | } | ||
86 | |||
87 | @ParameterizedTest(name = "Mutable-Immutable Compare Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") | ||
88 | @MethodSource | ||
89 | @Timeout(value = 10) | ||
90 | void parametrizedSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, | ||
91 | boolean evilHash) { | ||
92 | runSmokeTest("SmokeMutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, | ||
93 | noKeys, noValues, commitFrequency, evilHash); | ||
94 | } | ||
95 | |||
96 | public static Stream<Arguments> parametrizedSmoke() { | ||
97 | return TestPermuter.permutationWithSize(new Object[] { 1000 }, new Object[] { 3, 32, 32 * 32 }, | ||
98 | new Object[] { 2, 3 }, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, | ||
99 | new Object[] { false, true }); | ||
100 | } | ||
101 | } | ||