diff options
author | 2021-07-26 15:01:23 +0200 | |
---|---|---|
committer | 2021-07-26 15:01:23 +0200 | |
commit | 1527e27f36762a5e3a1cdbb84467f67322cb7cba (patch) | |
tree | c076fb8117180a15989535743bd3bab32db01c71 /Solvers/VIATRA-Solver/org.eclipse.viatra.solver.data/tests/org/eclipse/viatra/solver/data/map/test/smoke/fast/SmokeTest2Commit.java | |
parent | better progress logging in smoke tests (diff) | |
download | VIATRA-Generator-1527e27f36762a5e3a1cdbb84467f67322cb7cba.tar.gz VIATRA-Generator-1527e27f36762a5e3a1cdbb84467f67322cb7cba.tar.zst VIATRA-Generator-1527e27f36762a5e3a1cdbb84467f67322cb7cba.zip |
Smoketest refactor splitting fast and slow smoke tests
Diffstat (limited to 'Solvers/VIATRA-Solver/org.eclipse.viatra.solver.data/tests/org/eclipse/viatra/solver/data/map/test/smoke/fast/SmokeTest2Commit.java')
-rw-r--r-- | Solvers/VIATRA-Solver/org.eclipse.viatra.solver.data/tests/org/eclipse/viatra/solver/data/map/test/smoke/fast/SmokeTest2Commit.java | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/org.eclipse.viatra.solver.data/tests/org/eclipse/viatra/solver/data/map/test/smoke/fast/SmokeTest2Commit.java b/Solvers/VIATRA-Solver/org.eclipse.viatra.solver.data/tests/org/eclipse/viatra/solver/data/map/test/smoke/fast/SmokeTest2Commit.java new file mode 100644 index 00000000..18cb9f58 --- /dev/null +++ b/Solvers/VIATRA-Solver/org.eclipse.viatra.solver.data/tests/org/eclipse/viatra/solver/data/map/test/smoke/fast/SmokeTest2Commit.java | |||
@@ -0,0 +1,88 @@ | |||
1 | package org.eclipse.viatra.solver.data.map.test.smoke.fast; | ||
2 | |||
3 | import static org.junit.Assert.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.test.smoke.TestPermuter; | ||
13 | import org.eclipse.viatra.solver.data.map.test.support.MapTestEnvironment; | ||
14 | import org.junit.jupiter.params.ParameterizedTest; | ||
15 | import org.junit.jupiter.params.provider.Arguments; | ||
16 | import org.junit.jupiter.params.provider.MethodSource; | ||
17 | |||
18 | public class SmokeTest2Commit { | ||
19 | public void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, int commitFrequency, boolean evilHash) { | ||
20 | String[] values = MapTestEnvironment.prepareValues(maxValue); | ||
21 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | ||
22 | |||
23 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<Integer, String>(chp, values[0]); | ||
24 | VersionedMapImpl<Integer, String> sut = (VersionedMapImpl<Integer, String>) store.createMap(); | ||
25 | MapTestEnvironment<Integer, String> e = new MapTestEnvironment<Integer, String>(sut); | ||
26 | |||
27 | Random r = new Random(seed); | ||
28 | |||
29 | iterativeRandomPutsAndCommits(scenario, steps, maxKey, values, e, r, commitFrequency); | ||
30 | } | ||
31 | |||
32 | void iterativeRandomPutsAndCommits( | ||
33 | String scenario, | ||
34 | int steps, | ||
35 | int maxKey, | ||
36 | String[] values, | ||
37 | MapTestEnvironment<Integer, String> e, | ||
38 | Random r, | ||
39 | int commitFrequency) | ||
40 | { | ||
41 | int stopAt = -1; | ||
42 | for(int i=0; i<steps; i++) { | ||
43 | int index = i+1; | ||
44 | int nextKey = r.nextInt(maxKey); | ||
45 | String nextValue = values[r.nextInt(values.length)]; | ||
46 | if(index == stopAt) { | ||
47 | System.out.println("issue!"); | ||
48 | System.out.println("State before:"); | ||
49 | e.printComparison(); | ||
50 | e.sut.prettyPrint(); | ||
51 | System.out.println("Next: put("+nextKey+","+nextValue+")"); | ||
52 | } | ||
53 | try { | ||
54 | e.put(nextKey, nextValue); | ||
55 | if(index == stopAt) { | ||
56 | e.sut.prettyPrint(); | ||
57 | } | ||
58 | e.checkEquivalence(scenario+":"+index); | ||
59 | } catch (Exception exception) { | ||
60 | exception.printStackTrace(); | ||
61 | fail(scenario+":"+index+": exception happened: "+exception); | ||
62 | } | ||
63 | if(index%10000==0) System.out.println(scenario+":"+index+"/"+steps+" finished"); | ||
64 | if(index%commitFrequency == 0) { | ||
65 | e.sut.commit(); | ||
66 | //System.out.println(scenario+":"+index+": Commit! version=" + version); | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | |||
71 | |||
72 | @ParameterizedTest(name = "Immutable Smoke {index}/{0} Steps={1} Keys={2} Values={3} commit frequency={4} seed={5} evil-hash={6}") | ||
73 | @MethodSource | ||
74 | void parametrizedSmoke(int tests, int steps, int noKeys, int noValues, int commitFrequency, int seed, boolean evilHash) { | ||
75 | runSmokeTest("SmokeCommitS"+steps+"K"+noKeys+"V"+noValues+"s"+seed,seed,steps,noKeys,noValues,commitFrequency,evilHash); | ||
76 | } | ||
77 | |||
78 | public static Stream<Arguments> parametrizedSmoke(){ | ||
79 | return TestPermuter.permutationWithSize( | ||
80 | new Object[] {1000}, | ||
81 | new Object[] {3,32, 32*32}, | ||
82 | new Object[] {2,3}, | ||
83 | new Object[] {1,10,100}, | ||
84 | new Object[] {1,2,3}, | ||
85 | new Object[] {false,true} | ||
86 | ); | ||
87 | } | ||
88 | } | ||