diff options
author | 2021-08-11 03:08:16 +0200 | |
---|---|---|
committer | 2021-08-11 03:08:16 +0200 | |
commit | 5621aa7e911e548e42c7188a21ace2834e19a8bc (patch) | |
tree | ec8ec24414d34e685fafe389f6681cffa9727d04 /model-data | |
parent | getCursor renamed to getAll (diff) | |
download | refinery-5621aa7e911e548e42c7188a21ace2834e19a8bc.tar.gz refinery-5621aa7e911e548e42c7188a21ace2834e19a8bc.tar.zst refinery-5621aa7e911e548e42c7188a21ace2834e19a8bc.zip |
Fixed multithread test
Diffstat (limited to 'model-data')
2 files changed, 11 insertions, 8 deletions
diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/fuzz/MultiThreadFuzzTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/fuzz/MultiThreadFuzzTest.java index 1a213de3..c3a3e8ea 100644 --- a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/fuzz/MultiThreadFuzzTest.java +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/fuzz/MultiThreadFuzzTest.java | |||
@@ -76,7 +76,7 @@ class MultiThreadFuzzTest { | |||
76 | 76 | ||
77 | static Stream<Arguments> parametrizedFastFuzz() { | 77 | static Stream<Arguments> parametrizedFastFuzz() { |
78 | return FuzzTestUtils.permutationWithSize(new Object[] { FuzzTestUtils.FAST_STEP_COUNT }, new Object[] { 3, 32, 32 * 32 }, | 78 | return FuzzTestUtils.permutationWithSize(new Object[] { FuzzTestUtils.FAST_STEP_COUNT }, new Object[] { 3, 32, 32 * 32 }, |
79 | new Object[] { 2, 3 }, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, | 79 | new Object[] { 2, 3 }, new Object[] { 10, 100 }, new Object[] { 1, 2, 3 }, |
80 | new Object[] { false, true }); | 80 | new Object[] { false, true }); |
81 | } | 81 | } |
82 | 82 | ||
diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/fuzz/MultiThreadTestRunnable.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/fuzz/MultiThreadTestRunnable.java index c247a9e1..835ba41c 100644 --- a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/fuzz/MultiThreadTestRunnable.java +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/fuzz/MultiThreadTestRunnable.java | |||
@@ -1,11 +1,13 @@ | |||
1 | package org.eclipse.viatra.solver.data.map.tests.fuzz; | 1 | package org.eclipse.viatra.solver.data.map.tests.fuzz; |
2 | 2 | ||
3 | import java.util.ArrayList; | 3 | import java.util.ArrayList; |
4 | import java.util.Collections; | ||
4 | import java.util.HashMap; | 5 | import java.util.HashMap; |
5 | import java.util.LinkedList; | 6 | import java.util.LinkedList; |
6 | import java.util.List; | 7 | import java.util.List; |
7 | import java.util.Map; | 8 | import java.util.Map; |
8 | import java.util.Random; | 9 | import java.util.Random; |
10 | import java.util.Set; | ||
9 | 11 | ||
10 | import org.eclipse.viatra.solver.data.map.VersionedMapStore; | 12 | import org.eclipse.viatra.solver.data.map.VersionedMapStore; |
11 | import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; | 13 | import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; |
@@ -68,6 +70,7 @@ public class MultiThreadTestRunnable implements Runnable { | |||
68 | // 2. create a non-versioned | 70 | // 2. create a non-versioned |
69 | VersionedMapImpl<Integer, String> reference = (VersionedMapImpl<Integer, String>) store.createMap(); | 71 | VersionedMapImpl<Integer, String> reference = (VersionedMapImpl<Integer, String>) store.createMap(); |
70 | r = new Random(seed); | 72 | r = new Random(seed); |
73 | Random r2 = new Random(seed+1); | ||
71 | 74 | ||
72 | for (int i = 0; i < steps; i++) { | 75 | for (int i = 0; i < steps; i++) { |
73 | int index = i + 1; | 76 | int index = i + 1; |
@@ -80,19 +83,19 @@ public class MultiThreadTestRunnable implements Runnable { | |||
80 | logAndThrowError(scenario + ":" + index + ": exception happened: " + exception); | 83 | logAndThrowError(scenario + ":" + index + ": exception happened: " + exception); |
81 | } | 84 | } |
82 | // go back to an existing state and compare to the reference | 85 | // go back to an existing state and compare to the reference |
83 | if (index % (commitFrequency*2) == 0) { | 86 | if (index % (commitFrequency) == 0) { |
84 | versioned.restore(index2Version.get(i)); | 87 | versioned.restore(index2Version.get(i)); |
85 | MapTestEnvironment.compareTwoMaps(scenario + ":" + index, reference, versioned,errors); | 88 | MapTestEnvironment.compareTwoMaps(scenario + ":" + index, reference, versioned,errors); |
86 | 89 | ||
87 | // go back to a random state (probably created by another thread) | 90 | // go back to a random state (probably created by another thread) |
91 | List<Long> states = new ArrayList<>(store.getStates()); | ||
92 | Collections.shuffle(states, r2); | ||
93 | for(Long state : states.subList(0, Math.min(states.size(), 100))) { | ||
94 | versioned.restore(state); | ||
95 | } | ||
96 | versioned.restore(index2Version.get(i)); | ||
88 | } | 97 | } |
89 | 98 | ||
90 | else if(index % (commitFrequency*2) == commitFrequency) { | ||
91 | ArrayList<Long> states = new ArrayList<Long>(store.getStates()); | ||
92 | long selectedState = states.get(r.nextInt(states.size())); | ||
93 | versioned.restore(selectedState); | ||
94 | } | ||
95 | |||
96 | MapTestEnvironment.printStatus(scenario, index, steps, "comparison"); | 99 | MapTestEnvironment.printStatus(scenario, index, steps, "comparison"); |
97 | } | 100 | } |
98 | } | 101 | } |