diff options
Diffstat (limited to 'subprojects/store/src/test/java')
-rw-r--r-- | subprojects/store/src/test/java/tools/refinery/store/map/tests/MapUnitTests.java | 72 | ||||
-rw-r--r-- | subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SingleThreadFuzzTest.java | 61 |
2 files changed, 133 insertions, 0 deletions
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 77c62305..2216db76 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 | |||
@@ -2,6 +2,7 @@ package tools.refinery.store.map.tests; | |||
2 | 2 | ||
3 | import org.junit.jupiter.api.Test; | 3 | import org.junit.jupiter.api.Test; |
4 | import tools.refinery.store.map.VersionedMapStore; | 4 | import tools.refinery.store.map.VersionedMapStore; |
5 | import tools.refinery.store.map.VersionedMapStoreBuilder; | ||
5 | import tools.refinery.store.map.VersionedMapStoreImpl; | 6 | import tools.refinery.store.map.VersionedMapStoreImpl; |
6 | import tools.refinery.store.model.TupleHashProvider; | 7 | import tools.refinery.store.model.TupleHashProvider; |
7 | import tools.refinery.store.tuple.Tuple; | 8 | import tools.refinery.store.tuple.Tuple; |
@@ -18,4 +19,75 @@ class MapUnitTests { | |||
18 | var out2 = map.put(Tuple.of(1), true); | 19 | var out2 = map.put(Tuple.of(1), true); |
19 | assertEquals(false, out2); | 20 | assertEquals(false, out2); |
20 | } | 21 | } |
22 | |||
23 | @Test | ||
24 | void deltaRestoreTest() { | ||
25 | VersionedMapStore<Integer,String> store = | ||
26 | VersionedMapStoreBuilder.<Integer,String>builder().setDefaultValue("x").buildOne(); | ||
27 | var map = store.createMap(); | ||
28 | map.put(1,"val"); | ||
29 | var version1 = map.commit(); | ||
30 | map.put(1,"x"); | ||
31 | map.restore(version1); | ||
32 | System.out.println(map.getSize()); | ||
33 | assertEquals(1,map.getSize()); | ||
34 | } | ||
35 | |||
36 | @Test | ||
37 | void deltaRestoreTest2() { | ||
38 | VersionedMapStore<Integer,String> store = | ||
39 | VersionedMapStoreBuilder.<Integer,String>builder().setDefaultValue("x").buildOne(); | ||
40 | var map = store.createMap(); | ||
41 | map.put(1,"x"); | ||
42 | var version1 = map.commit(); | ||
43 | map.put(1,"1"); | ||
44 | map.restore(version1); | ||
45 | System.out.println(map.getSize()); | ||
46 | assertEquals(0,map.getSize()); | ||
47 | } | ||
48 | @Test | ||
49 | void deltaRestoreTest3() { | ||
50 | VersionedMapStore<Integer,String> store = | ||
51 | VersionedMapStoreBuilder.<Integer,String>builder().setDefaultValue("x").buildOne(); | ||
52 | var map = store.createMap(); | ||
53 | map.commit(); | ||
54 | map.put(1,"1"); | ||
55 | map.put(2,"x"); | ||
56 | assertEquals(1,map.getSize()); | ||
57 | var version1 = map.commit(); | ||
58 | map.put(1,"x"); | ||
59 | assertEquals(0,map.getSize()); | ||
60 | map.put(2,"2"); | ||
61 | assertEquals(1,map.getSize()); | ||
62 | map.put(2,"x"); | ||
63 | assertEquals(0,map.getSize()); | ||
64 | var version2 = map.commit(); | ||
65 | map.restore(version1); | ||
66 | assertEquals(1,map.getSize()); | ||
67 | map.restore(version2); | ||
68 | assertEquals(0,map.getSize()); | ||
69 | } | ||
70 | |||
71 | @Test | ||
72 | void deltaRestoreTest4() { | ||
73 | VersionedMapStore<Integer,String> store = | ||
74 | VersionedMapStoreBuilder.<Integer,String>builder().setDefaultValue("x").buildOne(); | ||
75 | var map = store.createMap(); | ||
76 | map.commit(); | ||
77 | map.put(1,"1"); | ||
78 | map.put(2,"x"); | ||
79 | assertEquals(1,map.getSize()); | ||
80 | var version1 = map.commit(); | ||
81 | map.put(1,"x"); | ||
82 | assertEquals(0,map.getSize()); | ||
83 | map.put(2,"2"); | ||
84 | assertEquals(1,map.getSize()); | ||
85 | map.put(2,"x"); | ||
86 | assertEquals(0,map.getSize()); | ||
87 | var version2 = map.commit(); | ||
88 | map.restore(version1); | ||
89 | assertEquals(1,map.getSize()); | ||
90 | map.restore(version2); | ||
91 | assertEquals(0,map.getSize()); | ||
92 | } | ||
21 | } | 93 | } |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SingleThreadFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SingleThreadFuzzTest.java new file mode 100644 index 00000000..e7d49227 --- /dev/null +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SingleThreadFuzzTest.java | |||
@@ -0,0 +1,61 @@ | |||
1 | package tools.refinery.store.map.tests.fuzz; | ||
2 | |||
3 | import org.junit.jupiter.api.Tag; | ||
4 | import org.junit.jupiter.api.Timeout; | ||
5 | import org.junit.jupiter.params.ParameterizedTest; | ||
6 | import org.junit.jupiter.params.provider.Arguments; | ||
7 | import org.junit.jupiter.params.provider.MethodSource; | ||
8 | import tools.refinery.store.map.VersionedMapStore; | ||
9 | import tools.refinery.store.map.VersionedMapStoreBuilder; | ||
10 | import tools.refinery.store.map.tests.fuzz.utils.FuzzTestUtils; | ||
11 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; | ||
12 | |||
13 | import java.util.stream.Stream; | ||
14 | |||
15 | import static tools.refinery.store.map.tests.fuzz.utils.FuzzTestCollections.*; | ||
16 | |||
17 | class SingleThreadFuzzTest { | ||
18 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, boolean nullDefault, int commitFrequency, VersionedMapStoreBuilder<Integer, String> builder) { | ||
19 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); | ||
20 | |||
21 | VersionedMapStore<Integer, String> store = builder.setDefaultValue(values[0]).buildOne(); | ||
22 | |||
23 | // initialize runnables | ||
24 | MultiThreadTestRunnable runnable = new MultiThreadTestRunnable(scenario, store, steps, maxKey, values, seed, commitFrequency); | ||
25 | |||
26 | // start threads; | ||
27 | runnable.run(); | ||
28 | } | ||
29 | |||
30 | static final String title = "SingleThread {index}/{0} Steps={1} Keys={2} Values={3} defaultNull={4} commit " + | ||
31 | "frequency={5} seed={6} config={7}"; | ||
32 | |||
33 | @ParameterizedTest(name = title) | ||
34 | @MethodSource | ||
35 | @Timeout(value = 10) | ||
36 | @Tag("fuzz") | ||
37 | void parametrizedFastFuzz(int ignoredTests, int steps, int noKeys, int noValues, boolean defaultNull, | ||
38 | int commitFrequency, int seed, VersionedMapStoreBuilder<Integer, String> builder) { | ||
39 | runFuzzTest("SingleThreadS" + steps + "K" + noKeys + "V" + noValues + defaultNull + "CF" + commitFrequency + | ||
40 | "s" + seed, seed, steps, noKeys, noValues, defaultNull, commitFrequency, builder); | ||
41 | } | ||
42 | |||
43 | static Stream<Arguments> parametrizedFastFuzz() { | ||
44 | return FuzzTestUtils.permutationWithSize(stepCounts, keyCounts, valueCounts, nullDefaultOptions, | ||
45 | new Object[]{10, 100}, randomSeedOptions, storeConfigs); | ||
46 | } | ||
47 | |||
48 | @ParameterizedTest(name = title) | ||
49 | @MethodSource | ||
50 | @Tag("fuzz") | ||
51 | @Tag("slow") | ||
52 | void parametrizedSlowFuzz(int ignoredTests, int steps, int noKeys, int noValues, boolean nullDefault, | ||
53 | int commitFrequency, int seed, VersionedMapStoreBuilder<Integer, String> builder) { | ||
54 | runFuzzTest("SingleThreadS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, noKeys, noValues, | ||
55 | nullDefault, commitFrequency, builder); | ||
56 | } | ||
57 | |||
58 | static Stream<Arguments> parametrizedSlowFuzz() { | ||
59 | return FuzzTestUtils.changeStepCount(RestoreFuzzTest.parametrizedFastFuzz(), 1); | ||
60 | } | ||
61 | } | ||