diff options
author | Oszkar Semerath <Oszkar Semerath@DESKTOP-DNR7JQ7> | 2021-07-14 00:42:41 +0200 |
---|---|---|
committer | Oszkar Semerath <Oszkar Semerath@DESKTOP-DNR7JQ7> | 2021-07-14 00:42:41 +0200 |
commit | c20ba5e78c2931a7de9928035bc6a80f22d0a2b6 (patch) | |
tree | f8f7ccfbc82734a5a5314471fd86c288e8221ce8 /Solvers | |
parent | Merged nodes in cache (diff) | |
download | VIATRA-Generator-c20ba5e78c2931a7de9928035bc6a80f22d0a2b6.tar.gz VIATRA-Generator-c20ba5e78c2931a7de9928035bc6a80f22d0a2b6.tar.zst VIATRA-Generator-c20ba5e78c2931a7de9928035bc6a80f22d0a2b6.zip |
npe fix
Diffstat (limited to 'Solvers')
-rw-r--r-- | Solvers/VIATRA-Solver/org.eclipse.viatra.solver.data/tests/org/eclipse/viatra/solver/data/map/SmokeTest3CompareMutableWithImmutable.java | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/org.eclipse.viatra.solver.data/tests/org/eclipse/viatra/solver/data/map/SmokeTest3CompareMutableWithImmutable.java b/Solvers/VIATRA-Solver/org.eclipse.viatra.solver.data/tests/org/eclipse/viatra/solver/data/map/SmokeTest3CompareMutableWithImmutable.java new file mode 100644 index 00000000..fecf3cc7 --- /dev/null +++ b/Solvers/VIATRA-Solver/org.eclipse.viatra.solver.data/tests/org/eclipse/viatra/solver/data/map/SmokeTest3CompareMutableWithImmutable.java | |||
@@ -0,0 +1,131 @@ | |||
1 | package org.eclipse.viatra.solver.data.map; | ||
2 | |||
3 | import static org.junit.Assert.fail; | ||
4 | |||
5 | import java.util.Random; | ||
6 | |||
7 | import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; | ||
8 | import org.junit.jupiter.api.Test; | ||
9 | |||
10 | public class SmokeTest3CompareMutableWithImmutable { | ||
11 | private void runSmokeTest(String scenario, int seed, int steps, int maxKey, int maxValue, int commitFrequency) { | ||
12 | String[] values = prepareValues(maxValue); | ||
13 | ContinousHashProvider<Integer> chp = prepareHashProvider(); | ||
14 | |||
15 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<Integer, String>(chp, values[0]); | ||
16 | VersionedMapImpl<Integer, String> sut = (VersionedMapImpl<Integer, String>) store.createMap(); | ||
17 | MapTestEnvironment<Integer, String> e = new MapTestEnvironment<Integer, String>(sut); | ||
18 | |||
19 | Random r = new Random(seed); | ||
20 | |||
21 | iterativeRandomPutsAndCommits(scenario, steps, maxKey, values, e, r, commitFrequency); | ||
22 | } | ||
23 | |||
24 | private String[] prepareValues(int maxValue) { | ||
25 | String[] values = new String[maxValue]; | ||
26 | values[0] = "DEFAULT"; | ||
27 | for(int i = 1; i<values.length; i++) { | ||
28 | values[i] = "VAL"+i; | ||
29 | } | ||
30 | return values; | ||
31 | } | ||
32 | private ContinousHashProvider<Integer> prepareHashProvider() { | ||
33 | ContinousHashProvider<Integer> chp = new ContinousHashProvider<Integer>() { | ||
34 | |||
35 | @Override | ||
36 | public int getHash(Integer key, int index) { | ||
37 | int result = 1; | ||
38 | final int prime = 31; | ||
39 | result = prime*result + key; | ||
40 | result = prime*result + index; | ||
41 | return result; | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | public boolean equals(Integer key1, Integer key2) { | ||
46 | return key1.equals(key2); | ||
47 | } | ||
48 | }; | ||
49 | return chp; | ||
50 | } | ||
51 | |||
52 | void iterativeRandomPutsAndCommits( | ||
53 | String scenario, | ||
54 | int steps, | ||
55 | int maxKey, | ||
56 | String[] values, | ||
57 | MapTestEnvironment<Integer, String> e, | ||
58 | Random r, | ||
59 | int commitFrequency) | ||
60 | { | ||
61 | int stopAt = -1; | ||
62 | for(int i=0; i<steps; i++) { | ||
63 | int index = i+1; | ||
64 | int nextKey = r.nextInt(maxKey); | ||
65 | String nextValue = values[r.nextInt(values.length)]; | ||
66 | if(index == stopAt) { | ||
67 | System.out.println("issue!"); | ||
68 | System.out.println("State before:"); | ||
69 | e.printComparison(); | ||
70 | e.sut.prettyPrint(); | ||
71 | System.out.println("Next: put("+nextKey+","+nextValue+")"); | ||
72 | } | ||
73 | try { | ||
74 | e.put(nextKey, nextValue); | ||
75 | if(index == stopAt) { | ||
76 | e.sut.prettyPrint(); | ||
77 | } | ||
78 | e.checkEquivalence(scenario+":"+index); | ||
79 | } catch (Exception exception) { | ||
80 | exception.printStackTrace(); | ||
81 | fail(scenario+":"+index+": exception happened: "+exception); | ||
82 | } | ||
83 | if(index%10000==0) System.out.println(scenario+":"+index+" finished"); | ||
84 | if(index%commitFrequency == 0) { | ||
85 | long version = e.sut.commit(); | ||
86 | System.out.println(scenario+":"+index+": Commit! " + version); | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | |||
91 | @Test | ||
92 | void MiniSmokeK3V2v1() { | ||
93 | runSmokeTest("MiniSmokeK3V2v1",0, 1000, 3, 2, 10); | ||
94 | } | ||
95 | @Test | ||
96 | void MiniSmokeK3V2v2() { | ||
97 | runSmokeTest("MiniSmokeK3V2v2",1, 1000, 3, 2, 10); | ||
98 | } | ||
99 | @Test | ||
100 | void MiniSmokeK3V2v3() { | ||
101 | runSmokeTest("MiniSmokeK3V2v3",3, 1000, 3, 2, 10); | ||
102 | } | ||
103 | @Test | ||
104 | void MiniSmokeK3V3v1() { | ||
105 | runSmokeTest("MiniSmokeK3V2v1",0, 1000, 3, 3, 10); | ||
106 | } | ||
107 | @Test | ||
108 | void MiniSmokeK3V3v2() { | ||
109 | runSmokeTest("MiniSmokeK3V2v2",1, 1000, 3, 3, 10); | ||
110 | } | ||
111 | @Test | ||
112 | void MiniSmokeK3V3v3() { | ||
113 | runSmokeTest("MiniSmokeK3V2v3",3, 1000, 3, 3, 10); | ||
114 | } | ||
115 | @Test | ||
116 | void MediumSmokeK3V2v1() { | ||
117 | runSmokeTest("MediumSmokeK3V2v1",1, 1000, 32, 2, 10); | ||
118 | } | ||
119 | @Test | ||
120 | void MediumSmokeK3V2v2() { | ||
121 | runSmokeTest("MediumSmokeK3V2v2",2, 1000, 32, 2, 10); | ||
122 | } | ||
123 | @Test | ||
124 | void MediumSmokeK3V2v3() { | ||
125 | runSmokeTest("MediumSmokeK3V2v3",3, 1000, 32, 2, 10); | ||
126 | } | ||
127 | // @Test | ||
128 | // void SmokeLarge() { | ||
129 | // runSmokeTest("SmokeLarge",0, 32*32*32*32, 32*32-1, 2); | ||
130 | // } | ||
131 | } | ||