diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2021-07-29 19:01:25 +0200 |
---|---|---|
committer | Kristóf Marussy <marussy@mit.bme.hu> | 2021-07-29 19:01:25 +0200 |
commit | 7f6a2528bf83f93e3d35eff228f7180e0181f4eb (patch) | |
tree | 068dc3454cc9f968162e5ae03cc8733f9011de72 /model-data/src/test/java/org/eclipse | |
parent | Refactoring based on Sonar reports (diff) | |
download | refinery-7f6a2528bf83f93e3d35eff228f7180e0181f4eb.tar.gz refinery-7f6a2528bf83f93e3d35eff228f7180e0181f4eb.tar.zst refinery-7f6a2528bf83f93e3d35eff228f7180e0181f4eb.zip |
Add new data structure for backend
Co-authored-by: Oszkár Semeráth <semerath@mit.bme.hu>
Diffstat (limited to 'model-data/src/test/java/org/eclipse')
9 files changed, 750 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 | } | ||
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 new file mode 100644 index 00000000..ef51d05e --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/DiffCursorSmokeTest.java | |||
@@ -0,0 +1,101 @@ | |||
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 | } | ||
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 new file mode 100644 index 00000000..ac5571b3 --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/MutableImmutableCompareSmokeTest.java | |||
@@ -0,0 +1,72 @@ | |||
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 MutableImmutableCompareSmokeTest { | ||
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> immutable = (VersionedMapImpl<Integer, String>) store.createMap(); | ||
27 | VersionedMapImpl<Integer, String> mutable = (VersionedMapImpl<Integer, String>) store.createMap(); | ||
28 | |||
29 | Random r = new Random(seed); | ||
30 | |||
31 | iterativeRandomPutsAndCommitsAndCompare(scenario, immutable, mutable, steps, maxKey, values, r, | ||
32 | commitFrequency); | ||
33 | } | ||
34 | |||
35 | void iterativeRandomPutsAndCommitsAndCompare(String scenario, VersionedMapImpl<Integer, String> immutable, | ||
36 | VersionedMapImpl<Integer, String> mutable, int steps, int maxKey, String[] values, Random r, | ||
37 | int commitFrequency) { | ||
38 | for (int i = 0; i < steps; i++) { | ||
39 | int index = i + 1; | ||
40 | int nextKey = r.nextInt(maxKey); | ||
41 | String nextValue = values[r.nextInt(values.length)]; | ||
42 | try { | ||
43 | immutable.put(nextKey, nextValue); | ||
44 | mutable.put(nextKey, nextValue); | ||
45 | } catch (Exception exception) { | ||
46 | exception.printStackTrace(); | ||
47 | fail(scenario + ":" + index + ": exception happened: " + exception); | ||
48 | } | ||
49 | if (index % commitFrequency == 0) { | ||
50 | immutable.commit(); | ||
51 | } | ||
52 | MapTestEnvironment.compareTwoMaps(scenario + ":" + index, immutable, mutable); | ||
53 | |||
54 | MapTestEnvironment.printStatus(scenario, index, steps, null); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | @ParameterizedTest(name = "Mutable-Immutable Compare Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") | ||
59 | @MethodSource | ||
60 | @Timeout(value = 10) | ||
61 | void parametrizedSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, | ||
62 | boolean evilHash) { | ||
63 | runSmokeTest("SmokeMutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, | ||
64 | noKeys, noValues, commitFrequency, evilHash); | ||
65 | } | ||
66 | |||
67 | public static Stream<Arguments> parametrizedSmoke() { | ||
68 | return TestPermuter.permutationWithSize(new Object[] { 1000 }, new Object[] { 3, 32, 32 * 32 }, | ||
69 | new Object[] { 2, 3 }, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, | ||
70 | new Object[] { false, true }); | ||
71 | } | ||
72 | } | ||
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 new file mode 100644 index 00000000..c24c220d --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/MutableSmokeTest.java | |||
@@ -0,0 +1,76 @@ | |||
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 MutableSmokeTest { | ||
20 | |||
21 | public void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, 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 | iterativeRandomPuts(scenario, steps, maxKey, values, e, r); | ||
32 | } | ||
33 | |||
34 | void iterativeRandomPuts(String scenario, int steps, int maxKey, String[] values, | ||
35 | MapTestEnvironment<Integer, String> e, Random r) { | ||
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 | } | ||
60 | } | ||
61 | |||
62 | @ParameterizedTest(name = "Mutable Smoke {index}/{0} Steps={1} Keys={2} Values={3} seed={4} evil-hash={5}") | ||
63 | @MethodSource | ||
64 | @Timeout(value = 10) | ||
65 | void parametrizedSmoke(int test, int steps, int noKeys, int noValues, int seed, boolean evilHash) { | ||
66 | runSmokeTest( | ||
67 | "SmokeS" + steps + "K" + noKeys + "V" + noValues + "s" + seed + "H" + (evilHash ? "Evil" : "Normal"), | ||
68 | seed, steps, noKeys, noValues, evilHash); | ||
69 | } | ||
70 | |||
71 | public static Stream<Arguments> parametrizedSmoke() { | ||
72 | return TestPermuter.permutationWithSize(new Object[] { 1000 }, | ||
73 | new Object[] { 3, 32, 32 * 32, 32 * 32 * 32 * 32 }, new Object[] { 2, 3 }, new Object[] { 1, 2, 3 }, | ||
74 | new Object[] { false, true }); | ||
75 | } | ||
76 | } | ||
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 new file mode 100644 index 00000000..4ca9b088 --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/fast/RestoreSmokeTest.java | |||
@@ -0,0 +1,92 @@ | |||
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.HashMap; | ||
6 | import java.util.Map; | ||
7 | import java.util.Random; | ||
8 | import java.util.stream.Stream; | ||
9 | |||
10 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
11 | import org.eclipse.viatra.solver.data.map.VersionedMapStore; | ||
12 | import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; | ||
13 | import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; | ||
14 | import org.eclipse.viatra.solver.data.map.tests.smoke.utils.TestPermuter; | ||
15 | import org.eclipse.viatra.solver.data.map.tests.support.MapTestEnvironment; | ||
16 | import org.junit.jupiter.api.Timeout; | ||
17 | import org.junit.jupiter.params.ParameterizedTest; | ||
18 | import org.junit.jupiter.params.provider.Arguments; | ||
19 | import org.junit.jupiter.params.provider.MethodSource; | ||
20 | |||
21 | public class RestoreSmokeTest { | ||
22 | public void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, int commitFrequency, | ||
23 | boolean evilHash) { | ||
24 | String[] values = MapTestEnvironment.prepareValues(maxValue); | ||
25 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | ||
26 | |||
27 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<Integer, String>(chp, values[0]); | ||
28 | |||
29 | iterativeRandomPutsAndCommitsThenRestore(scenario, store, steps, maxKey, values, seed, commitFrequency); | ||
30 | } | ||
31 | |||
32 | void iterativeRandomPutsAndCommitsThenRestore(String scenario, VersionedMapStore<Integer, String> store, int steps, | ||
33 | int maxKey, String[] values, int seed, int commitFrequency) { | ||
34 | // 1. build a map with versions | ||
35 | Random r = new Random(seed); | ||
36 | VersionedMapImpl<Integer, String> versioned = (VersionedMapImpl<Integer, String>) store.createMap(); | ||
37 | Map<Integer, Long> index2Version = new HashMap<>(); | ||
38 | |||
39 | for (int i = 0; i < steps; i++) { | ||
40 | int index = i + 1; | ||
41 | int nextKey = r.nextInt(maxKey); | ||
42 | String nextValue = values[r.nextInt(values.length)]; | ||
43 | try { | ||
44 | versioned.put(nextKey, nextValue); | ||
45 | } catch (Exception exception) { | ||
46 | exception.printStackTrace(); | ||
47 | fail(scenario + ":" + index + ": exception happened: " + exception); | ||
48 | } | ||
49 | if (index % commitFrequency == 0) { | ||
50 | long version = versioned.commit(); | ||
51 | index2Version.put(i, version); | ||
52 | } | ||
53 | MapTestEnvironment.printStatus(scenario, index, steps, "building"); | ||
54 | } | ||
55 | // 2. create a non-versioned and | ||
56 | VersionedMapImpl<Integer, String> reference = (VersionedMapImpl<Integer, String>) store.createMap(); | ||
57 | r = new Random(seed); | ||
58 | |||
59 | for (int i = 0; i < steps; i++) { | ||
60 | int index = i + 1; | ||
61 | int nextKey = r.nextInt(maxKey); | ||
62 | String nextValue = values[r.nextInt(values.length)]; | ||
63 | try { | ||
64 | reference.put(nextKey, nextValue); | ||
65 | } catch (Exception exception) { | ||
66 | exception.printStackTrace(); | ||
67 | fail(scenario + ":" + index + ": exception happened: " + exception); | ||
68 | } | ||
69 | if (index % commitFrequency == 0) { | ||
70 | versioned.restore(index2Version.get(i)); | ||
71 | MapTestEnvironment.compareTwoMaps(scenario + ":" + index, reference, versioned); | ||
72 | } | ||
73 | MapTestEnvironment.printStatus(scenario, index, steps, "comparison"); | ||
74 | } | ||
75 | |||
76 | } | ||
77 | |||
78 | @ParameterizedTest(name = "Mutable-Immutable Compare Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") | ||
79 | @MethodSource | ||
80 | @Timeout(value = 10) | ||
81 | void parametrizedSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, | ||
82 | boolean evilHash) { | ||
83 | runSmokeTest("SmokeMutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, | ||
84 | noKeys, noValues, commitFrequency, evilHash); | ||
85 | } | ||
86 | |||
87 | public static Stream<Arguments> parametrizedSmoke() { | ||
88 | return TestPermuter.permutationWithSize(new Object[] { 1000 }, new Object[] { 3, 32, 32 * 32 }, | ||
89 | new Object[] { 2, 3 }, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, | ||
90 | new Object[] { false, true }); | ||
91 | } | ||
92 | } | ||
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 new file mode 100644 index 00000000..004d30d9 --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/slow/SlowSmokeTest.java | |||
@@ -0,0 +1,77 @@ | |||
1 | package org.eclipse.viatra.solver.data.map.tests.smoke.slow; | ||
2 | |||
3 | import java.util.Arrays; | ||
4 | import java.util.stream.Stream; | ||
5 | |||
6 | import org.eclipse.viatra.solver.data.map.tests.smoke.fast.CommitSmokeTest; | ||
7 | import org.eclipse.viatra.solver.data.map.tests.smoke.fast.MutableImmutableCompareSmokeTest; | ||
8 | import org.eclipse.viatra.solver.data.map.tests.smoke.fast.MutableSmokeTest; | ||
9 | import org.eclipse.viatra.solver.data.map.tests.smoke.fast.RestoreSmokeTest; | ||
10 | import org.junit.jupiter.api.Disabled; | ||
11 | import org.junit.jupiter.params.ParameterizedTest; | ||
12 | import org.junit.jupiter.params.provider.Arguments; | ||
13 | import org.junit.jupiter.params.provider.MethodSource; | ||
14 | |||
15 | @Disabled | ||
16 | public class SlowSmokeTest { | ||
17 | |||
18 | private static int slowStepCount = 32 * 32 * 32 * 32; | ||
19 | |||
20 | private static Stream<Arguments> changeStepCount(Stream<Arguments> arguments) { | ||
21 | return arguments.map(x -> Arguments.of(updatedStepCount(x.get()))); | ||
22 | |||
23 | } | ||
24 | |||
25 | private static Object[] updatedStepCount(Object[] arguments) { | ||
26 | Object[] copy = Arrays.copyOf(arguments, arguments.length); | ||
27 | copy[1] = slowStepCount; | ||
28 | return copy; | ||
29 | } | ||
30 | |||
31 | @ParameterizedTest(name = "Mutable Smoke {index}/{0} Steps={1} Keys={2} Values={3} seed={4} evil-hash={5}") | ||
32 | @MethodSource | ||
33 | void smoke1(int test, int steps, int noKeys, int noValues, int seed, boolean evilHash) { | ||
34 | (new MutableSmokeTest()).runSmokeTest( | ||
35 | "SmokeS" + steps + "K" + noKeys + "V" + noValues + "s" + seed + "H" + (evilHash ? "Evil" : "Normal"), | ||
36 | seed, steps, noKeys, noValues, evilHash); | ||
37 | } | ||
38 | |||
39 | private static Stream<Arguments> smoke1() { | ||
40 | return changeStepCount(MutableSmokeTest.parametrizedSmoke()); | ||
41 | } | ||
42 | |||
43 | @ParameterizedTest(name = "Immutable Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") | ||
44 | @MethodSource | ||
45 | void smoke2(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, boolean evilHash) { | ||
46 | (new CommitSmokeTest()).runSmokeTest("SmokeCommitS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, | ||
47 | steps, noKeys, noValues, commitFrequency, evilHash); | ||
48 | } | ||
49 | |||
50 | private static Stream<Arguments> smoke2() { | ||
51 | return changeStepCount(CommitSmokeTest.parametrizedSmoke()); | ||
52 | } | ||
53 | |||
54 | @ParameterizedTest(name = "Mutable-Immutable Compare Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") | ||
55 | @MethodSource | ||
56 | void smoke3(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, boolean evilHash) { | ||
57 | (new MutableImmutableCompareSmokeTest()).runSmokeTest( | ||
58 | "SmokeMutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, | ||
59 | noKeys, noValues, commitFrequency, evilHash); | ||
60 | } | ||
61 | |||
62 | private static Stream<Arguments> smoke3() { | ||
63 | return changeStepCount(MutableImmutableCompareSmokeTest.parametrizedSmoke()); | ||
64 | } | ||
65 | |||
66 | @ParameterizedTest(name = "Mutable-Immutable Compare Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") | ||
67 | @MethodSource | ||
68 | void smoke4(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, boolean evilHash) { | ||
69 | (new RestoreSmokeTest()).runSmokeTest( | ||
70 | "SmokeMutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, | ||
71 | noKeys, noValues, commitFrequency, evilHash); | ||
72 | } | ||
73 | |||
74 | private static Stream<Arguments> smoke4() { | ||
75 | return changeStepCount(RestoreSmokeTest.parametrizedSmoke()); | ||
76 | } | ||
77 | } | ||
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 new file mode 100644 index 00000000..0f7b4642 --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuter.java | |||
@@ -0,0 +1,46 @@ | |||
1 | package org.eclipse.viatra.solver.data.map.tests.smoke.utils; | ||
2 | |||
3 | import java.util.LinkedList; | ||
4 | import java.util.List; | ||
5 | import java.util.stream.Stream; | ||
6 | |||
7 | import org.junit.jupiter.params.provider.Arguments; | ||
8 | |||
9 | public class TestPermuter { | ||
10 | static List<List<Object>> permutationInternal(int from, Object[]... valueOption) { | ||
11 | if (valueOption.length == from) { | ||
12 | return List.of(List.of()); | ||
13 | } else { | ||
14 | Object[] permuteThis = valueOption[from]; | ||
15 | List<List<Object>> otherCombination = permutationInternal(from + 1, valueOption); | ||
16 | List<List<Object>> result = new LinkedList<>(); | ||
17 | for (Object permuteThisElement : permuteThis) { | ||
18 | for (List<Object> otherCombinationList : otherCombination) { | ||
19 | List<Object> newResult = new LinkedList<>(); | ||
20 | newResult.add(permuteThisElement); | ||
21 | newResult.addAll(otherCombinationList); | ||
22 | result.add(newResult); | ||
23 | } | ||
24 | } | ||
25 | return result; | ||
26 | } | ||
27 | } | ||
28 | |||
29 | public static Stream<Arguments> permutation(Object[]... valueOption) { | ||
30 | List<List<Object>> permutations = permutationInternal(0, valueOption); | ||
31 | return permutations.stream().map(x -> Arguments.of(x.toArray())); | ||
32 | } | ||
33 | |||
34 | public static Stream<Arguments> permutationWithSize(Object[]... valueOption) { | ||
35 | int size = 1; | ||
36 | for (int i = 0; i < valueOption.length; i++) { | ||
37 | size *= valueOption[i].length; | ||
38 | } | ||
39 | Object[][] newValueOption = new Object[valueOption.length + 1][]; | ||
40 | newValueOption[0] = new Object[] { size }; | ||
41 | for (int i = 1; i < newValueOption.length; i++) { | ||
42 | newValueOption[i] = valueOption[i - 1]; | ||
43 | } | ||
44 | return permutation(newValueOption); | ||
45 | } | ||
46 | } | ||
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 new file mode 100644 index 00000000..91f1c2e0 --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuterTest.java | |||
@@ -0,0 +1,33 @@ | |||
1 | package org.eclipse.viatra.solver.data.map.tests.smoke.utils; | ||
2 | |||
3 | import static org.junit.jupiter.api.Assertions.assertEquals; | ||
4 | |||
5 | import java.util.List; | ||
6 | |||
7 | import org.junit.jupiter.api.Test; | ||
8 | |||
9 | class TestPermuterTest { | ||
10 | @Test | ||
11 | void permutationInternalTest() { | ||
12 | List<List<Object>> res = TestPermuter.permutationInternal(0, new Object[] { 1, 2, 3 }, | ||
13 | new Object[] { 'a', 'b', 'c' }, new Object[] { "alpha", "beta", "gamma", "delta" }); | ||
14 | assertEquals(3 * 3 * 4, res.size()); | ||
15 | } | ||
16 | |||
17 | @Test | ||
18 | void permutationTest1() { | ||
19 | var res = TestPermuter.permutation(new Object[] { 1, 2, 3 }, new Object[] { 'a', 'b', 'c' }, | ||
20 | new Object[] { "alpha", "beta", "gamma", "delta" }); | ||
21 | assertEquals(3 * 3 * 4, res.count()); | ||
22 | } | ||
23 | |||
24 | @Test | ||
25 | void permutationTest2() { | ||
26 | var res = TestPermuter.permutation(new Object[] { 1, 2, 3 }, new Object[] { 'a', 'b', 'c' }, | ||
27 | new Object[] { "alpha", "beta", "gamma", "delta" }); | ||
28 | var arguments = res.findFirst().get().get(); | ||
29 | assertEquals(1, arguments[0]); | ||
30 | assertEquals('a', arguments[1]); | ||
31 | assertEquals("alpha", arguments[2]); | ||
32 | } | ||
33 | } | ||
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 new file mode 100644 index 00000000..6c55be62 --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/support/MapTestEnvironment.java | |||
@@ -0,0 +1,174 @@ | |||
1 | package org.eclipse.viatra.solver.data.map.tests.support; | ||
2 | |||
3 | import static org.junit.jupiter.api.Assertions.assertEquals; | ||
4 | import static org.junit.jupiter.api.Assertions.fail; | ||
5 | |||
6 | import java.util.HashMap; | ||
7 | import java.util.Iterator; | ||
8 | import java.util.Map; | ||
9 | import java.util.Map.Entry; | ||
10 | import java.util.TreeMap; | ||
11 | |||
12 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
13 | import org.eclipse.viatra.solver.data.map.Cursor; | ||
14 | import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; | ||
15 | |||
16 | public class MapTestEnvironment<KEY, VALUE> { | ||
17 | public static String[] prepareValues(int maxValue) { | ||
18 | String[] values = new String[maxValue]; | ||
19 | values[0] = "DEFAULT"; | ||
20 | for (int i = 1; i < values.length; i++) { | ||
21 | values[i] = "VAL" + i; | ||
22 | } | ||
23 | return values; | ||
24 | } | ||
25 | |||
26 | public static ContinousHashProvider<Integer> prepareHashProvider(final boolean evil) { | ||
27 | // Use maxPrime = 2147483629 | ||
28 | |||
29 | ContinousHashProvider<Integer> chp = new ContinousHashProvider<Integer>() { | ||
30 | |||
31 | @Override | ||
32 | public int getHash(Integer key, int index) { | ||
33 | if (evil && index < 15 && index < key / 3) { | ||
34 | return 7; | ||
35 | } | ||
36 | int result = 1; | ||
37 | final int prime = 31; | ||
38 | |||
39 | result = prime * result + key; | ||
40 | result = prime * result + index; | ||
41 | |||
42 | return result; | ||
43 | } | ||
44 | }; | ||
45 | return chp; | ||
46 | } | ||
47 | |||
48 | public static void printStatus(String scenario, int actual, int max, String stepName) { | ||
49 | if (actual % 10000 == 0) { | ||
50 | String printStepName = stepName == null ? "" : stepName; | ||
51 | System.out.format(scenario + ":%d/%d (%d%%) " + printStepName + "%n", actual, max, actual * 100 / max); | ||
52 | } | ||
53 | |||
54 | } | ||
55 | |||
56 | public static <KEY, VALUE> void compareTwoMaps(String title, VersionedMapImpl<KEY, VALUE> map1, | ||
57 | VersionedMapImpl<KEY, VALUE> map2) { | ||
58 | // 1. Comparing cursors. | ||
59 | Cursor<KEY, VALUE> cursor1 = map1.getCursor(); | ||
60 | Cursor<KEY, VALUE> cursor2 = map2.getCursor(); | ||
61 | while (!cursor1.isTerminated()) { | ||
62 | if (cursor2.isTerminated()) { | ||
63 | fail("cursor 2 terminated before cursor1"); | ||
64 | } | ||
65 | assertEquals(cursor1.getKey(), cursor2.getKey()); | ||
66 | assertEquals(cursor2.getValue(), cursor2.getValue()); | ||
67 | cursor1.move(); | ||
68 | cursor2.move(); | ||
69 | } | ||
70 | if (!cursor2.isTerminated()) | ||
71 | fail("cursor 1 terminated before cursor 2"); | ||
72 | |||
73 | // 2.1. comparing hash codes | ||
74 | assertEquals(map1.hashCode(), map2.hashCode(), title + ": hash code check"); | ||
75 | assertEquals(map1, map2, title + ": 1.equals(2)"); | ||
76 | assertEquals(map2, map1, title + ": 2.equals(1)"); | ||
77 | } | ||
78 | |||
79 | public VersionedMapImpl<KEY, VALUE> sut; | ||
80 | Map<KEY, VALUE> oracle = new HashMap<KEY, VALUE>(); | ||
81 | |||
82 | public MapTestEnvironment(VersionedMapImpl<KEY, VALUE> sut) { | ||
83 | this.sut = sut; | ||
84 | } | ||
85 | |||
86 | public void put(KEY key, VALUE value) { | ||
87 | sut.put(key, value); | ||
88 | if (value != sut.getDefaultValue()) { | ||
89 | oracle.put(key, value); | ||
90 | } else { | ||
91 | oracle.remove(key); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | public void checkEquivalence(String title) { | ||
96 | // 0. Checking integrity | ||
97 | try { | ||
98 | sut.checkIntegrity(); | ||
99 | } catch (IllegalStateException e) { | ||
100 | fail(title + ": " + e.getMessage()); | ||
101 | } | ||
102 | |||
103 | // 1. Checking: if Reference contains <key,value> pair, then SUT contains | ||
104 | // <key,value> pair. | ||
105 | // Tests get functions | ||
106 | for (Entry<KEY, VALUE> entry : oracle.entrySet()) { | ||
107 | VALUE sutValue = sut.get(entry.getKey()); | ||
108 | VALUE oracleValue = entry.getValue(); | ||
109 | if (sutValue != oracleValue) { | ||
110 | printComparison(); | ||
111 | fail(title + ": Non-equivalent get(" + entry.getKey() + ") results: SUT=" + sutValue + ", Oracle=" | ||
112 | + oracleValue + "!"); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | // 2. Checking: if SUT contains <key,value> pair, then Reference contains | ||
117 | // <key,value> pair. | ||
118 | // Tests iterators | ||
119 | // TODO: Counts the number of elements in the entryset | ||
120 | int elementsInSutEntrySet = 0; | ||
121 | Cursor<KEY, VALUE> cursor = sut.getCursor(); | ||
122 | while (cursor.move()) { | ||
123 | elementsInSutEntrySet++; | ||
124 | KEY key = cursor.getKey(); | ||
125 | VALUE sutValue = cursor.getValue(); | ||
126 | // System.out.println(key + " -> " + sutValue); | ||
127 | VALUE oracleValue = oracle.get(key); | ||
128 | if (sutValue != oracleValue) { | ||
129 | printComparison(); | ||
130 | fail(title + ": Non-equivalent entry in iterator: SUT=<" + key + "," + sutValue + ">, Oracle=<" + key | ||
131 | + "," + oracleValue + ">!"); | ||
132 | } | ||
133 | |||
134 | } | ||
135 | |||
136 | // 3. Checking sizes | ||
137 | // Counting of non-default value pairs. | ||
138 | int oracleSize = oracle.entrySet().size(); | ||
139 | long sutSize = sut.getSize(); | ||
140 | if (oracleSize != sutSize || oracleSize != elementsInSutEntrySet) { | ||
141 | printComparison(); | ||
142 | fail(title + ": Non-eqivalent size() result: SUT.getSize()=" + sutSize + ", SUT.entryset.size=" | ||
143 | + elementsInSutEntrySet + ", Oracle=" + oracleSize + "!"); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | public void printComparison() { | ||
148 | System.out.println("SUT:"); | ||
149 | printEntrySet(sut.getCursor()); | ||
150 | System.out.println("Oracle:"); | ||
151 | printEntrySet(oracle.entrySet().iterator()); | ||
152 | } | ||
153 | |||
154 | private void printEntrySet(Iterator<Entry<KEY, VALUE>> iterator) { | ||
155 | TreeMap<KEY, VALUE> treemap = new TreeMap<>(); | ||
156 | while (iterator.hasNext()) { | ||
157 | Entry<KEY, VALUE> entry = iterator.next(); | ||
158 | treemap.put(entry.getKey(), entry.getValue()); | ||
159 | } | ||
160 | for (Entry<KEY, VALUE> e : treemap.entrySet()) { | ||
161 | System.out.println("\t" + e.getKey() + " -> " + e.getValue()); | ||
162 | } | ||
163 | } | ||
164 | |||
165 | private void printEntrySet(Cursor<KEY, VALUE> cursor) { | ||
166 | TreeMap<KEY, VALUE> treemap = new TreeMap<>(); | ||
167 | while (cursor.move()) { | ||
168 | treemap.put(cursor.getKey(), cursor.getValue()); | ||
169 | } | ||
170 | for (Entry<KEY, VALUE> e : treemap.entrySet()) { | ||
171 | System.out.println("\t" + e.getKey() + " -> " + e.getValue()); | ||
172 | } | ||
173 | } | ||
174 | } | ||