diff options
author | 2023-07-24 16:51:47 +0200 | |
---|---|---|
committer | 2023-07-24 16:51:47 +0200 | |
commit | 26592fc70a026b850616fc4bc9be5a46ab1179a9 (patch) | |
tree | 0e1f22a451122169f5efd2bc683c7787c666ddd6 /subprojects/store/src/test | |
parent | Enabled QueryTransactionTest (diff) | |
download | refinery-26592fc70a026b850616fc4bc9be5a46ab1179a9.tar.gz refinery-26592fc70a026b850616fc4bc9be5a46ab1179a9.tar.zst refinery-26592fc70a026b850616fc4bc9be5a46ab1179a9.zip |
Refactoring packages related to VersionedMapDeltaImpl + VersionedMapStoreStateImpl, update builder.
- details of the maps goes to internal packages
- ModelStoreBuilderImpl uses VersionedMapStoreFactoryBuilder
Diffstat (limited to 'subprojects/store/src/test')
6 files changed, 32 insertions, 35 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/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/SharedStoreFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SharedStoreFuzzTest.java index 680d962d..b17766b7 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,10 @@ 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.VersionedMapStore; | 22 | import tools.refinery.store.map.VersionedMapStore; |
23 | import tools.refinery.store.map.VersionedMapStoreImpl; | 23 | import tools.refinery.store.map.internal.state.VersionedMapStoreStateImpl; |
24 | import tools.refinery.store.map.internal.VersionedMapImpl; | 24 | import tools.refinery.store.map.internal.state.VersionedMapStateImpl; |
25 | import tools.refinery.store.map.tests.fuzz.utils.FuzzTestUtils; | 25 | import tools.refinery.store.map.tests.fuzz.utils.FuzzTestUtils; |
26 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; | 26 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; |
27 | 27 | ||
@@ -31,9 +31,9 @@ class SharedStoreFuzzTest { | |||
31 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, | 31 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, |
32 | boolean nullDefault, int commitFrequency, boolean evilHash) { | 32 | boolean nullDefault, int commitFrequency, boolean evilHash) { |
33 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); | 33 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); |
34 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | 34 | ContinuousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); |
35 | 35 | ||
36 | List<VersionedMapStore<Integer, String>> stores = VersionedMapStoreImpl.createSharedVersionedMapStores(5, chp, values[0]); | 36 | List<VersionedMapStore<Integer, String>> stores = VersionedMapStoreStateImpl.createSharedVersionedMapStores(5, chp, values[0]); |
37 | 37 | ||
38 | iterativeRandomPutsAndCommitsThenRestore(scenario, stores, steps, maxKey, values, seed, commitFrequency); | 38 | iterativeRandomPutsAndCommitsThenRestore(scenario, stores, steps, maxKey, values, seed, commitFrequency); |
39 | } | 39 | } |
@@ -42,9 +42,9 @@ class SharedStoreFuzzTest { | |||
42 | int steps, int maxKey, String[] values, int seed, int commitFrequency) { | 42 | int steps, int maxKey, String[] values, int seed, int commitFrequency) { |
43 | // 1. maps with versions | 43 | // 1. maps with versions |
44 | Random r = new Random(seed); | 44 | Random r = new Random(seed); |
45 | List<VersionedMapImpl<Integer, String>> versioneds = new LinkedList<>(); | 45 | List<VersionedMapStateImpl<Integer, String>> versioneds = new LinkedList<>(); |
46 | for (VersionedMapStore<Integer, String> store : stores) { | 46 | for (VersionedMapStore<Integer, String> store : stores) { |
47 | versioneds.add((VersionedMapImpl<Integer, String>) store.createMap()); | 47 | versioneds.add((VersionedMapStateImpl<Integer, String>) store.createMap()); |
48 | } | 48 | } |
49 | 49 | ||
50 | List<Map<Integer, Long>> index2Version = new LinkedList<>(); | 50 | List<Map<Integer, Long>> index2Version = new LinkedList<>(); |
@@ -66,9 +66,9 @@ class SharedStoreFuzzTest { | |||
66 | } | 66 | } |
67 | } | 67 | } |
68 | // 2. create a non-versioned and | 68 | // 2. create a non-versioned and |
69 | List<VersionedMapImpl<Integer, String>> reference = new LinkedList<>(); | 69 | List<VersionedMapStateImpl<Integer, String>> reference = new LinkedList<>(); |
70 | for (VersionedMapStore<Integer, String> store : stores) { | 70 | for (VersionedMapStore<Integer, String> store : stores) { |
71 | reference.add((VersionedMapImpl<Integer, String>) store.createMap()); | 71 | reference.add((VersionedMapStateImpl<Integer, String>) store.createMap()); |
72 | } | 72 | } |
73 | r = new Random(seed); | 73 | r = new Random(seed); |
74 | 74 | ||
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..401f2866 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) -> { |
@@ -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}; |