diff options
author | 2023-07-26 17:58:52 +0200 | |
---|---|---|
committer | 2023-07-26 17:58:52 +0200 | |
commit | 70e769cd59bca88e5d3ce3e6e6aa279b7085a3f8 (patch) | |
tree | 5db595fcf8b13ea0c3b4969b4fc3ffacd95b08a5 /subprojects/store/src/test/java/tools | |
parent | Merge pull request #30 from OszkarSemerath/datastructure (diff) | |
parent | Versioned.commit + Versioned.restore uses Version instead of long. (diff) | |
download | refinery-70e769cd59bca88e5d3ce3e6e6aa279b7085a3f8.tar.gz refinery-70e769cd59bca88e5d3ce3e6e6aa279b7085a3f8.tar.zst refinery-70e769cd59bca88e5d3ce3e6e6aa279b7085a3f8.zip |
Merge pull request #31 from OszkarSemerath/datastructure
Datastructure versions
Diffstat (limited to 'subprojects/store/src/test/java/tools')
11 files changed, 72 insertions, 62 deletions
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/InOrderCursorTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/InOrderCursorTest.java index 4ada4ea4..98756460 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/InOrderCursorTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/InOrderCursorTest.java | |||
@@ -8,8 +8,8 @@ package tools.refinery.store.map.tests; | |||
8 | import org.junit.jupiter.api.Test; | 8 | import org.junit.jupiter.api.Test; |
9 | import tools.refinery.store.map.VersionedMapStore; | 9 | import tools.refinery.store.map.VersionedMapStore; |
10 | import tools.refinery.store.map.VersionedMapStoreFactoryBuilder; | 10 | import tools.refinery.store.map.VersionedMapStoreFactoryBuilder; |
11 | import tools.refinery.store.map.internal.InOrderMapCursor; | 11 | import tools.refinery.store.map.internal.state.InOrderMapCursor; |
12 | import tools.refinery.store.map.internal.VersionedMapImpl; | 12 | import tools.refinery.store.map.internal.state.VersionedMapStateImpl; |
13 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; | 13 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; |
14 | 14 | ||
15 | import static org.junit.jupiter.api.Assertions.*; | 15 | import static org.junit.jupiter.api.Assertions.*; |
@@ -26,7 +26,7 @@ class InOrderCursorTest { | |||
26 | .build() | 26 | .build() |
27 | .createOne(); | 27 | .createOne(); |
28 | 28 | ||
29 | VersionedMapImpl<Integer,String> map = (VersionedMapImpl<Integer,String>) store.createMap(); | 29 | VersionedMapStateImpl<Integer,String> map = (VersionedMapStateImpl<Integer,String>) store.createMap(); |
30 | checkMove(map,0); | 30 | checkMove(map,0); |
31 | 31 | ||
32 | map.put(1,"A"); | 32 | map.put(1,"A"); |
@@ -44,7 +44,7 @@ class InOrderCursorTest { | |||
44 | 44 | ||
45 | } | 45 | } |
46 | 46 | ||
47 | private void checkMove(VersionedMapImpl<Integer,String> map, int num) { | 47 | private void checkMove(VersionedMapStateImpl<Integer,String> map, int num) { |
48 | InOrderMapCursor<Integer,String> cursor = new InOrderMapCursor<>(map); | 48 | InOrderMapCursor<Integer,String> cursor = new InOrderMapCursor<>(map); |
49 | for(int i=0; i<num; i++) { | 49 | for(int i=0; i<num; i++) { |
50 | assertTrue(cursor.move()); | 50 | assertTrue(cursor.move()); |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/MapUnitTests.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/MapUnitTests.java index 2be49bd9..cc2e425c 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/MapUnitTests.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/MapUnitTests.java | |||
@@ -7,7 +7,7 @@ package tools.refinery.store.map.tests; | |||
7 | 7 | ||
8 | import org.junit.jupiter.api.Test; | 8 | import org.junit.jupiter.api.Test; |
9 | import tools.refinery.store.map.VersionedMapStore; | 9 | import tools.refinery.store.map.VersionedMapStore; |
10 | import tools.refinery.store.map.VersionedMapStoreImpl; | 10 | import tools.refinery.store.map.internal.state.VersionedMapStoreStateImpl; |
11 | import tools.refinery.store.model.TupleHashProvider; | 11 | import tools.refinery.store.model.TupleHashProvider; |
12 | import tools.refinery.store.tuple.Tuple; | 12 | import tools.refinery.store.tuple.Tuple; |
13 | 13 | ||
@@ -16,7 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; | |||
16 | class MapUnitTests { | 16 | class MapUnitTests { |
17 | @Test | 17 | @Test |
18 | void defaultTest() { | 18 | void defaultTest() { |
19 | VersionedMapStore<Tuple, Boolean> store = new VersionedMapStoreImpl<>(TupleHashProvider.INSTANCE, false); | 19 | VersionedMapStore<Tuple, Boolean> store = new VersionedMapStoreStateImpl<>(TupleHashProvider.INSTANCE, false); |
20 | var map = store.createMap(); | 20 | var map = store.createMap(); |
21 | var out1 = map.put(Tuple.of(0), true); | 21 | var out1 = map.put(Tuple.of(0), true); |
22 | assertEquals(false, out1); | 22 | assertEquals(false, out1); |
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/MutableImmutableCompareFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableImmutableCompareFuzzTest.java index 420dade6..abfb4791 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableImmutableCompareFuzzTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableImmutableCompareFuzzTest.java | |||
@@ -17,10 +17,10 @@ import org.junit.jupiter.params.ParameterizedTest; | |||
17 | import org.junit.jupiter.params.provider.Arguments; | 17 | import org.junit.jupiter.params.provider.Arguments; |
18 | import org.junit.jupiter.params.provider.MethodSource; | 18 | import org.junit.jupiter.params.provider.MethodSource; |
19 | 19 | ||
20 | import tools.refinery.store.map.ContinousHashProvider; | 20 | import tools.refinery.store.map.ContinuousHashProvider; |
21 | import tools.refinery.store.map.VersionedMapStore; | 21 | import tools.refinery.store.map.VersionedMapStore; |
22 | import tools.refinery.store.map.VersionedMapStoreImpl; | 22 | import tools.refinery.store.map.internal.state.VersionedMapStoreStateImpl; |
23 | import tools.refinery.store.map.internal.VersionedMapImpl; | 23 | import tools.refinery.store.map.internal.state.VersionedMapStateImpl; |
24 | import tools.refinery.store.map.tests.fuzz.utils.FuzzTestUtils; | 24 | import tools.refinery.store.map.tests.fuzz.utils.FuzzTestUtils; |
25 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; | 25 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; |
26 | 26 | ||
@@ -28,11 +28,11 @@ class MutableImmutableCompareFuzzTest { | |||
28 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, | 28 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, |
29 | boolean nullDefault, int commitFrequency, boolean evilHash) { | 29 | boolean nullDefault, int commitFrequency, boolean evilHash) { |
30 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); | 30 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); |
31 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | 31 | ContinuousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); |
32 | 32 | ||
33 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<>(chp, values[0]); | 33 | VersionedMapStore<Integer, String> store = new VersionedMapStoreStateImpl<>(chp, values[0]); |
34 | VersionedMapImpl<Integer, String> immutable = (VersionedMapImpl<Integer, String>) store.createMap(); | 34 | VersionedMapStateImpl<Integer, String> immutable = (VersionedMapStateImpl<Integer, String>) store.createMap(); |
35 | VersionedMapImpl<Integer, String> mutable = (VersionedMapImpl<Integer, String>) store.createMap(); | 35 | VersionedMapStateImpl<Integer, String> mutable = (VersionedMapStateImpl<Integer, String>) store.createMap(); |
36 | 36 | ||
37 | Random r = new Random(seed); | 37 | Random r = new Random(seed); |
38 | 38 | ||
@@ -40,8 +40,8 @@ class MutableImmutableCompareFuzzTest { | |||
40 | commitFrequency); | 40 | commitFrequency); |
41 | } | 41 | } |
42 | 42 | ||
43 | private void iterativeRandomPutsAndCommitsAndCompare(String scenario, VersionedMapImpl<Integer, String> immutable, | 43 | private void iterativeRandomPutsAndCommitsAndCompare(String scenario, VersionedMapStateImpl<Integer, String> immutable, |
44 | VersionedMapImpl<Integer, String> mutable, int steps, int maxKey, String[] values, Random r, | 44 | VersionedMapStateImpl<Integer, String> mutable, int steps, int maxKey, String[] values, Random r, |
45 | int commitFrequency) { | 45 | int commitFrequency) { |
46 | for (int i = 0; i < steps; i++) { | 46 | for (int i = 0; i < steps; i++) { |
47 | int index = i + 1; | 47 | int index = i + 1; |
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 680d962d..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 | |||
@@ -18,10 +18,11 @@ import org.junit.jupiter.params.ParameterizedTest; | |||
18 | import org.junit.jupiter.params.provider.Arguments; | 18 | 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.ContinousHashProvider; | 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.VersionedMapStoreImpl; | 24 | import tools.refinery.store.map.internal.state.VersionedMapStoreStateImpl; |
24 | import tools.refinery.store.map.internal.VersionedMapImpl; | 25 | import tools.refinery.store.map.internal.state.VersionedMapStateImpl; |
25 | import tools.refinery.store.map.tests.fuzz.utils.FuzzTestUtils; | 26 | import tools.refinery.store.map.tests.fuzz.utils.FuzzTestUtils; |
26 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; | 27 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; |
27 | 28 | ||
@@ -31,9 +32,9 @@ class SharedStoreFuzzTest { | |||
31 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, | 32 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, |
32 | boolean nullDefault, int commitFrequency, boolean evilHash) { | 33 | boolean nullDefault, int commitFrequency, boolean evilHash) { |
33 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); | 34 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); |
34 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | 35 | ContinuousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); |
35 | 36 | ||
36 | List<VersionedMapStore<Integer, String>> stores = VersionedMapStoreImpl.createSharedVersionedMapStores(5, chp, values[0]); | 37 | List<VersionedMapStore<Integer, String>> stores = VersionedMapStoreStateImpl.createSharedVersionedMapStores(5, chp, values[0]); |
37 | 38 | ||
38 | iterativeRandomPutsAndCommitsThenRestore(scenario, stores, steps, maxKey, values, seed, commitFrequency); | 39 | iterativeRandomPutsAndCommitsThenRestore(scenario, stores, steps, maxKey, values, seed, commitFrequency); |
39 | } | 40 | } |
@@ -42,12 +43,12 @@ class SharedStoreFuzzTest { | |||
42 | int steps, int maxKey, String[] values, int seed, int commitFrequency) { | 43 | int steps, int maxKey, String[] values, int seed, int commitFrequency) { |
43 | // 1. maps with versions | 44 | // 1. maps with versions |
44 | Random r = new Random(seed); | 45 | Random r = new Random(seed); |
45 | List<VersionedMapImpl<Integer, String>> versioneds = new LinkedList<>(); | 46 | List<VersionedMapStateImpl<Integer, String>> versioneds = new LinkedList<>(); |
46 | for (VersionedMapStore<Integer, String> store : stores) { | 47 | for (VersionedMapStore<Integer, String> store : stores) { |
47 | versioneds.add((VersionedMapImpl<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,16 +60,16 @@ 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"); |
66 | } | 67 | } |
67 | } | 68 | } |
68 | // 2. create a non-versioned and | 69 | // 2. create a non-versioned and |
69 | List<VersionedMapImpl<Integer, String>> reference = new LinkedList<>(); | 70 | List<VersionedMapStateImpl<Integer, String>> reference = new LinkedList<>(); |
70 | for (VersionedMapStore<Integer, String> store : stores) { | 71 | for (VersionedMapStore<Integer, String> store : stores) { |
71 | reference.add((VersionedMapImpl<Integer, String>) store.createMap()); | 72 | reference.add((VersionedMapStateImpl<Integer, String>) store.createMap()); |
72 | } | 73 | } |
73 | r = new Random(seed); | 74 | r = new Random(seed); |
74 | 75 | ||
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 e7348370..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 | |||
@@ -6,7 +6,7 @@ | |||
6 | package tools.refinery.store.map.tests.utils; | 6 | package tools.refinery.store.map.tests.utils; |
7 | 7 | ||
8 | import tools.refinery.store.map.*; | 8 | import tools.refinery.store.map.*; |
9 | import tools.refinery.store.map.internal.VersionedMapImpl; | 9 | import tools.refinery.store.map.internal.state.VersionedMapStateImpl; |
10 | 10 | ||
11 | import java.util.*; | 11 | import java.util.*; |
12 | import java.util.Map.Entry; | 12 | import java.util.Map.Entry; |
@@ -28,7 +28,7 @@ public class MapTestEnvironment<K, V> { | |||
28 | return values; | 28 | return values; |
29 | } | 29 | } |
30 | 30 | ||
31 | public static ContinousHashProvider<Integer> prepareHashProvider(final boolean evil) { | 31 | public static ContinuousHashProvider<Integer> prepareHashProvider(final boolean evil) { |
32 | // Use maxPrime = 2147483629 | 32 | // Use maxPrime = 2147483629 |
33 | 33 | ||
34 | return (key, index) -> { | 34 | return (key, index) -> { |
@@ -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 | ||
@@ -187,7 +187,7 @@ public class MapTestEnvironment<K, V> { | |||
187 | //System.out.println(cursor.getKey() + " " + ((VersionedMapImpl<K, V>) versionedMap).getHashProvider() | 187 | //System.out.println(cursor.getKey() + " " + ((VersionedMapImpl<K, V>) versionedMap).getHashProvider() |
188 | // .getHash(cursor.getKey(), 0)); | 188 | // .getHash(cursor.getKey(), 0)); |
189 | if (previous != null) { | 189 | if (previous != null) { |
190 | int comparisonResult = ((VersionedMapImpl<K, V>) versionedMap).getHashProvider().compare(previous, | 190 | int comparisonResult = ((VersionedMapStateImpl<K, V>) versionedMap).getHashProvider().compare(previous, |
191 | cursor.getKey()); | 191 | cursor.getKey()); |
192 | assertTrue(comparisonResult < 0, scenario + " Cursor order is not incremental!"); | 192 | assertTrue(comparisonResult < 0, scenario + " Cursor order is not incremental!"); |
193 | } | 193 | } |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/model/hashtests/HashEfficiencyTest.java b/subprojects/store/src/test/java/tools/refinery/store/model/hashtests/HashEfficiencyTest.java index 4d4f5e26..5b595da7 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/model/hashtests/HashEfficiencyTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/model/hashtests/HashEfficiencyTest.java | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.model.hashtests; | 6 | package tools.refinery.store.model.hashTests; |
7 | 7 | ||
8 | import static org.junit.jupiter.api.Assertions.assertEquals; | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; |
9 | 9 | ||
@@ -14,10 +14,9 @@ import java.util.Random; | |||
14 | 14 | ||
15 | import org.junit.jupiter.api.Test; | 15 | import org.junit.jupiter.api.Test; |
16 | 16 | ||
17 | import tools.refinery.store.map.ContinousHashProvider; | 17 | import tools.refinery.store.map.ContinuousHashProvider; |
18 | import tools.refinery.store.tuple.Tuple; | 18 | import tools.refinery.store.tuple.Tuple; |
19 | import tools.refinery.store.model.TupleHashProvider; | 19 | import tools.refinery.store.model.TupleHashProvider; |
20 | import tools.refinery.store.model.TupleHashProviderBitMagic; | ||
21 | 20 | ||
22 | class HashEfficiencyTest { | 21 | class HashEfficiencyTest { |
23 | 22 | ||
@@ -95,7 +94,7 @@ class HashEfficiencyTest { | |||
95 | List<Tuple> p = nRandoms(2, amount, 1);; | 94 | List<Tuple> p = nRandoms(2, amount, 1);; |
96 | assertEquals(amount,p.size()); | 95 | assertEquals(amount,p.size()); |
97 | } | 96 | } |
98 | private static double calculateHashClashes(List<Tuple> tuples, ContinousHashProvider<Tuple> chp) { | 97 | private static double calculateHashClashes(List<Tuple> tuples, ContinuousHashProvider<Tuple> chp) { |
99 | int sumClashes = 0; | 98 | int sumClashes = 0; |
100 | 99 | ||
101 | for(int i = 0; i<tuples.size(); i++) { | 100 | for(int i = 0; i<tuples.size(); i++) { |
@@ -108,7 +107,7 @@ class HashEfficiencyTest { | |||
108 | } | 107 | } |
109 | return (sumClashes+0.0) / tuples.size(); | 108 | return (sumClashes+0.0) / tuples.size(); |
110 | } | 109 | } |
111 | private static int calculateHashClash(ContinousHashProvider<Tuple> chp, Tuple a, Tuple b) { | 110 | private static int calculateHashClash(ContinuousHashProvider<Tuple> chp, Tuple a, Tuple b) { |
112 | if(a.equals(b)) return 0; | 111 | if(a.equals(b)) return 0; |
113 | final int bits = 5; | 112 | final int bits = 5; |
114 | final int segments = Integer.SIZE/bits; | 113 | final int segments = Integer.SIZE/bits; |
@@ -131,11 +130,9 @@ class HashEfficiencyTest { | |||
131 | } | 130 | } |
132 | public static void main(String[] args) { | 131 | public static void main(String[] args) { |
133 | List<String> hashNames = new LinkedList<>(); | 132 | List<String> hashNames = new LinkedList<>(); |
134 | List<ContinousHashProvider<Tuple>> hashes = new LinkedList<>(); | 133 | List<ContinuousHashProvider<Tuple>> hashes = new LinkedList<>(); |
135 | hashNames.add("PrimeGroup"); | 134 | hashNames.add("PrimeGroup"); |
136 | hashes.add(new TupleHashProvider()); | 135 | hashes.add(new TupleHashProvider()); |
137 | hashNames.add("BitMagic"); | ||
138 | hashes.add(new TupleHashProviderBitMagic()); | ||
139 | 136 | ||
140 | int[] arities = new int[] {2,3,4,5}; | 137 | int[] arities = new int[] {2,3,4,5}; |
141 | int[] sizes = new int[] {32*32,32*32*8}; | 138 | int[] sizes = new int[] {32*32,32*32*8}; |
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()); |