CavalliumDBEngine/src/test/java/it/cavallium/dbengine/tests/TestDictionaryMapDeep.java

1121 lines
39 KiB
Java
Raw Normal View History

2023-02-22 22:31:36 +01:00
package it.cavallium.dbengine.tests;
2021-05-02 19:18:15 +02:00
2023-02-22 22:31:36 +01:00
import static it.cavallium.dbengine.tests.DbTestUtils.BIG_STRING;
import static it.cavallium.dbengine.tests.DbTestUtils.ensureNoLeaks;
import static it.cavallium.dbengine.tests.DbTestUtils.isCIMode;
import static it.cavallium.dbengine.tests.DbTestUtils.run;
import static it.cavallium.dbengine.tests.DbTestUtils.runVoid;
import static it.cavallium.dbengine.tests.DbTestUtils.tempDatabaseMapDictionaryDeepMap;
import static it.cavallium.dbengine.tests.DbTestUtils.tempDictionary;
2021-05-02 19:18:15 +02:00
2023-02-22 22:31:36 +01:00
import com.google.common.collect.Streams;
2021-05-02 19:18:15 +02:00
import it.cavallium.dbengine.database.UpdateMode;
2021-12-18 18:16:56 +01:00
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap;
2023-02-22 22:31:36 +01:00
import java.io.IOException;
2021-05-02 19:18:15 +02:00
import java.util.Arrays;
2021-08-29 01:15:51 +02:00
import java.util.List;
2021-05-02 19:18:15 +02:00
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
2022-01-04 12:55:33 +01:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2021-08-28 22:42:51 +02:00
import org.junit.jupiter.api.AfterEach;
2021-09-23 11:30:44 +02:00
import org.junit.jupiter.api.Assertions;
2021-08-28 22:42:51 +02:00
import org.junit.jupiter.api.BeforeEach;
2021-08-29 01:15:51 +02:00
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.TestMethodOrder;
2021-05-02 19:18:15 +02:00
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
2021-08-29 01:15:51 +02:00
@TestMethodOrder(MethodOrderer.MethodName.class)
2021-09-06 01:15:13 +02:00
public abstract class TestDictionaryMapDeep {
2021-05-02 19:18:15 +02:00
2022-01-04 12:55:33 +01:00
private final Logger log = LogManager.getLogger(this.getClass());
2021-09-08 00:22:39 +02:00
private boolean checkLeaks = true;
2021-08-29 01:15:51 +02:00
2021-05-02 19:18:15 +02:00
private static boolean isTestBadKeysEnabled() {
2021-09-10 13:34:26 +02:00
return !isCIMode() && System.getProperty("badkeys", "true").equalsIgnoreCase("true");
2021-05-02 19:18:15 +02:00
}
2021-09-06 01:15:13 +02:00
protected abstract TemporaryDbGenerator getTempDbGenerator();
2021-05-02 19:18:15 +02:00
2023-02-22 22:31:36 +01:00
record Tuple2<X, Y>(X getT1, Y getT2) {}
2023-02-22 23:31:05 +01:00
record Tuple3<X, Y, Z>(X getT1, Y getT2, Z getT3) {}
record Tuple4<X, Y, Z, W>(X getT1, Y getT2, Z getT3, W getT4) {}
record Tuple5<X, Y, Z, W, X1>(X getT1, Y getT2, Z getT3, W getT4, X1 getT5) {}
2023-02-22 22:31:36 +01:00
2021-05-02 19:18:15 +02:00
private static Stream<Arguments> provideArgumentsSet() {
2021-05-03 21:41:51 +02:00
var goodKeys = Set.of("12345");
2021-05-02 19:18:15 +02:00
Set<String> badKeys;
if (isTestBadKeysEnabled()) {
2021-05-03 21:41:51 +02:00
badKeys = Set.of("", "aaaa", "aaaaaa");
2021-05-02 19:18:15 +02:00
} else {
badKeys = Set.of();
}
Set<Tuple2<String, Boolean>> keys = Stream.concat(
2023-02-22 22:31:36 +01:00
goodKeys.stream().map(s -> new Tuple2<>(s, false)),
badKeys.stream().map(s -> new Tuple2<>(s, true))
2021-05-02 19:18:15 +02:00
).collect(Collectors.toSet());
var values = Set.of(
2021-12-18 18:16:56 +01:00
new Object2ObjectLinkedOpenHashMap<>(Map.of("123456", "a", "234567", "")),
new Object2ObjectLinkedOpenHashMap<>(Map.of("123456", "\0", "234567", "\0\0", "345678", BIG_STRING))
2021-05-02 19:18:15 +02:00
);
return keys
.stream()
.flatMap(keyTuple -> {
2021-12-18 18:16:56 +01:00
Stream<Object2ObjectLinkedOpenHashMap<String, String>> strm;
2021-05-02 19:18:15 +02:00
if (keyTuple.getT2()) {
strm = values.stream().limit(1);
} else {
strm = values.stream();
}
2023-02-22 22:31:36 +01:00
return strm.map(val -> new Tuple3<>(keyTuple.getT1(), val, keyTuple.getT2()));
2021-05-02 19:18:15 +02:00
})
2023-02-22 22:31:36 +01:00
.flatMap(entryTuple -> Arrays.stream(UpdateMode.values()).map(updateMode -> new Tuple4<>(updateMode,
2021-05-02 19:18:15 +02:00
entryTuple.getT1(),
entryTuple.getT2(),
entryTuple.getT3()
)))
.map(fullTuple -> Arguments.of(fullTuple.getT1(), fullTuple.getT2(), fullTuple.getT3(), fullTuple.getT4()));
}
private static Stream<Arguments> provideArgumentsPut() {
2021-09-10 13:34:26 +02:00
var goodKeys1 = isCIMode() ? List.of("12345") : List.of("12345", "zebra");
2021-08-29 01:15:51 +02:00
List<String> badKeys1;
2021-05-02 19:18:15 +02:00
if (isTestBadKeysEnabled()) {
2021-08-29 01:15:51 +02:00
badKeys1 = List.of("", "a", "aaaa", "aaaaaa");
2021-05-02 19:18:15 +02:00
} else {
2021-08-29 01:15:51 +02:00
badKeys1 = List.of();
2021-05-02 19:18:15 +02:00
}
2021-09-10 13:34:26 +02:00
var goodKeys2 = isCIMode() ? List.of("123456") : List.of("123456", "anatra");
2021-08-29 01:15:51 +02:00
List<String> badKeys2;
2021-05-02 19:18:15 +02:00
if (isTestBadKeysEnabled()) {
2021-08-29 01:15:51 +02:00
badKeys2 = List.of("", "a", "aaaaa", "aaaaaaa");
2021-05-02 19:18:15 +02:00
} else {
2021-08-29 01:15:51 +02:00
badKeys2 = List.of();
2021-05-02 19:18:15 +02:00
}
2021-09-10 13:34:26 +02:00
var values = isCIMode() ? List.of("val") : List.of("a", "", "\0", "\0\0", "z", "azzszgzczqz", BIG_STRING);
2021-05-02 19:18:15 +02:00
2023-02-22 22:31:36 +01:00
Stream<Tuple4<String, String, String, Boolean>> failOnKeys1 = badKeys1.stream()
.map(badKey1 -> new Tuple4<>(
2021-05-02 19:18:15 +02:00
badKey1,
2021-08-29 01:15:51 +02:00
goodKeys2.stream().findFirst().orElseThrow(),
values.stream().findFirst().orElseThrow(),
2021-05-02 19:18:15 +02:00
true
));
2023-02-22 22:31:36 +01:00
Stream<Tuple4<String, String, String, Boolean>> failOnKeys2 = badKeys2.stream()
.map(badKey2 -> new Tuple4<>(
2021-08-29 01:15:51 +02:00
goodKeys1.stream().findFirst().orElseThrow(),
2021-05-02 19:18:15 +02:00
badKey2,
2021-08-29 01:15:51 +02:00
values.stream().findFirst().orElseThrow(),
2021-05-02 19:18:15 +02:00
true
));
2023-02-22 22:31:36 +01:00
Stream<Tuple4<String, String, String, Boolean>> goodKeys1And2 = values.stream()
.map(value -> new Tuple4<>(
2021-08-29 01:15:51 +02:00
goodKeys1.stream().findFirst().orElseThrow(),
goodKeys2.stream().findFirst().orElseThrow(),
2021-05-02 19:18:15 +02:00
value,
false
));
2023-02-22 22:31:36 +01:00
Stream<Tuple4<String, String, String, Boolean>> keys1And2 = Streams.concat(
2021-05-02 19:18:15 +02:00
goodKeys1And2,
failOnKeys1,
failOnKeys2
);
return keys1And2
2023-02-22 22:31:36 +01:00
.flatMap(entryTuple -> Stream.of(UpdateMode.values())
.map(updateMode -> new Tuple5<>(updateMode,
2021-05-02 19:18:15 +02:00
entryTuple.getT1(),
entryTuple.getT2(),
entryTuple.getT3(),
entryTuple.getT4()
))
)
.map(fullTuple -> Arguments.of(fullTuple.getT1(),
fullTuple.getT2(),
fullTuple.getT3(),
fullTuple.getT4(),
fullTuple.getT5()
))
2021-08-29 01:15:51 +02:00
.sequential();
2021-05-02 19:18:15 +02:00
}
2021-08-28 22:42:51 +02:00
@BeforeEach
public void beforeEach() {
2023-02-22 22:31:36 +01:00
ensureNoLeaks(false, false);
2021-08-28 22:42:51 +02:00
}
@AfterEach
public void afterEach() {
2021-09-10 13:42:02 +02:00
if (!isCIMode() && checkLeaks) {
2023-02-22 22:31:36 +01:00
ensureNoLeaks(true, false);
2021-09-08 00:22:39 +02:00
}
2021-08-28 22:42:51 +02:00
}
2021-05-02 19:18:15 +02:00
@ParameterizedTest
@MethodSource("provideArgumentsSet")
2021-12-18 18:16:56 +01:00
public void testPutValue(UpdateMode updateMode,
String key,
Object2ObjectSortedMap<String, String> value,
2023-02-22 22:31:36 +01:00
boolean shouldFail) throws IOException {
2021-09-23 11:30:44 +02:00
var gen = getTempDbGenerator();
2023-02-22 22:31:36 +01:00
var db = gen.openTempDb();
var dict = tempDictionary(db.db(), updateMode);
2021-09-23 11:30:44 +02:00
var map = tempDatabaseMapDictionaryDeepMap(dict, 5, 6);
log.debug("Put \"{}\" = \"{}\"", key, value);
2023-02-22 22:31:36 +01:00
runVoid(shouldFail, () -> map.putValue(key, value));
2021-09-23 11:30:44 +02:00
2023-02-22 22:31:36 +01:00
var resultingMapSize = map.leavesCount(null, false);
2021-09-23 11:30:44 +02:00
Assertions.assertEquals(shouldFail ? 0 : value.size(), resultingMapSize);
2023-02-22 22:31:36 +01:00
var resultingMap = map.get(null);
2021-09-23 11:30:44 +02:00
Assertions.assertEquals(shouldFail ? null : Map.of(key, value), resultingMap);
gen.closeTempDb(db);
}
@ParameterizedTest
@MethodSource("provideArgumentsSet")
2021-12-18 18:16:56 +01:00
public void testGetValue(UpdateMode updateMode,
String key,
Object2ObjectSortedMap<String, String> value,
2023-02-22 22:31:36 +01:00
boolean shouldFail) throws IOException {
2021-09-23 11:30:44 +02:00
var gen = getTempDbGenerator();
2023-02-22 22:31:36 +01:00
var db = gen.openTempDb();
var dict = tempDictionary(db.db(), updateMode);
2021-09-23 11:30:44 +02:00
var map = tempDatabaseMapDictionaryDeepMap(dict, 5, 6);
log.debug("Put \"{}\" = \"{}\"", key, value);
2023-02-22 22:31:36 +01:00
runVoid(shouldFail, () -> map.putValue(key, value));
2021-09-23 11:30:44 +02:00
log.debug("Get \"{}\"", key);
2023-02-22 22:31:36 +01:00
var returnedValue = run(shouldFail, () -> map.getValue(null, key));
2021-09-23 11:30:44 +02:00
Assertions.assertEquals(shouldFail ? null : value, returnedValue);
gen.closeTempDb(db);
2021-05-02 19:18:15 +02:00
}
2023-02-22 22:31:36 +01:00
/*
2021-05-02 19:18:15 +02:00
@ParameterizedTest
@MethodSource("provideArgumentsSet")
2021-12-18 18:16:56 +01:00
public void testSetValueGetAllValues(UpdateMode updateMode, String key, Object2ObjectSortedMap<String, String> value,
2021-05-02 19:18:15 +02:00
boolean shouldFail) {
var stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> map
.putValue(key, value)
2022-03-24 23:56:23 +01:00
.thenMany(map.getAllValues(null, false))
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
stpVer.expectNext(Map.entry(key, value)).verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSet")
2021-12-18 18:16:56 +01:00
public void testAtSetGetAllStagesGetAllValues(UpdateMode updateMode,
String key,
Object2ObjectSortedMap<String, String> value,
2021-09-24 01:59:56 +02:00
boolean shouldFail) {
2021-05-02 19:18:15 +02:00
var remainingEntries = new ConcurrentHashMap<Tuple3<String, String, String>, Boolean>().keySet(true);
Step<Tuple3<String, String, String>> stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
2021-09-02 21:14:26 +02:00
.flatMapMany(map_ -> Flux.using(
() -> map_,
map -> map
2021-05-02 19:18:15 +02:00
.at(null, key)
2021-09-02 21:14:26 +02:00
.flatMap(v_ -> Mono.using(
() -> v_,
v -> v.set(value),
2022-07-19 23:45:39 +02:00
SimpleResource::close
2021-09-02 21:14:26 +02:00
))
2021-05-02 19:18:15 +02:00
.then(map
.at(null, "capra")
2021-09-02 21:14:26 +02:00
.flatMap(v_ -> Mono.using(
() -> v_,
2021-12-18 18:16:56 +01:00
v -> v.set(new Object2ObjectLinkedOpenHashMap<>(Map.of("normal", "123", "ormaln", "456"))),
2022-07-19 23:45:39 +02:00
SimpleResource::close
2021-09-02 21:14:26 +02:00
))
2021-05-02 19:18:15 +02:00
)
.thenMany(map
2022-03-24 23:56:23 +01:00
.getAllStages(null, false)
2021-05-02 19:18:15 +02:00
.flatMap(v -> v.getValue()
2022-03-24 23:56:23 +01:00
.getAllValues(null, false)
2023-02-22 22:31:36 +01:00
.map(result -> new Tuple2<>(v.getKey(), result.getKey(), result.getValue()))
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.getValue().close())
2021-05-02 19:18:15 +02:00
)
2021-09-02 21:14:26 +02:00
),
2022-07-19 23:45:39 +02:00
SimpleResource::close
2021-09-02 21:14:26 +02:00
))
2021-05-02 19:18:15 +02:00
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
2023-02-22 22:31:36 +01:00
value.forEach((k, v) -> remainingEntries.add(new Tuple2<>(key, k, v)));
remainingEntries.add(new Tuple2<>("capra", "normal", "123"));
remainingEntries.add(new Tuple2<>("capra", "ormaln", "456"));
2021-05-02 19:18:15 +02:00
for (Tuple3<String, String, String> ignored : remainingEntries) {
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
}
stpVer.verifyComplete();
assert remainingEntries.isEmpty();
}
}
@ParameterizedTest
2021-08-29 01:15:51 +02:00
@MethodSource({"provideArgumentsPut"})
2021-09-24 01:59:56 +02:00
public void testAtPutValueAtGetValue(UpdateMode updateMode, String key1, String key2, String value,
boolean shouldFail) {
2021-05-02 19:18:15 +02:00
var stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMap(map -> map
2021-09-24 01:59:56 +02:00
.at(null, key1)
.flatMap(v -> v
.putValue(key2, value)
.doFinally(s -> v.close())
)
.then(map
.at(null, key1)
.flatMap(v -> v
.getValue(null, key2)
.doFinally(s -> v.close())
)
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
stpVer.expectNext(value).verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSet")
2021-12-18 18:16:56 +01:00
public void testSetAndGetPrevious(UpdateMode updateMode,
String key,
Object2ObjectSortedMap<String, String> value,
boolean shouldFail) {
2021-05-02 19:18:15 +02:00
var stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
2021-09-24 01:59:56 +02:00
.concat
(map
2021-12-18 18:16:56 +01:00
.putValueAndGetPrevious(key, new Object2ObjectLinkedOpenHashMap<>(Map.of("error?", "error.")))
.defaultIfEmpty(new Object2ObjectLinkedOpenHashMap<>(Map.of("nothing", "nothing"))),
2021-05-02 19:18:15 +02:00
map.putValueAndGetPrevious(key, value),
map.putValueAndGetPrevious(key, value)
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
2021-12-18 18:16:56 +01:00
stpVer
.expectNext(new Object2ObjectLinkedOpenHashMap<>(Map.of("nothing", "nothing")),
new Object2ObjectLinkedOpenHashMap<>(Map.of("error?", "error."))
)
.expectNext(value)
.verifyComplete();
2021-05-02 19:18:15 +02:00
}
}
@ParameterizedTest
@MethodSource("provideArgumentsPut")
2021-09-24 01:59:56 +02:00
public void testAtPutValueAndGetPrevious(UpdateMode updateMode, String key1, String key2, String value,
boolean shouldFail) {
2021-05-02 19:18:15 +02:00
var stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map
.at(null, key1)
.flatMap(v -> v
.putValueAndGetPrevious(key2, "error?")
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
),
map
.at(null, key1)
.flatMap(v -> v
.putValueAndGetPrevious(key2, value)
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
),
map
.at(null, key1)
.flatMap(v -> v
.putValueAndGetPrevious(key2, value)
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
)
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
stpVer.expectNext("error?", value).verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSet")
2021-12-18 18:16:56 +01:00
public void testSetValueRemoveAndGetPrevious(UpdateMode updateMode,
String key,
Object2ObjectSortedMap<String, String> value,
2021-09-24 01:59:56 +02:00
boolean shouldFail) {
2021-05-02 19:18:15 +02:00
var stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map.removeAndGetPrevious(key),
map.putValue(key, value).then(map.removeAndGetPrevious(key)),
map.removeAndGetPrevious(key)
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
stpVer.expectNext(value).verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsPut")
2021-09-24 01:59:56 +02:00
public void testAtPutValueRemoveAndGetPrevious(UpdateMode updateMode, String key1, String key2, String value,
boolean shouldFail) {
2021-05-02 19:18:15 +02:00
var stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map
.at(null, key1)
.flatMap(v -> v
.putValue(key2, "error?")
.then(v.removeAndGetPrevious(key2))
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
),
map
.at(null, key1)
.flatMap(v -> v
.putValue(key2, value)
.then(v.removeAndGetPrevious(key2))
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
),
map
.at(null, key1)
.flatMap(v -> v.removeAndGetPrevious(key2)
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
)
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
stpVer.expectNext("error?", value).verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSet")
2021-12-18 18:16:56 +01:00
public void testSetValueRemoveAndGetStatus(UpdateMode updateMode,
String key,
Object2ObjectSortedMap<String, String> value,
2021-09-24 01:59:56 +02:00
boolean shouldFail) {
2021-05-02 19:18:15 +02:00
var stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map.removeAndGetStatus(key),
map.putValue(key, value).then(map.removeAndGetStatus(key)),
map.removeAndGetStatus(key)
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
stpVer.expectNext(false, true, false).verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsPut")
2021-09-24 01:59:56 +02:00
public void testAtPutValueRemoveAndGetStatus(UpdateMode updateMode, String key1, String key2, String value,
boolean shouldFail) {
2021-05-02 19:18:15 +02:00
var stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map
.at(null, key1)
.flatMap(v -> v
.putValue(key2, "error?")
.then(v.removeAndGetStatus(key2))
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
),
map
.at(null, key1)
.flatMap(v -> v
.putValue(key2, value)
.then(v.removeAndGetStatus(key2))
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
),
map
.at(null, key1)
.flatMap(v -> v.removeAndGetStatus(key2)
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
)
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
stpVer.expectNext(true, true, false).verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSet")
2021-12-18 18:16:56 +01:00
public void testUpdate(UpdateMode updateMode,
String key,
Object2ObjectSortedMap<String, String> value,
boolean shouldFail) {
2021-05-02 19:18:15 +02:00
if (updateMode != UpdateMode.ALLOW_UNSAFE && !isTestBadKeysEnabled()) {
return;
}
var stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map.updateValue(key, old -> {
assert old == null;
2021-12-18 18:16:56 +01:00
return new Object2ObjectLinkedOpenHashMap<>(Map.of("error?", "error."));
2021-05-02 19:18:15 +02:00
}),
2022-03-02 18:33:58 +01:00
map.updateValue(key, old -> {
2021-05-02 19:18:15 +02:00
assert Objects.equals(old, Map.of("error?", "error."));
2021-12-18 18:16:56 +01:00
return new Object2ObjectLinkedOpenHashMap<>(Map.of("error?", "error."));
2021-05-02 19:18:15 +02:00
}),
2022-03-02 18:33:58 +01:00
map.updateValue(key, old -> {
2021-05-02 19:18:15 +02:00
assert Objects.equals(old, Map.of("error?", "error."));
2021-12-18 18:16:56 +01:00
return new Object2ObjectLinkedOpenHashMap<>(Map.of("error?", "error."));
2021-05-02 19:18:15 +02:00
}),
2022-03-02 18:33:58 +01:00
map.updateValue(key, old -> {
2021-05-02 19:18:15 +02:00
assert Objects.equals(old, Map.of("error?", "error."));
return value;
}),
2022-03-02 18:33:58 +01:00
map.updateValue(key, old -> {
2021-05-02 19:18:15 +02:00
assert Objects.equals(old, value);
return value;
})
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (updateMode != UpdateMode.ALLOW_UNSAFE || shouldFail) {
stpVer.verifyError();
} else {
stpVer.expectNext(true, false, false, true, false).verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsPut")
public void testAtUpdate(UpdateMode updateMode, String key1, String key2, String value, boolean shouldFail) {
if (updateMode == UpdateMode.DISALLOW && !isTestBadKeysEnabled()) {
return;
}
var stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map
.at(null, key1)
.flatMap(v -> v
.updateValue(key2, prev -> prev)
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
),
map
.at(null, key1)
.flatMap(v -> v
.updateValue(key2, prev -> value)
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
),
map
.at(null, key1)
.flatMap(v -> v
.updateValue(key2, prev -> value)
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
),
map
.at(null, key1)
.flatMap(v -> v
.updateValue(key2, prev -> null)
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
)
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (updateMode == UpdateMode.DISALLOW || shouldFail) {
stpVer.verifyError();
} else {
stpVer.expectNext(false, true, false, true).verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSet")
2021-12-18 18:16:56 +01:00
public void testUpdateGet(UpdateMode updateMode,
String key,
Object2ObjectSortedMap<String, String> value,
boolean shouldFail) {
2021-05-02 19:18:15 +02:00
if (updateMode != UpdateMode.ALLOW_UNSAFE && !isTestBadKeysEnabled()) {
return;
}
2021-09-06 01:15:13 +02:00
var stpVer = StepVerifier.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-08-28 22:42:51 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux.concat(
map.updateValue(key, old -> {
assert old == null;
2021-12-18 18:16:56 +01:00
return new Object2ObjectLinkedOpenHashMap<>(Map.of("error?", "error."));
2021-08-28 22:42:51 +02:00
}).then(map.getValue(null, key)),
2022-03-02 18:33:58 +01:00
map.updateValue(key, old -> {
2021-08-28 22:42:51 +02:00
assert Objects.equals(old, Map.of("error?", "error."));
2021-12-18 18:16:56 +01:00
return new Object2ObjectLinkedOpenHashMap<>(Map.of("error?", "error."));
2021-08-28 22:42:51 +02:00
}).then(map.getValue(null, key)),
2022-03-02 18:33:58 +01:00
map.updateValue(key, old -> {
2021-08-28 22:42:51 +02:00
assert Objects.equals(old, Map.of("error?", "error."));
2021-12-18 18:16:56 +01:00
return new Object2ObjectLinkedOpenHashMap<>(Map.of("error?", "error."));
2021-08-28 22:42:51 +02:00
}).then(map.getValue(null, key)),
2022-03-02 18:33:58 +01:00
map.updateValue(key, old -> {
2021-12-18 18:16:56 +01:00
assert Objects.equals(old, new Object2ObjectLinkedOpenHashMap<>(Map.of("error?", "error.")));
2021-08-28 22:42:51 +02:00
return value;
}).then(map.getValue(null, key)),
2022-03-02 18:33:58 +01:00
map.updateValue(key, old -> {
2021-08-28 22:42:51 +02:00
assert Objects.equals(old, value);
return value;
}).then(map.getValue(null, key))
2021-09-23 20:57:28 +02:00
).doFinally(s -> map.close()))
2021-08-28 22:42:51 +02:00
));
2021-05-02 19:18:15 +02:00
if (updateMode != UpdateMode.ALLOW_UNSAFE || shouldFail) {
stpVer.verifyError();
} else {
2021-09-24 01:59:56 +02:00
stpVer
2021-12-18 18:16:56 +01:00
.expectNext(new Object2ObjectLinkedOpenHashMap<>(Map.of("error?", "error.")),
new Object2ObjectLinkedOpenHashMap<>(Map.of("error?", "error.")),
new Object2ObjectLinkedOpenHashMap<>(Map.of("error?", "error.")),
value,
value
)
2021-09-24 01:59:56 +02:00
.verifyComplete();
2021-05-02 19:18:15 +02:00
}
}
@ParameterizedTest
@MethodSource("provideArgumentsPut")
public void testAtUpdateGetValue(UpdateMode updateMode, String key1, String key2, String value, boolean shouldFail) {
if (updateMode == UpdateMode.DISALLOW && !isTestBadKeysEnabled()) {
return;
}
var stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map
.at(null, key1)
.flatMap(v -> v
.updateValue(key2, prev -> prev)
.then(v.getValue(null, key2))
.defaultIfEmpty("empty")
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
),
map
.at(null, key1)
.flatMap(v -> v
.updateValue(key2, prev -> value)
.then(v.getValue(null, key2))
.defaultIfEmpty("empty")
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
),
map
.at(null, key1)
.flatMap(v -> v
.updateValue(key2, prev -> value)
.then(v.getValue(null, key2))
.defaultIfEmpty("empty")
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
),
map
.at(null, key1)
.flatMap(v -> v
.updateValue(key2, prev -> null)
.then(v.getValue(null, key2))
.defaultIfEmpty("empty")
2021-09-23 20:57:28 +02:00
.doFinally(s -> v.close())
2021-05-02 19:18:15 +02:00
)
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (updateMode == UpdateMode.DISALLOW || shouldFail) {
stpVer.verifyError();
} else {
stpVer.expectNext("empty", value, value, "empty").verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSet")
2021-12-18 18:16:56 +01:00
public void testSetAndGetChanged(UpdateMode updateMode,
String key,
Object2ObjectSortedMap<String, String> value,
boolean shouldFail) {
2021-05-02 19:18:15 +02:00
var stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
2021-12-18 18:16:56 +01:00
map.putValueAndGetChanged(key, new Object2ObjectLinkedOpenHashMap<>(Map.of("error?", "error."))).single(),
2021-05-02 19:18:15 +02:00
map.putValueAndGetChanged(key, value).single(),
map.putValueAndGetChanged(key, value).single(),
map.remove(key),
2021-12-18 18:16:56 +01:00
map.putValueAndGetChanged(key, new Object2ObjectLinkedOpenHashMap<>(Map.of("error?", "error."))).single()
2021-05-02 19:18:15 +02:00
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
stpVer.expectNext(true, true, false, true).verifyComplete();
}
}
private static Stream<Arguments> provideArgumentsSetMulti() {
2021-09-10 13:34:26 +02:00
var goodKeys = isCIMode() ? List.of(List.of("12345")) : List.of(List.of("12345", "67890"), List.<String>of());
2021-08-29 01:15:51 +02:00
List<List<String>> badKeys;
2021-05-02 19:18:15 +02:00
if (isTestBadKeysEnabled()) {
2021-08-29 01:15:51 +02:00
badKeys = List.of(List.of("", "12345"), List.of("45678", "aaaa"), List.of("aaaaaa", "capra"));
2021-05-02 19:18:15 +02:00
} else {
2021-08-29 01:15:51 +02:00
badKeys = List.of();
2021-05-02 19:18:15 +02:00
}
2021-12-18 18:16:56 +01:00
List<Tuple2<List<String>, Boolean>> keys = Stream
2023-02-22 22:31:36 +01:00
.concat(goodKeys.stream().map(s -> new Tuple2<>(s, false)), badKeys.stream().map(s -> new Tuple2<>(s, true)))
2021-12-18 18:16:56 +01:00
.toList();
var values = isCIMode() ? List.of(new Object2ObjectLinkedOpenHashMap<>(Map.of("123456", "val"))) : List.of(
new Object2ObjectLinkedOpenHashMap<>(Map.of("123456", "a", "234567", "")),
new Object2ObjectLinkedOpenHashMap<>(Map.of("123456", "\0", "234567", "\0\0", "345678", BIG_STRING))
2021-05-02 19:18:15 +02:00
);
return keys
.stream()
.map(keyTuple -> keyTuple.mapT1(ks -> Flux
.zip(Flux.fromIterable(ks), Flux.fromIterable(values))
2021-12-18 18:16:56 +01:00
.collectMap(Tuple2::getT1, Tuple2::getT2, Object2ObjectLinkedOpenHashMap::new)
2021-05-02 19:18:15 +02:00
.block()
))
2023-02-22 22:31:36 +01:00
.flatMap(entryTuple -> Arrays.stream(UpdateMode.values()).map(updateMode -> new Tuple2<>(updateMode,
2021-05-02 19:18:15 +02:00
entryTuple.getT1(),
entryTuple.getT2()
)))
.map(fullTuple -> Arguments.of(fullTuple.getT1(), fullTuple.getT2(), fullTuple.getT3()));
}
@ParameterizedTest
@MethodSource("provideArgumentsSetMulti")
2021-12-18 18:16:56 +01:00
public void testSetMultiGetMulti(UpdateMode updateMode,
Map<String, Object2ObjectSortedMap<String, String>> entries,
2021-09-24 01:59:56 +02:00
boolean shouldFail) {
2021-12-12 23:40:30 +01:00
var flux = tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
2021-11-08 10:49:59 +01:00
.flatMapMany(map -> {
var entriesFlux = Flux.fromIterable(entries.entrySet());
var keysFlux = entriesFlux.map(Entry::getKey);
var resultsFlux = Flux
.concat(
map.putMulti(entriesFlux).then(Mono.empty()),
map.getMulti(null, keysFlux)
);
return Flux.zip(keysFlux, resultsFlux, Map::entry).doFinally(s -> map.close());
})
2021-07-23 15:20:33 +02:00
.filter(k -> k.getValue().isPresent())
.map(k -> Map.entry(k.getKey(), k.getValue().orElseThrow()))
2021-12-12 23:40:30 +01:00
);
2021-05-02 19:18:15 +02:00
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-12-12 23:40:30 +01:00
StepVerifier.create(flux).verifyError();
2021-05-02 19:18:15 +02:00
} else {
2021-12-12 23:40:30 +01:00
var elements = flux.collect(Collectors.toList()).block();
assertThat(elements).containsExactlyInAnyOrderElementsOf(entries.entrySet());
2021-05-02 19:18:15 +02:00
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSetMulti")
2021-12-18 18:16:56 +01:00
public void testSetAllValuesGetMulti(UpdateMode updateMode,
Object2ObjectSortedMap<String, Object2ObjectSortedMap<String, String>> entries,
2021-09-24 01:59:56 +02:00
boolean shouldFail) {
2021-05-02 19:18:15 +02:00
var remainingEntries = new ConcurrentHashMap<Entry<String, Map<String, String>>, Boolean>().keySet(true);
Step<Entry<String, Map<String, String>>> stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
2021-11-08 10:49:59 +01:00
.flatMapMany(map -> {
var entriesFlux = Flux.fromIterable(entries.entrySet());
var keysFlux = entriesFlux.map(Entry::getKey);
var resultsFlux = map
.setAllValues(Flux.fromIterable(entries.entrySet()))
.thenMany(map.getMulti(null, Flux.fromIterable(entries.keySet())));
return Flux.zip(keysFlux, resultsFlux, Map::entry).doFinally(s -> map.close());
})
2021-07-23 15:20:33 +02:00
.filter(k -> k.getValue().isPresent())
.map(k -> Map.entry(k.getKey(), k.getValue().orElseThrow()))
2021-05-02 19:18:15 +02:00
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
for (Entry<String, Map<String, String>> ignored : remainingEntries) {
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
}
stpVer.verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSetMulti")
2021-12-18 18:16:56 +01:00
public void testSetAllValuesAndGetPrevious(UpdateMode updateMode, Object2ObjectSortedMap<String, Object2ObjectSortedMap<String, String>> entries,
2021-09-24 01:59:56 +02:00
boolean shouldFail) {
2021-12-18 18:16:56 +01:00
var remainingEntries = new ConcurrentHashMap<Entry<String, Object2ObjectSortedMap<String, String>>, Boolean>().keySet(true);
Step<Entry<String, Object2ObjectSortedMap<String, String>>> stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map.setAllValuesAndGetPrevious(Flux.fromIterable(entries.entrySet())),
map.setAllValuesAndGetPrevious(Flux.fromIterable(entries.entrySet()))
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
2021-12-18 18:16:56 +01:00
for (Entry<String, Object2ObjectSortedMap<String, String>> ignored : remainingEntries) {
2021-05-02 19:18:15 +02:00
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
}
stpVer.verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSetMulti")
2021-12-18 18:16:56 +01:00
public void testSetGetMulti(UpdateMode updateMode, Object2ObjectSortedMap<String, Object2ObjectSortedMap<String, String>> entries, boolean shouldFail) {
var remainingEntries = new ConcurrentHashMap<Entry<String, Object2ObjectSortedMap<String, String>>, Boolean>().keySet(true);
Step<Entry<String, Object2ObjectSortedMap<String, String>>> stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
2021-11-08 10:49:59 +01:00
.flatMapMany(map -> {
var entriesFlux = Flux.fromIterable(entries.entrySet());
var keysFlux = entriesFlux.map(Entry::getKey);
var resultsFlux = Flux
.concat(
map.set(entries).then(Mono.empty()),
map.getMulti(null, Flux.fromIterable(entries.keySet()))
);
return Flux.zip(keysFlux, resultsFlux, Map::entry).doFinally(s -> map.close());
})
2021-07-23 15:20:33 +02:00
.filter(k -> k.getValue().isPresent())
.map(k -> Map.entry(k.getKey(), k.getValue().orElseThrow()))
2021-05-02 19:18:15 +02:00
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
2021-12-18 18:16:56 +01:00
for (Entry<String, Object2ObjectSortedMap<String, String>> ignored : remainingEntries) {
2021-05-02 19:18:15 +02:00
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
}
stpVer.verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSetMulti")
2021-12-18 18:16:56 +01:00
public void testSetAndGetStatus(UpdateMode updateMode, Object2ObjectSortedMap<String, Object2ObjectSortedMap<String, String>> entries,
2021-09-24 01:59:56 +02:00
boolean shouldFail) {
2021-05-02 19:18:15 +02:00
Step<Boolean> stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> {
Mono<Void> removalMono;
if (entries.isEmpty()) {
removalMono = Mono.empty();
} else {
removalMono = map.remove(entries.keySet().stream().findAny().orElseThrow());
}
return Flux
.concat(
map.setAndGetChanged(entries).single(),
map.setAndGetChanged(entries).single(),
removalMono.then(Mono.empty()),
map.setAndGetChanged(entries).single()
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close());
2021-05-02 19:18:15 +02:00
})
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
stpVer.expectNext(!entries.isEmpty(), false, !entries.isEmpty()).verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSetMulti")
2021-12-18 18:16:56 +01:00
public void testSetAndGetPrevious(UpdateMode updateMode, Object2ObjectSortedMap<String, Object2ObjectSortedMap<String, String>> entries,
2021-09-24 01:59:56 +02:00
boolean shouldFail) {
2021-12-18 18:16:56 +01:00
var remainingEntries = new ConcurrentHashMap<Entry<String, Object2ObjectSortedMap<String, String>>, Boolean>().keySet(true);
Step<Entry<String, Object2ObjectSortedMap<String, String>>> stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map.setAndGetPrevious(entries),
map.setAndGetPrevious(entries)
)
.map(Map::entrySet)
2021-07-31 18:00:53 +02:00
.concatMapIterable(list -> list)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
2021-12-18 18:16:56 +01:00
for (Entry<String, Object2ObjectSortedMap<String, String>> ignored : remainingEntries) {
2021-05-02 19:18:15 +02:00
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
}
stpVer.verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSetMulti")
2021-12-18 18:16:56 +01:00
public void testSetClearAndGetPreviousGet(UpdateMode updateMode, Object2ObjectSortedMap<String, Object2ObjectSortedMap<String, String>> entries,
2021-09-24 01:59:56 +02:00
boolean shouldFail) {
2021-12-18 18:16:56 +01:00
var remainingEntries = new ConcurrentHashMap<Entry<String, Object2ObjectSortedMap<String, String>>, Boolean>().keySet(true);
Step<Entry<String, Object2ObjectSortedMap<String, String>>> stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(map.set(entries).then(Mono.empty()), map.clearAndGetPrevious(), map.get(null))
.map(Map::entrySet)
2021-07-31 18:00:53 +02:00
.concatMapIterable(list -> list)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
2021-12-18 18:16:56 +01:00
for (Entry<String, Object2ObjectSortedMap<String, String>> ignored : remainingEntries) {
2021-05-02 19:18:15 +02:00
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
}
stpVer.verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSetMulti")
2021-12-18 18:16:56 +01:00
public void testSetMultiGetAllValues(UpdateMode updateMode, Object2ObjectSortedMap<String, Object2ObjectSortedMap<String, String>> entries,
2021-09-24 01:59:56 +02:00
boolean shouldFail) {
2021-12-18 18:16:56 +01:00
var remainingEntries = new ConcurrentHashMap<Entry<String, Object2ObjectSortedMap<String, String>>, Boolean>().keySet(true);
Step<Entry<String, Object2ObjectSortedMap<String, String>>> stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map.putMulti(Flux.fromIterable(entries.entrySet())).then(Mono.empty()),
2022-03-24 23:56:23 +01:00
map.getAllValues(null, false)
2021-05-02 19:18:15 +02:00
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
2021-12-18 18:16:56 +01:00
for (Entry<String, Object2ObjectSortedMap<String, String>> ignored : remainingEntries) {
2021-05-02 19:18:15 +02:00
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
}
stpVer.verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSetMulti")
2021-12-18 18:16:56 +01:00
public void testSetMultiGet(UpdateMode updateMode, Object2ObjectSortedMap<String, Object2ObjectSortedMap<String, String>> entries, boolean shouldFail) {
var remainingEntries = new ConcurrentHashMap<Entry<String, Object2ObjectSortedMap<String, String>>, Boolean>().keySet(true);
Step<Entry<String, Object2ObjectSortedMap<String, String>>> stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map.putMulti(Flux.fromIterable(entries.entrySet())).then(Mono.empty()),
map.get(null)
.map(Map::entrySet)
2021-07-31 18:00:53 +02:00
.flatMapIterable(list -> list)
2021-05-02 19:18:15 +02:00
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
2021-12-18 18:16:56 +01:00
for (Entry<String, Object2ObjectSortedMap<String, String>> ignored : remainingEntries) {
2021-05-02 19:18:15 +02:00
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
}
stpVer.verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSetMulti")
2021-12-18 18:16:56 +01:00
public void testSetMultiGetAllStagesGet(UpdateMode updateMode, Object2ObjectSortedMap<String, Object2ObjectSortedMap<String, String>> entries,
2021-09-24 01:59:56 +02:00
boolean shouldFail) {
2021-12-18 18:16:56 +01:00
var remainingEntries = new ConcurrentHashMap<Entry<String, Object2ObjectSortedMap<String, String>>, Boolean>().keySet(true);
Step<Entry<String, Object2ObjectSortedMap<String, String>>> stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map.putMulti(Flux.fromIterable(entries.entrySet())).then(Mono.empty()),
map
2022-03-24 23:56:23 +01:00
.getAllStages(null, false)
2021-05-02 19:18:15 +02:00
.flatMap(stage -> stage
.getValue()
.get(null)
.map(val -> Map.entry(stage.getKey(), val))
2021-09-23 20:57:28 +02:00
.doFinally(s -> stage.getValue().close())
2021-05-02 19:18:15 +02:00
)
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.verifyError();
} else {
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
2021-12-18 18:16:56 +01:00
for (Entry<String, Object2ObjectSortedMap<String, String>> ignored : remainingEntries) {
2021-05-02 19:18:15 +02:00
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
}
stpVer.verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSetMulti")
2021-12-18 18:16:56 +01:00
public void testSetMultiIsEmpty(UpdateMode updateMode, Object2ObjectSortedMap<String, Object2ObjectSortedMap<String, String>> entries,
2021-09-24 01:59:56 +02:00
boolean shouldFail) {
2021-05-02 19:18:15 +02:00
Step<Boolean> stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map.isEmpty(null),
map.putMulti(Flux.fromIterable(entries.entrySet())).then(Mono.empty()),
map.isEmpty(null)
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.expectNext(true).verifyError();
} else {
stpVer.expectNext(true, entries.isEmpty()).verifyComplete();
}
}
@ParameterizedTest
@MethodSource("provideArgumentsSetMulti")
2021-12-18 18:16:56 +01:00
public void testSetMultiClear(UpdateMode updateMode, Object2ObjectSortedMap<String, Object2ObjectSortedMap<String, String>> entries, boolean shouldFail) {
2021-05-02 19:18:15 +02:00
Step<Boolean> stpVer = StepVerifier
2021-09-06 01:15:13 +02:00
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
2021-05-02 19:18:15 +02:00
.map(dict -> tempDatabaseMapDictionaryDeepMap(dict, 5, 6))
.flatMapMany(map -> Flux
.concat(
map.isEmpty(null),
map.putMulti(Flux.fromIterable(entries.entrySet())).then(Mono.empty()),
map.isEmpty(null),
map.clear().then(Mono.empty()),
map.isEmpty(null)
)
2021-09-23 20:57:28 +02:00
.doFinally(s -> map.close())
2021-05-02 19:18:15 +02:00
)
));
if (shouldFail) {
2021-09-08 00:22:39 +02:00
this.checkLeaks = false;
2021-05-02 19:18:15 +02:00
stpVer.expectNext(true).verifyError();
} else {
stpVer.expectNext(true, entries.isEmpty(), true).verifyComplete();
}
}
2023-02-22 22:31:36 +01:00
*/
2021-05-02 19:18:15 +02:00
}