diff options
Diffstat (limited to 'subprojects/store/src/test/java')
7 files changed, 40 insertions, 27 deletions
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/DiffCursorFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/DiffCursorFuzzTest.java index 5a4f8038..94259edc 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/DiffCursorFuzzTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/DiffCursorFuzzTest.java | |||
@@ -10,13 +10,12 @@ import org.junit.jupiter.api.Timeout; | |||
10 | import org.junit.jupiter.params.ParameterizedTest; | 10 | import org.junit.jupiter.params.ParameterizedTest; |
11 | import org.junit.jupiter.params.provider.Arguments; | 11 | import org.junit.jupiter.params.provider.Arguments; |
12 | import org.junit.jupiter.params.provider.MethodSource; | 12 | import org.junit.jupiter.params.provider.MethodSource; |
13 | import tools.refinery.store.map.DiffCursor; | 13 | import tools.refinery.store.map.*; |
14 | import tools.refinery.store.map.VersionedMap; | ||
15 | import tools.refinery.store.map.VersionedMapStore; | ||
16 | import tools.refinery.store.map.VersionedMapStoreFactoryBuilder; | ||
17 | import tools.refinery.store.map.tests.fuzz.utils.FuzzTestUtils; | 14 | import tools.refinery.store.map.tests.fuzz.utils.FuzzTestUtils; |
18 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; | 15 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; |
19 | 16 | ||
17 | import java.util.HashMap; | ||
18 | import java.util.Map; | ||
20 | import java.util.Random; | 19 | import java.util.Random; |
21 | import java.util.stream.Stream; | 20 | import java.util.stream.Stream; |
22 | 21 | ||
@@ -39,6 +38,7 @@ class DiffCursorFuzzTest { | |||
39 | int commitFrequency, boolean commitBeforeDiffCursor) { | 38 | int commitFrequency, boolean commitBeforeDiffCursor) { |
40 | 39 | ||
41 | int largestCommit = -1; | 40 | int largestCommit = -1; |
41 | Map<Integer,Version> index2Version = new HashMap<>(); | ||
42 | 42 | ||
43 | { | 43 | { |
44 | // 1. build a map with versions | 44 | // 1. build a map with versions |
@@ -55,8 +55,9 @@ class DiffCursorFuzzTest { | |||
55 | fail(scenario + ":" + index + ": exception happened: " + exception); | 55 | fail(scenario + ":" + index + ": exception happened: " + exception); |
56 | } | 56 | } |
57 | if (index % commitFrequency == 0) { | 57 | if (index % commitFrequency == 0) { |
58 | long version = versioned.commit(); | 58 | Version version = versioned.commit(); |
59 | largestCommit = (int) version; | 59 | index2Version.put(index,version); |
60 | largestCommit = index; | ||
60 | } | 61 | } |
61 | if (index % 10000 == 0) | 62 | if (index % 10000 == 0) |
62 | System.out.println(scenario + ":" + index + "/" + steps + " building finished"); | 63 | System.out.println(scenario + ":" + index + "/" + steps + " building finished"); |
@@ -73,20 +74,20 @@ class DiffCursorFuzzTest { | |||
73 | int index = i + 1; | 74 | int index = i + 1; |
74 | if (index % diffTravelFrequency == 0) { | 75 | if (index % diffTravelFrequency == 0) { |
75 | // diff-travel | 76 | // diff-travel |
76 | long travelToVersion = r2.nextInt(largestCommit + 1); | 77 | int travelToVersion = r2.nextInt(largestCommit + 1); |
77 | 78 | ||
78 | VersionedMap<Integer, String> oracle = store.createMap(travelToVersion); | 79 | VersionedMap<Integer, String> oracle = store.createMap(index2Version.get(travelToVersion)); |
79 | 80 | ||
80 | if(commitBeforeDiffCursor) { | 81 | if(commitBeforeDiffCursor) { |
81 | moving.commit(); | 82 | moving.commit(); |
82 | } | 83 | } |
83 | DiffCursor<Integer, String> diffCursor = moving.getDiffCursor(travelToVersion); | 84 | DiffCursor<Integer, String> diffCursor = moving.getDiffCursor(index2Version.get(travelToVersion)); |
84 | moving.putAll(diffCursor); | 85 | moving.putAll(diffCursor); |
85 | moving.commit(); | 86 | moving.commit(); |
86 | 87 | ||
87 | MapTestEnvironment.compareTwoMaps(scenario + ":c" + index, oracle, moving); | 88 | MapTestEnvironment.compareTwoMaps(scenario + ":c" + index, oracle, moving); |
88 | 89 | ||
89 | moving.restore(travelToVersion); | 90 | moving.restore(index2Version.get(travelToVersion)); |
90 | 91 | ||
91 | } else { | 92 | } else { |
92 | // random puts | 93 | // random puts |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MultiThreadTestRunnable.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MultiThreadTestRunnable.java index 9b2e591a..dfe46bae 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MultiThreadTestRunnable.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MultiThreadTestRunnable.java | |||
@@ -13,6 +13,7 @@ import java.util.List; | |||
13 | import java.util.Map; | 13 | import java.util.Map; |
14 | import java.util.Random; | 14 | import java.util.Random; |
15 | 15 | ||
16 | import tools.refinery.store.map.Version; | ||
16 | import tools.refinery.store.map.VersionedMap; | 17 | import tools.refinery.store.map.VersionedMap; |
17 | import tools.refinery.store.map.VersionedMapStore; | 18 | import tools.refinery.store.map.VersionedMapStore; |
18 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; | 19 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; |
@@ -61,7 +62,7 @@ public class MultiThreadTestRunnable implements Runnable { | |||
61 | // 1. build a map with versions | 62 | // 1. build a map with versions |
62 | Random r = new Random(seed); | 63 | Random r = new Random(seed); |
63 | VersionedMap<Integer, String> versioned = store.createMap(); | 64 | VersionedMap<Integer, String> versioned = store.createMap(); |
64 | Map<Integer, Long> index2Version = new HashMap<>(); | 65 | Map<Integer, Version> index2Version = new HashMap<>(); |
65 | 66 | ||
66 | for (int i = 0; i < steps; i++) { | 67 | for (int i = 0; i < steps; i++) { |
67 | int index = i + 1; | 68 | int index = i + 1; |
@@ -74,7 +75,7 @@ public class MultiThreadTestRunnable implements Runnable { | |||
74 | logAndThrowError(scenario + ":" + index + ": exception happened: " + exception); | 75 | logAndThrowError(scenario + ":" + index + ": exception happened: " + exception); |
75 | } | 76 | } |
76 | if (index % commitFrequency == 0) { | 77 | if (index % commitFrequency == 0) { |
77 | long version = versioned.commit(); | 78 | Version version = versioned.commit(); |
78 | index2Version.put(i, version); | 79 | index2Version.put(i, version); |
79 | } | 80 | } |
80 | MapTestEnvironment.printStatus(scenario, index, steps, "building"); | 81 | MapTestEnvironment.printStatus(scenario, index, steps, "building"); |
@@ -100,13 +101,12 @@ public class MultiThreadTestRunnable implements Runnable { | |||
100 | MapTestEnvironment.compareTwoMaps(scenario + ":" + index, reference, versioned, null); | 101 | MapTestEnvironment.compareTwoMaps(scenario + ":" + index, reference, versioned, null); |
101 | 102 | ||
102 | // go back to a random state (probably created by another thread) | 103 | // go back to a random state (probably created by another thread) |
103 | List<Long> states = new ArrayList<>(store.getStates()); | 104 | List<Version> states = new ArrayList<>(index2Version.values()); |
104 | states.sort(Long::compare); | 105 | //states.sort(Long::compare); |
105 | Collections.shuffle(states, r2); | 106 | Collections.shuffle(states, r2); |
106 | for (Long state : states.subList(0, Math.min(states.size(), 100))) { | 107 | for (Version state : states.subList(0, Math.min(states.size(), 100))) { |
107 | long x = state; | 108 | versioned.restore(state); |
108 | versioned.restore(x); | 109 | var clean = store.createMap(state); |
109 | var clean = store.createMap(x); | ||
110 | MapTestEnvironment.compareTwoMaps(scenario + ":" + index, clean, versioned, null); | 110 | MapTestEnvironment.compareTwoMaps(scenario + ":" + index, clean, versioned, null); |
111 | } | 111 | } |
112 | versioned.restore(index2Version.get(i)); | 112 | versioned.restore(index2Version.get(i)); |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/RestoreFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/RestoreFuzzTest.java index 0b399c3a..5c768788 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/RestoreFuzzTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/RestoreFuzzTest.java | |||
@@ -10,6 +10,7 @@ import org.junit.jupiter.api.Timeout; | |||
10 | import org.junit.jupiter.params.ParameterizedTest; | 10 | import org.junit.jupiter.params.ParameterizedTest; |
11 | import org.junit.jupiter.params.provider.Arguments; | 11 | import org.junit.jupiter.params.provider.Arguments; |
12 | import org.junit.jupiter.params.provider.MethodSource; | 12 | import org.junit.jupiter.params.provider.MethodSource; |
13 | import tools.refinery.store.map.Version; | ||
13 | import tools.refinery.store.map.VersionedMap; | 14 | import tools.refinery.store.map.VersionedMap; |
14 | import tools.refinery.store.map.VersionedMapStore; | 15 | import tools.refinery.store.map.VersionedMapStore; |
15 | import tools.refinery.store.map.VersionedMapStoreFactoryBuilder; | 16 | import tools.refinery.store.map.VersionedMapStoreFactoryBuilder; |
@@ -40,7 +41,7 @@ class RestoreFuzzTest { | |||
40 | // 1. build a map with versions | 41 | // 1. build a map with versions |
41 | Random r = new Random(seed); | 42 | Random r = new Random(seed); |
42 | VersionedMap<Integer, String> versioned = store.createMap(); | 43 | VersionedMap<Integer, String> versioned = store.createMap(); |
43 | Map<Integer, Long> index2Version = new HashMap<>(); | 44 | Map<Integer, Version> index2Version = new HashMap<>(); |
44 | 45 | ||
45 | for (int i = 0; i < steps; i++) { | 46 | for (int i = 0; i < steps; i++) { |
46 | int index = i + 1; | 47 | int index = i + 1; |
@@ -53,7 +54,7 @@ class RestoreFuzzTest { | |||
53 | fail(scenario + ":" + index + ": exception happened: " + exception); | 54 | fail(scenario + ":" + index + ": exception happened: " + exception); |
54 | } | 55 | } |
55 | if (index % commitFrequency == 0) { | 56 | if (index % commitFrequency == 0) { |
56 | long version = versioned.commit(); | 57 | Version version = versioned.commit(); |
57 | index2Version.put(i, version); | 58 | index2Version.put(i, version); |
58 | } | 59 | } |
59 | MapTestEnvironment.printStatus(scenario, index, steps, "building"); | 60 | MapTestEnvironment.printStatus(scenario, index, steps, "building"); |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SharedStoreFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SharedStoreFuzzTest.java index b17766b7..299c94b1 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SharedStoreFuzzTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SharedStoreFuzzTest.java | |||
@@ -19,6 +19,7 @@ import org.junit.jupiter.params.provider.Arguments; | |||
19 | import org.junit.jupiter.params.provider.MethodSource; | 19 | import org.junit.jupiter.params.provider.MethodSource; |
20 | 20 | ||
21 | import tools.refinery.store.map.ContinuousHashProvider; | 21 | import tools.refinery.store.map.ContinuousHashProvider; |
22 | import tools.refinery.store.map.Version; | ||
22 | import tools.refinery.store.map.VersionedMapStore; | 23 | import tools.refinery.store.map.VersionedMapStore; |
23 | import tools.refinery.store.map.internal.state.VersionedMapStoreStateImpl; | 24 | import tools.refinery.store.map.internal.state.VersionedMapStoreStateImpl; |
24 | import tools.refinery.store.map.internal.state.VersionedMapStateImpl; | 25 | import tools.refinery.store.map.internal.state.VersionedMapStateImpl; |
@@ -47,7 +48,7 @@ class SharedStoreFuzzTest { | |||
47 | versioneds.add((VersionedMapStateImpl<Integer, String>) store.createMap()); | 48 | versioneds.add((VersionedMapStateImpl<Integer, String>) store.createMap()); |
48 | } | 49 | } |
49 | 50 | ||
50 | List<Map<Integer, Long>> index2Version = new LinkedList<>(); | 51 | List<Map<Integer, Version>> index2Version = new LinkedList<>(); |
51 | for (int i = 0; i < stores.size(); i++) { | 52 | for (int i = 0; i < stores.size(); i++) { |
52 | index2Version.add(new HashMap<>()); | 53 | index2Version.add(new HashMap<>()); |
53 | } | 54 | } |
@@ -59,7 +60,7 @@ class SharedStoreFuzzTest { | |||
59 | String nextValue = values[r.nextInt(values.length)]; | 60 | String nextValue = values[r.nextInt(values.length)]; |
60 | versioneds.get(storeIndex).put(nextKey, nextValue); | 61 | versioneds.get(storeIndex).put(nextKey, nextValue); |
61 | if (stepIndex % commitFrequency == 0) { | 62 | if (stepIndex % commitFrequency == 0) { |
62 | long version = versioneds.get(storeIndex).commit(); | 63 | Version version = versioneds.get(storeIndex).commit(); |
63 | index2Version.get(storeIndex).put(i, version); | 64 | index2Version.get(storeIndex).put(i, version); |
64 | } | 65 | } |
65 | MapTestEnvironment.printStatus(scenario, stepIndex, steps, "building"); | 66 | MapTestEnvironment.printStatus(scenario, stepIndex, steps, "building"); |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/utils/FuzzTestCollections.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/utils/FuzzTestCollections.java index 4c3ecb09..ec04904e 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/utils/FuzzTestCollections.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/utils/FuzzTestCollections.java | |||
@@ -18,26 +18,35 @@ public final class FuzzTestCollections { | |||
18 | public static final Object[] randomSeedOptions = {1}; | 18 | public static final Object[] randomSeedOptions = {1}; |
19 | public static final Object[] storeConfigs = { | 19 | public static final Object[] storeConfigs = { |
20 | // State based | 20 | // State based |
21 | // Default | ||
21 | VersionedMapStore.<Integer,String>builder() | 22 | VersionedMapStore.<Integer,String>builder() |
22 | .stateBasedImmutableWhenCommitting(true) | ||
23 | .stateBasedHashProvider(MapTestEnvironment.prepareHashProvider(false)) | 23 | .stateBasedHashProvider(MapTestEnvironment.prepareHashProvider(false)) |
24 | .stateBasedSharingStrategy(VersionedMapStoreFactoryBuilder.SharingStrategy.SHARED_NODE_CACHE), | 24 | .stateBasedSharingStrategy(VersionedMapStoreFactoryBuilder.SharingStrategy.SHARED_NODE_CACHE), |
25 | // Evil hash code test | ||
25 | VersionedMapStore.<Integer,String>builder() | 26 | VersionedMapStore.<Integer,String>builder() |
26 | .stateBasedImmutableWhenCommitting(true) | ||
27 | .stateBasedHashProvider(MapTestEnvironment.prepareHashProvider(true)) | 27 | .stateBasedHashProvider(MapTestEnvironment.prepareHashProvider(true)) |
28 | .stateBasedSharingStrategy(VersionedMapStoreFactoryBuilder.SharingStrategy.SHARED_NODE_CACHE), | 28 | .stateBasedSharingStrategy(VersionedMapStoreFactoryBuilder.SharingStrategy.SHARED_NODE_CACHE), |
29 | // No weak hashmap test | ||
30 | VersionedMapStore.<Integer,String>builder() | ||
31 | .versionFreeing(false) | ||
32 | .stateBasedHashProvider(MapTestEnvironment.prepareHashProvider(false)) | ||
33 | .stateBasedSharingStrategy(VersionedMapStoreFactoryBuilder.SharingStrategy.SHARED_NODE_CACHE), | ||
34 | // Copy when committing, do not hurt the work copy, share between saves. | ||
29 | VersionedMapStore.<Integer,String>builder() | 35 | VersionedMapStore.<Integer,String>builder() |
30 | .stateBasedImmutableWhenCommitting(false) | 36 | .stateBasedImmutableWhenCommitting(false) |
31 | .stateBasedHashProvider(MapTestEnvironment.prepareHashProvider(false)) | 37 | .stateBasedHashProvider(MapTestEnvironment.prepareHashProvider(false)) |
32 | .stateBasedSharingStrategy(VersionedMapStoreFactoryBuilder.SharingStrategy.SHARED_NODE_CACHE), | 38 | .stateBasedSharingStrategy(VersionedMapStoreFactoryBuilder.SharingStrategy.SHARED_NODE_CACHE), |
39 | // Copy when committing, do not hurt the work copy, do not share between states. | ||
33 | VersionedMapStore.<Integer,String>builder() | 40 | VersionedMapStore.<Integer,String>builder() |
34 | .stateBasedImmutableWhenCommitting(false) | 41 | .stateBasedImmutableWhenCommitting(false) |
35 | .stateBasedHashProvider(MapTestEnvironment.prepareHashProvider(false)) | 42 | .stateBasedHashProvider(MapTestEnvironment.prepareHashProvider(false)) |
36 | .stateBasedSharingStrategy(VersionedMapStoreFactoryBuilder.SharingStrategy.NO_NODE_CACHE), | 43 | .stateBasedSharingStrategy(VersionedMapStoreFactoryBuilder.SharingStrategy.NO_NODE_CACHE), |
37 | 44 | ||
38 | // Delta based | 45 | // Delta based |
46 | // Set based transactions | ||
39 | VersionedMapStore.<Integer,String>builder() | 47 | VersionedMapStore.<Integer,String>builder() |
40 | .deltaTransactionStrategy(VersionedMapStoreFactoryBuilder.DeltaTransactionStrategy.SET), | 48 | .deltaTransactionStrategy(VersionedMapStoreFactoryBuilder.DeltaTransactionStrategy.SET), |
49 | // List based transactions | ||
41 | VersionedMapStore.<Integer,String>builder() | 50 | VersionedMapStore.<Integer,String>builder() |
42 | .deltaTransactionStrategy(VersionedMapStoreFactoryBuilder.DeltaTransactionStrategy.LIST) | 51 | .deltaTransactionStrategy(VersionedMapStoreFactoryBuilder.DeltaTransactionStrategy.LIST) |
43 | }; | 52 | }; |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java index 401f2866..b84df280 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java | |||
@@ -125,7 +125,7 @@ public class MapTestEnvironment<K, V> { | |||
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | public long commit(){ | 128 | public Version commit(){ |
129 | return sut.commit(); | 129 | return sut.commit(); |
130 | } | 130 | } |
131 | 131 | ||
diff --git a/subprojects/store/src/test/java/tools/refinery/store/model/tests/ModelTest.java b/subprojects/store/src/test/java/tools/refinery/store/model/tests/ModelTest.java index 56b75804..dc7b776e 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/model/tests/ModelTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/model/tests/ModelTest.java | |||
@@ -6,6 +6,7 @@ | |||
6 | package tools.refinery.store.model.tests; | 6 | package tools.refinery.store.model.tests; |
7 | 7 | ||
8 | import org.junit.jupiter.api.Test; | 8 | import org.junit.jupiter.api.Test; |
9 | import tools.refinery.store.map.Version; | ||
9 | import tools.refinery.store.model.Model; | 10 | import tools.refinery.store.model.Model; |
10 | import tools.refinery.store.model.ModelStore; | 11 | import tools.refinery.store.model.ModelStore; |
11 | import tools.refinery.store.representation.Symbol; | 12 | import tools.refinery.store.representation.Symbol; |
@@ -120,7 +121,7 @@ class ModelTest { | |||
120 | assertTrue(model.hasUncommittedChanges()); | 121 | assertTrue(model.hasUncommittedChanges()); |
121 | assertEquals(Model.NO_STATE_ID, model.getState()); | 122 | assertEquals(Model.NO_STATE_ID, model.getState()); |
122 | 123 | ||
123 | long state1 = model.commit(); | 124 | Version state1 = model.commit(); |
124 | 125 | ||
125 | assertFalse(model.hasUncommittedChanges()); | 126 | assertFalse(model.hasUncommittedChanges()); |
126 | assertEquals(state1, model.getState()); | 127 | assertEquals(state1, model.getState()); |
@@ -134,7 +135,7 @@ class ModelTest { | |||
134 | assertTrue(model.hasUncommittedChanges()); | 135 | assertTrue(model.hasUncommittedChanges()); |
135 | assertEquals(state1, model.getState()); | 136 | assertEquals(state1, model.getState()); |
136 | 137 | ||
137 | long state2 = model.commit(); | 138 | Version state2 = model.commit(); |
138 | 139 | ||
139 | assertFalse(model.hasUncommittedChanges()); | 140 | assertFalse(model.hasUncommittedChanges()); |
140 | assertEquals(state2, model.getState()); | 141 | assertEquals(state2, model.getState()); |