|
|
|
@ -1,18 +1,34 @@
|
|
|
|
|
package it.cavallium.dbengine.tests;
|
|
|
|
|
|
|
|
|
|
import static it.cavallium.dbengine.tests.DbTestUtils.*;
|
|
|
|
|
import static it.cavallium.dbengine.utils.StreamUtils.toListClose;
|
|
|
|
|
|
|
|
|
|
import com.google.common.collect.Streams;
|
|
|
|
|
import it.cavallium.dbengine.database.LLUtils;
|
|
|
|
|
import it.cavallium.dbengine.database.UpdateMode;
|
|
|
|
|
import it.cavallium.dbengine.utils.StreamUtils;
|
|
|
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap;
|
|
|
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMaps;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
|
import org.junit.jupiter.params.provider.Arguments;
|
|
|
|
|
import org.junit.jupiter.params.provider.MethodSource;
|
|
|
|
@ -147,50 +163,39 @@ public abstract class TestDictionaryMap {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@MethodSource("provideArgumentsPut")
|
|
|
|
|
public void testPutValueRemoveAndGetPrevious(MapType mapType, UpdateMode updateMode, String key, String value, boolean shouldFail) {
|
|
|
|
|
var stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.flatMapMany(map -> Flux
|
|
|
|
|
.concat(
|
|
|
|
|
map.removeAndGetPrevious(key),
|
|
|
|
|
map.putValue(key, value).then(map.removeAndGetPrevious(key)),
|
|
|
|
|
map.removeAndGetPrevious(key)
|
|
|
|
|
)
|
|
|
|
|
.doFinally(s -> map.close())
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
var stpVer = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
var x1 = map.removeAndGetPrevious(key);
|
|
|
|
|
map.putValue(key, value);
|
|
|
|
|
var x2 = map.removeAndGetPrevious(key);
|
|
|
|
|
var x3 = map.removeAndGetPrevious(key);
|
|
|
|
|
return Arrays.asList(x1, x2, x3);
|
|
|
|
|
}));
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
stpVer.expectNext(value).verifyComplete();
|
|
|
|
|
Assertions.assertEquals(Arrays.asList(null, value, null), stpVer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@MethodSource("provideArgumentsPut")
|
|
|
|
|
public void testPutValueRemoveAndGetStatus(MapType mapType, UpdateMode updateMode, String key, String value, boolean shouldFail) {
|
|
|
|
|
var stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.flatMapMany(map -> Flux
|
|
|
|
|
.concat(
|
|
|
|
|
map.removeAndGetStatus(key),
|
|
|
|
|
map.putValue(key, value).then(map.removeAndGetStatus(key)),
|
|
|
|
|
map.removeAndGetStatus(key)
|
|
|
|
|
)
|
|
|
|
|
.doFinally(s -> map.close())
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
var stpVer = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
var x1 = map.removeAndGetStatus(key);
|
|
|
|
|
map.putValue(key, value);
|
|
|
|
|
var x2 = map.removeAndGetStatus(key);
|
|
|
|
|
var x3 = map.removeAndGetStatus(key);
|
|
|
|
|
return Stream.of(x1, x2, x3).toList();
|
|
|
|
|
}));
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
stpVer.expectNext(false, true, false).verifyComplete();
|
|
|
|
|
Assertions.assertEquals(Arrays.asList(false, true, false), stpVer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -200,39 +205,27 @@ public abstract class TestDictionaryMap {
|
|
|
|
|
if (updateMode == UpdateMode.DISALLOW && !isTestBadKeysEnabled()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.flatMapMany(map -> Flux
|
|
|
|
|
.concat(
|
|
|
|
|
map.updateValue(key, old -> {
|
|
|
|
|
var stpVer = run(updateMode == UpdateMode.DISALLOW || shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
return Arrays.asList(map.updateValue(key, old -> {
|
|
|
|
|
Assertions.assertNull(old);
|
|
|
|
|
return "error?";
|
|
|
|
|
}),
|
|
|
|
|
map.updateValue(key, old -> {
|
|
|
|
|
}), map.updateValue(key, old -> {
|
|
|
|
|
Assertions.assertEquals("error?", old);
|
|
|
|
|
return "error?";
|
|
|
|
|
}),
|
|
|
|
|
map.updateValue(key, old -> {
|
|
|
|
|
}), map.updateValue(key, old -> {
|
|
|
|
|
Assertions.assertEquals("error?", old);
|
|
|
|
|
return "error?";
|
|
|
|
|
}),
|
|
|
|
|
map.updateValue(key, old -> {
|
|
|
|
|
}), map.updateValue(key, old -> {
|
|
|
|
|
Assertions.assertEquals("error?", old);
|
|
|
|
|
return value;
|
|
|
|
|
}),
|
|
|
|
|
map.updateValue(key, old -> {
|
|
|
|
|
}), map.updateValue(key, old -> {
|
|
|
|
|
Assertions.assertEquals(value, old);
|
|
|
|
|
return value;
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.doFinally(s -> map.close())
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
if (updateMode == UpdateMode.DISALLOW || shouldFail) {
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
stpVer.expectNext(true, false, false, true, false).verifyComplete();
|
|
|
|
|
}));
|
|
|
|
|
}));
|
|
|
|
|
if (updateMode != UpdateMode.DISALLOW && !shouldFail) {
|
|
|
|
|
Assertions.assertEquals(Arrays.asList(true, false, false, true, false), stpVer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -242,103 +235,70 @@ public abstract class TestDictionaryMap {
|
|
|
|
|
if (updateMode == UpdateMode.DISALLOW && !isTestBadKeysEnabled()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.flatMapMany(map -> Flux
|
|
|
|
|
.concat(
|
|
|
|
|
Mono
|
|
|
|
|
.fromRunnable(() -> log.debug("1. Updating value: {}", key))
|
|
|
|
|
.then(map.updateValue(key, old -> {
|
|
|
|
|
var stpVer = run(updateMode == UpdateMode.DISALLOW || shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
log.debug("1. Updating value: {}", key);
|
|
|
|
|
map.updateValue(key, old -> {
|
|
|
|
|
assert old == null;
|
|
|
|
|
return "error?";
|
|
|
|
|
}))
|
|
|
|
|
.doOnSuccess(s -> log.debug("1. Getting value: {}", key))
|
|
|
|
|
.then(map.getValue(null, key)),
|
|
|
|
|
});
|
|
|
|
|
log.debug("1. Getting value: {}", key);
|
|
|
|
|
var x2 = map.getValue(null, key);
|
|
|
|
|
|
|
|
|
|
Mono
|
|
|
|
|
.fromRunnable(() -> log.debug("2. Updating value: {}", key))
|
|
|
|
|
.then(map.updateValue(key, old -> {
|
|
|
|
|
log.debug("2. Updating value: {}", key);
|
|
|
|
|
map.updateValue(key, old -> {
|
|
|
|
|
assert Objects.equals(old, "error?");
|
|
|
|
|
return "error?";
|
|
|
|
|
}))
|
|
|
|
|
.doOnSuccess(s -> log.debug("2. Getting value: {}", key))
|
|
|
|
|
.then(map.getValue(null, key)),
|
|
|
|
|
});
|
|
|
|
|
log.debug("2. Getting value: {}", key);
|
|
|
|
|
var x3 = map.getValue(null, key);
|
|
|
|
|
|
|
|
|
|
Mono
|
|
|
|
|
.fromRunnable(() -> log.debug("3. Updating value: {}", key))
|
|
|
|
|
.then(map.updateValue(key, old -> {
|
|
|
|
|
log.debug("3. Updating value: {}", key);
|
|
|
|
|
map.updateValue(key, old -> {
|
|
|
|
|
assert Objects.equals(old, "error?");
|
|
|
|
|
return "error?";
|
|
|
|
|
}))
|
|
|
|
|
.doOnSuccess(s -> log.debug("3. Getting value: {}", key))
|
|
|
|
|
.then(map.getValue(null, key)),
|
|
|
|
|
});
|
|
|
|
|
log.debug("3. Getting value: {}", key);
|
|
|
|
|
var x4 = map.getValue(null, key);
|
|
|
|
|
|
|
|
|
|
Mono
|
|
|
|
|
.fromRunnable(() -> log.debug("4. Updating value: {}", key))
|
|
|
|
|
.then(map.updateValue(key, old -> {
|
|
|
|
|
log.debug("4. Updating value: {}", key);
|
|
|
|
|
map.updateValue(key, old -> {
|
|
|
|
|
assert Objects.equals(old, "error?");
|
|
|
|
|
return value;
|
|
|
|
|
}))
|
|
|
|
|
.doOnSuccess(s -> log.debug("4. Getting value: {}", key))
|
|
|
|
|
.then(map.getValue(null, key)),
|
|
|
|
|
});
|
|
|
|
|
log.debug("4. Getting value: {}", key);
|
|
|
|
|
var x5 = map.getValue(null, key);
|
|
|
|
|
|
|
|
|
|
Mono
|
|
|
|
|
.fromRunnable(() -> log.debug("5. Updating value: {}", key))
|
|
|
|
|
.then(map.updateValue(key, old -> {
|
|
|
|
|
log.debug("5. Updating value: {}", key);
|
|
|
|
|
map.updateValue(key, old -> {
|
|
|
|
|
assert Objects.equals(old, value);
|
|
|
|
|
return value;
|
|
|
|
|
}))
|
|
|
|
|
.doOnSuccess(s -> log.debug("5. Getting value: {}", key))
|
|
|
|
|
.then(map.getValue(null, key))
|
|
|
|
|
)
|
|
|
|
|
.doFinally(s -> map.close())
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
if (updateMode == UpdateMode.DISALLOW || shouldFail) {
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
stpVer.expectNext("error?", "error?", "error?", value, value).verifyComplete();
|
|
|
|
|
});
|
|
|
|
|
log.debug("5. Getting value: {}", key);
|
|
|
|
|
var x6 = map.getValue(null, key);
|
|
|
|
|
return Arrays.asList(x2, x3, x4, x5, x6);
|
|
|
|
|
}));
|
|
|
|
|
if (updateMode != UpdateMode.DISALLOW && !shouldFail) {
|
|
|
|
|
Assertions.assertEquals(Arrays.asList("error?", "error?", "error?", value, value), stpVer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testUpdateGetWithCancel() {
|
|
|
|
|
tempDb(getTempDbGenerator(), allocator, db -> {
|
|
|
|
|
var mapMono = tempDictionary(db, UpdateMode.ALLOW)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, MapType.MAP, 5));
|
|
|
|
|
|
|
|
|
|
var keys = Flux.range(10, 89).map(n -> "key" + n).repeat(100);
|
|
|
|
|
|
|
|
|
|
return Mono.usingWhen(mapMono,
|
|
|
|
|
map -> keys.flatMap(key -> map.updateValue(key, prevValue -> key + "-val")).then(),
|
|
|
|
|
LLUtils::finalizeResource
|
|
|
|
|
);
|
|
|
|
|
}).take(50).blockLast();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@MethodSource("provideArgumentsPut")
|
|
|
|
|
public void testPutAndGetChanged(MapType mapType, UpdateMode updateMode, String key, String value, boolean shouldFail) {
|
|
|
|
|
var stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.flatMapMany(map -> Flux
|
|
|
|
|
.concat(
|
|
|
|
|
map.putValueAndGetChanged(key, "error?").single(),
|
|
|
|
|
map.putValueAndGetChanged(key, value).single(),
|
|
|
|
|
map.putValueAndGetChanged(key, value).single(),
|
|
|
|
|
map.remove(key),
|
|
|
|
|
map.putValueAndGetChanged(key, "error?").single()
|
|
|
|
|
)
|
|
|
|
|
.doFinally(s -> map.close())
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
var stpVer = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
var x1 = map.putValueAndGetChanged(key, "error?");
|
|
|
|
|
var x2 = map.putValueAndGetChanged(key, value);
|
|
|
|
|
var x3 = map.putValueAndGetChanged(key, value);
|
|
|
|
|
map.remove(key);
|
|
|
|
|
var x4 = map.putValueAndGetChanged(key, "error?");
|
|
|
|
|
return Arrays.asList(x1, x2, x3, x4);
|
|
|
|
|
}));
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
stpVer.expectNext(true, true, false, true).verifyComplete();
|
|
|
|
|
Assertions.assertEquals(Arrays.asList(true, true, false, true), stpVer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -357,22 +317,21 @@ public abstract class TestDictionaryMap {
|
|
|
|
|
|
|
|
|
|
return keys
|
|
|
|
|
.stream()
|
|
|
|
|
.map(keyTuple -> keyTuple.mapT1(ks -> Flux
|
|
|
|
|
.zip(Flux.fromIterable(ks), Flux.fromIterable(values))
|
|
|
|
|
.collectMap(Tuple2::getT1, Tuple2::getT2, Object2ObjectLinkedOpenHashMap::new)
|
|
|
|
|
.block()
|
|
|
|
|
))
|
|
|
|
|
.flatMap(entryTuple -> Arrays.stream(UpdateMode.values()).map(updateMode -> new Tuple2<>(updateMode,
|
|
|
|
|
.map(keyTuple -> new Tuple2<>(Streams
|
|
|
|
|
.zip(keyTuple.getT1().stream(), values.stream(), Tuple2::new)
|
|
|
|
|
.collect(Collectors.toMap(Tuple2::getT1,
|
|
|
|
|
Tuple2::getT2,
|
|
|
|
|
(a, b) -> a,
|
|
|
|
|
it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap::new
|
|
|
|
|
)), keyTuple.getT2()))
|
|
|
|
|
.flatMap(entryTuple -> Arrays
|
|
|
|
|
.stream(UpdateMode.values())
|
|
|
|
|
.map(updateMode -> new Tuple3<>(updateMode, entryTuple.getT1(), entryTuple.getT2())))
|
|
|
|
|
.flatMap(entryTuple -> Stream.of(new Tuple4<>(MapType.MAP,
|
|
|
|
|
entryTuple.getT1(),
|
|
|
|
|
entryTuple.getT2()
|
|
|
|
|
)))
|
|
|
|
|
.flatMap(entryTuple -> Stream.of(new Tuple2<>(MapType.MAP, entryTuple.getT1(),
|
|
|
|
|
entryTuple.getT2(),
|
|
|
|
|
entryTuple.getT3()
|
|
|
|
|
), new Tuple2<>(MapType.HASH_MAP, entryTuple.getT1(),
|
|
|
|
|
entryTuple.getT2(),
|
|
|
|
|
false
|
|
|
|
|
)))
|
|
|
|
|
), new Tuple4<>(MapType.HASH_MAP, entryTuple.getT1(), entryTuple.getT2(), false)))
|
|
|
|
|
.filter(tuple -> !(tuple.getT1() == MapType.HASH_MAP && tuple.getT2() != UpdateMode.ALLOW))
|
|
|
|
|
.map(fullTuple -> Arguments.of(fullTuple.getT1(), fullTuple.getT2(), fullTuple.getT3(), fullTuple.getT4()));
|
|
|
|
|
}
|
|
|
|
@ -380,88 +339,77 @@ public abstract class TestDictionaryMap {
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@MethodSource("provideArgumentsPutMulti")
|
|
|
|
|
public void testPutMultiGetMulti(MapType mapType, UpdateMode updateMode, Object2ObjectSortedMap<String, String> entries, boolean shouldFail) {
|
|
|
|
|
var remainingEntries = new ConcurrentHashMap<Entry<String, String>, Boolean>().keySet(true);
|
|
|
|
|
Step<Entry<String, String>> stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.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());
|
|
|
|
|
})
|
|
|
|
|
var remainingEntries = new ArrayList<Entry<String, String>>();
|
|
|
|
|
var stpVer = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
|
|
|
|
|
var entriesFlux = entries.entrySet();
|
|
|
|
|
var keysFlux = entriesFlux.stream().map(Entry::getKey).toList();
|
|
|
|
|
map.putMulti(entriesFlux.stream());
|
|
|
|
|
List<Optional<String>> results;
|
|
|
|
|
try (var resultsFlux = map.getMulti(null, keysFlux.stream())) {
|
|
|
|
|
results = resultsFlux.toList();
|
|
|
|
|
}
|
|
|
|
|
return Streams
|
|
|
|
|
.zip(keysFlux.stream(), results.stream(), Map::entry)
|
|
|
|
|
.filter(entry -> entry.getValue().isPresent())
|
|
|
|
|
.map(k -> Map.entry(k.getKey(), k.getValue().orElseThrow()))
|
|
|
|
|
));
|
|
|
|
|
.toList();
|
|
|
|
|
}));
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
|
|
|
|
|
for (Entry<String, String> ignored : remainingEntries) {
|
|
|
|
|
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
|
|
|
|
|
}
|
|
|
|
|
stpVer.verifyComplete();
|
|
|
|
|
Assertions.assertEquals(remainingEntries, stpVer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@MethodSource("provideArgumentsPutMulti")
|
|
|
|
|
public void testSetAllValuesGetMulti(MapType mapType, UpdateMode updateMode, Object2ObjectSortedMap<String, String> entries, boolean shouldFail) {
|
|
|
|
|
var remainingEntries = new ConcurrentHashMap<Entry<String, String>, Boolean>().keySet(true);
|
|
|
|
|
Step<Entry<String, String>> stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> {
|
|
|
|
|
var mapMono = tempDictionary(db, updateMode).map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5));
|
|
|
|
|
return Flux.usingWhen(mapMono, map -> {
|
|
|
|
|
Flux<Entry<String, String>> entriesFlux = Flux.fromIterable(entries.entrySet());
|
|
|
|
|
Flux<String> keysFlux = entriesFlux.map(Entry::getKey);
|
|
|
|
|
Flux<Optional<String>> resultsFlux = map.setAllValues(entriesFlux).thenMany(map.getMulti(null, keysFlux));
|
|
|
|
|
return Flux.zip(keysFlux, resultsFlux, Map::entry);
|
|
|
|
|
}, LLUtils::finalizeResource)
|
|
|
|
|
.filter(k -> k.getValue().isPresent()).map(k -> Map.entry(k.getKey(), k.getValue().orElseThrow()));
|
|
|
|
|
var remainingEntries = new ArrayList<Entry<String, String>>();
|
|
|
|
|
var stpVer = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
|
|
|
|
|
var entriesFlux = entries.entrySet();
|
|
|
|
|
var keysFlux = entriesFlux.stream().map(Entry::getKey).toList();
|
|
|
|
|
map.setAllValues(entriesFlux.stream());
|
|
|
|
|
List<Optional<String>> resultsFlux;
|
|
|
|
|
try (var stream = map.getMulti(null, keysFlux.stream())) {
|
|
|
|
|
resultsFlux = stream.toList();
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
return Streams
|
|
|
|
|
.zip(keysFlux.stream(), resultsFlux.stream(), Map::entry)
|
|
|
|
|
.filter(k -> k.getValue().isPresent())
|
|
|
|
|
.map(k -> Map.entry(k.getKey(), k.getValue().orElseThrow()))
|
|
|
|
|
.toList();
|
|
|
|
|
}));
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
|
|
|
|
|
for (Entry<String, String> ignored : remainingEntries) {
|
|
|
|
|
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
|
|
|
|
|
}
|
|
|
|
|
stpVer.verifyComplete();
|
|
|
|
|
Assertions.assertEquals(remainingEntries, stpVer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@MethodSource("provideArgumentsPutMulti")
|
|
|
|
|
public void testSetAllValuesAndGetPrevious(MapType mapType, UpdateMode updateMode, Object2ObjectSortedMap<String, String> entries, boolean shouldFail) {
|
|
|
|
|
var remainingEntries = new ConcurrentHashMap<Entry<String, String>, Boolean>().keySet(true);
|
|
|
|
|
Step<Entry<String, String>> stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.flatMapMany(map -> Flux
|
|
|
|
|
.concat(
|
|
|
|
|
map.setAllValuesAndGetPrevious(Flux.fromIterable(entries.entrySet())),
|
|
|
|
|
map.setAllValuesAndGetPrevious(Flux.fromIterable(entries.entrySet()))
|
|
|
|
|
)
|
|
|
|
|
.doFinally(s -> map.close())
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
public void testSetAllValuesAndGetPrevious(MapType mapType,
|
|
|
|
|
UpdateMode updateMode,
|
|
|
|
|
Object2ObjectSortedMap<String, String> entries,
|
|
|
|
|
boolean shouldFail) {
|
|
|
|
|
var remainingEntries = new ArrayList<Entry<String, String>>();
|
|
|
|
|
var stpVer = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
return Arrays.asList(toListClose(map.setAllValuesAndGetPrevious(entries.entrySet().stream())),
|
|
|
|
|
toListClose(map.setAllValuesAndGetPrevious(entries.entrySet().stream()))
|
|
|
|
|
);
|
|
|
|
|
}));
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
|
|
|
|
|
for (Entry<String, String> ignored : remainingEntries) {
|
|
|
|
|
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
|
|
|
|
|
}
|
|
|
|
|
stpVer.verifyComplete();
|
|
|
|
|
Assertions.assertEquals(Arrays.asList(List.of(), remainingEntries), stpVer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -471,32 +419,24 @@ public abstract class TestDictionaryMap {
|
|
|
|
|
UpdateMode updateMode,
|
|
|
|
|
Object2ObjectSortedMap<String, String> entries,
|
|
|
|
|
boolean shouldFail) {
|
|
|
|
|
var remainingEntries = new ConcurrentHashMap<Entry<String, String>, Boolean>().keySet(true);
|
|
|
|
|
Step<Entry<String, String>> stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.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());
|
|
|
|
|
})
|
|
|
|
|
var remainingEntries = new ArrayList<Entry<String, String>>();
|
|
|
|
|
var stpVer = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
var entriesFlux = entries.entrySet();
|
|
|
|
|
var keysFlux = entriesFlux.stream().map(Entry::getKey).toList();
|
|
|
|
|
map.set(entries);
|
|
|
|
|
var resultsFlux = toListClose(map.getMulti(null, entries.keySet().stream()));
|
|
|
|
|
return Streams
|
|
|
|
|
.zip(keysFlux.stream(), resultsFlux.stream(), Map::entry)
|
|
|
|
|
.filter(k -> k.getValue().isPresent())
|
|
|
|
|
.map(k -> Map.entry(k.getKey(), k.getValue().orElseThrow()))
|
|
|
|
|
));
|
|
|
|
|
.toList();
|
|
|
|
|
}));
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
|
|
|
|
|
for (Entry<String, String> ignored : remainingEntries) {
|
|
|
|
|
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
|
|
|
|
|
}
|
|
|
|
|
stpVer.verifyComplete();
|
|
|
|
|
Assertions.assertEquals(remainingEntries, stpVer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -506,31 +446,20 @@ public abstract class TestDictionaryMap {
|
|
|
|
|
UpdateMode updateMode,
|
|
|
|
|
Object2ObjectSortedMap<String, String> entries,
|
|
|
|
|
boolean shouldFail) {
|
|
|
|
|
Step<Boolean> stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.flatMapMany(map -> {
|
|
|
|
|
Mono<Void> removalMono;
|
|
|
|
|
if (entries.isEmpty()) {
|
|
|
|
|
removalMono = Mono.empty();
|
|
|
|
|
} else {
|
|
|
|
|
removalMono = map.remove(entries.keySet().stream().findFirst().orElseThrow());
|
|
|
|
|
var stpVer = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
var x1 = map.setAndGetChanged(entries);
|
|
|
|
|
var x2 = map.setAndGetChanged(entries);
|
|
|
|
|
if (!entries.isEmpty()) {
|
|
|
|
|
map.remove(entries.keySet().stream().findFirst().orElseThrow());
|
|
|
|
|
}
|
|
|
|
|
return Flux
|
|
|
|
|
.concat(
|
|
|
|
|
map.setAndGetChanged(entries).single(),
|
|
|
|
|
map.setAndGetChanged(entries).single(),
|
|
|
|
|
removalMono.then(Mono.empty()),
|
|
|
|
|
map.setAndGetChanged(entries).single()
|
|
|
|
|
)
|
|
|
|
|
.doFinally(s -> map.close());
|
|
|
|
|
})
|
|
|
|
|
));
|
|
|
|
|
var x3 = map.setAndGetChanged(entries);
|
|
|
|
|
return Arrays.asList(x1, x2, x3);
|
|
|
|
|
}));
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
stpVer.expectNext(!entries.isEmpty(), false, !entries.isEmpty()).verifyComplete();
|
|
|
|
|
Assertions.assertEquals(Arrays.asList(!entries.isEmpty(), false, !entries.isEmpty()), stpVer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -540,26 +469,14 @@ public abstract class TestDictionaryMap {
|
|
|
|
|
UpdateMode updateMode,
|
|
|
|
|
Object2ObjectSortedMap<String, String> entries,
|
|
|
|
|
boolean shouldFail) {
|
|
|
|
|
var remainingEntries = new ConcurrentHashMap<Entry<String, String>, Boolean>().keySet(true);
|
|
|
|
|
Step<Entry<String, String>> stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.flatMapMany(map -> Flux
|
|
|
|
|
.concat(map.setAndGetPrevious(entries), map.setAndGetPrevious(entries))
|
|
|
|
|
.map(Map::entrySet)
|
|
|
|
|
.concatMapIterable(list -> list)
|
|
|
|
|
.doFinally(s -> map.close())
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
var stpVer = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
return Arrays.asList(map.setAndGetPrevious(entries), map.setAndGetPrevious(entries));
|
|
|
|
|
}));
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
|
|
|
|
|
for (Entry<String, String> ignored : remainingEntries) {
|
|
|
|
|
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
|
|
|
|
|
}
|
|
|
|
|
stpVer.verifyComplete();
|
|
|
|
|
Assertions.assertEquals(Arrays.asList(null, entries.isEmpty() ? null : entries), stpVer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -569,178 +486,116 @@ public abstract class TestDictionaryMap {
|
|
|
|
|
UpdateMode updateMode,
|
|
|
|
|
Object2ObjectSortedMap<String, String> entries,
|
|
|
|
|
boolean shouldFail) {
|
|
|
|
|
var remainingEntries = new ConcurrentHashMap<Entry<String, String>, Boolean>().keySet(true);
|
|
|
|
|
Step<Entry<String, String>> stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.flatMapMany(map -> Flux
|
|
|
|
|
.concat(map.set(entries).then(Mono.empty()), map.clearAndGetPrevious(), map.get(null))
|
|
|
|
|
.map(Map::entrySet)
|
|
|
|
|
.concatMapIterable(list -> list)
|
|
|
|
|
.doFinally(s -> map.close())
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
var stpVer = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
map.set(entries);
|
|
|
|
|
return Arrays.asList(map.clearAndGetPrevious(), map.get(null));
|
|
|
|
|
}));
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
|
|
|
|
|
for (Entry<String, String> ignored : remainingEntries) {
|
|
|
|
|
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
|
|
|
|
|
}
|
|
|
|
|
stpVer.verifyComplete();
|
|
|
|
|
Assertions.assertEquals(Arrays.asList(entries.isEmpty() ? null : entries, null), stpVer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@MethodSource("provideArgumentsPutMulti")
|
|
|
|
|
public void testPutMultiGetAllValues(MapType mapType, UpdateMode updateMode, Object2ObjectSortedMap<String, String> entries, boolean shouldFail) {
|
|
|
|
|
var remainingEntries = new ConcurrentHashMap<Entry<String, String>, Boolean>().keySet(true);
|
|
|
|
|
Step<Entry<String, String>> stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.flatMapMany(map -> Flux
|
|
|
|
|
.concat(
|
|
|
|
|
map.putMulti(Flux.fromIterable(entries.entrySet())).then(Mono.empty()),
|
|
|
|
|
map.getAllValues(null, false)
|
|
|
|
|
)
|
|
|
|
|
.doFinally(s -> map.close())
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
var stpVer = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
map.putMulti(entries.entrySet().stream());
|
|
|
|
|
return toListClose(map.getAllValues(null, false));
|
|
|
|
|
}));
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
|
|
|
|
|
for (Entry<String, String> ignored : remainingEntries) {
|
|
|
|
|
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
|
|
|
|
|
}
|
|
|
|
|
stpVer.verifyComplete();
|
|
|
|
|
Assertions.assertEquals(entries.entrySet(), Set.copyOf(stpVer));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@MethodSource("provideArgumentsPutMulti")
|
|
|
|
|
public void testPutMultiGet(MapType mapType, UpdateMode updateMode, Object2ObjectSortedMap<String, String> entries, boolean shouldFail) {
|
|
|
|
|
var remainingEntries = new ConcurrentHashMap<Entry<String, String>, Boolean>().keySet(true);
|
|
|
|
|
Step<Entry<String, String>> stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.flatMapMany(map -> Flux
|
|
|
|
|
.concat(
|
|
|
|
|
map.putMulti(Flux.fromIterable(entries.entrySet())).then(Mono.empty()),
|
|
|
|
|
map.get(null)
|
|
|
|
|
.map(Map::entrySet)
|
|
|
|
|
.flatMapIterable(list -> list)
|
|
|
|
|
)
|
|
|
|
|
.doFinally(s -> map.close())
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
var stpVer = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
map.putMulti(entries.entrySet().stream());
|
|
|
|
|
return map.get(null);
|
|
|
|
|
}));
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
|
|
|
|
|
for (Entry<String, String> ignored : remainingEntries) {
|
|
|
|
|
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
|
|
|
|
|
}
|
|
|
|
|
stpVer.verifyComplete();
|
|
|
|
|
Assertions.assertEquals(entries.isEmpty() ? null : entries, stpVer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@MethodSource("provideArgumentsPutMulti")
|
|
|
|
|
public void testPutMultiGetAllStagesGet(MapType mapType, UpdateMode updateMode, Object2ObjectSortedMap<String, String> entries, boolean shouldFail) {
|
|
|
|
|
var remainingEntries = new ConcurrentHashMap<Entry<String, String>, Boolean>().keySet(true);
|
|
|
|
|
Step<Entry<String, String>> stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.flatMapMany(map -> Flux
|
|
|
|
|
.concat(
|
|
|
|
|
map.putMulti(Flux.fromIterable(entries.entrySet())).then(Mono.empty()),
|
|
|
|
|
map
|
|
|
|
|
.getAllStages(null, false)
|
|
|
|
|
.flatMap(stage -> stage
|
|
|
|
|
.getValue()
|
|
|
|
|
.get(null)
|
|
|
|
|
.map(val -> Map.entry(stage.getKey(), val))
|
|
|
|
|
.doFinally(s -> stage.getValue().close())
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.doFinally(s -> map.close())
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
var remainingEntries = new ArrayList<Entry<String, String>>();
|
|
|
|
|
var stpVer = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
map.putMulti(entries.entrySet().stream());
|
|
|
|
|
return toListClose(map.getAllStages(null, false).map(stage -> {
|
|
|
|
|
var v = stage.getValue().get(null);
|
|
|
|
|
if (v == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return Map.entry(stage.getKey(), v);
|
|
|
|
|
}));
|
|
|
|
|
}));
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
entries.forEach((k, v) -> remainingEntries.add(Map.entry(k, v)));
|
|
|
|
|
for (Entry<String, String> ignored : remainingEntries) {
|
|
|
|
|
stpVer = stpVer.expectNextMatches(remainingEntries::remove);
|
|
|
|
|
}
|
|
|
|
|
stpVer.verifyComplete();
|
|
|
|
|
Assertions.assertEquals(new HashSet<>(remainingEntries), Set.copyOf(stpVer));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@MethodSource("provideArgumentsPutMulti")
|
|
|
|
|
public void testPutMultiIsEmpty(MapType mapType, UpdateMode updateMode, Object2ObjectSortedMap<String, String> entries, boolean shouldFail) {
|
|
|
|
|
var remainingEntries = new ConcurrentHashMap<Entry<String, String>, Boolean>().keySet(true);
|
|
|
|
|
Step<Boolean> stpVer = StepVerifier
|
|
|
|
|
.create(tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.flatMapMany(map -> Flux
|
|
|
|
|
.concat(
|
|
|
|
|
map.isEmpty(null),
|
|
|
|
|
map.putMulti(Flux.fromIterable(entries.entrySet())).then(Mono.empty()),
|
|
|
|
|
map.isEmpty(null)
|
|
|
|
|
)
|
|
|
|
|
.doFinally(s -> map.close())
|
|
|
|
|
)
|
|
|
|
|
.flatMap(val -> shouldFail ? Mono.empty() : Mono.just(val))
|
|
|
|
|
));
|
|
|
|
|
var stpVer = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
var x1 = map.isEmpty(null);
|
|
|
|
|
map.putMulti(entries.entrySet().stream());
|
|
|
|
|
var x2 = map.isEmpty(null);
|
|
|
|
|
return Arrays.asList(x1, x2);
|
|
|
|
|
}));
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
stpVer.verifyError();
|
|
|
|
|
} else {
|
|
|
|
|
stpVer.expectNext(true, entries.isEmpty()).verifyComplete();
|
|
|
|
|
Assertions.assertEquals(Arrays.asList(true, entries.isEmpty()), stpVer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@MethodSource("provideArgumentsPutMulti")
|
|
|
|
|
public void testPutMultiClear(MapType mapType, UpdateMode updateMode, Object2ObjectSortedMap<String, String> entries, boolean shouldFail) {
|
|
|
|
|
public void testPutMultiClear(MapType mapType,
|
|
|
|
|
UpdateMode updateMode,
|
|
|
|
|
Object2ObjectSortedMap<String, String> entries,
|
|
|
|
|
boolean shouldFail) {
|
|
|
|
|
List<Boolean> result;
|
|
|
|
|
try {
|
|
|
|
|
result = SyncUtils.run(DbTestUtils.tempDb(getTempDbGenerator(), allocator, db -> tempDictionary(db, updateMode)
|
|
|
|
|
.map(dict -> tempDatabaseMapDictionaryMap(dict, mapType, 5))
|
|
|
|
|
.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)
|
|
|
|
|
)
|
|
|
|
|
.doFinally(s -> map.close())
|
|
|
|
|
)
|
|
|
|
|
.flatMap(val -> shouldFail ? Mono.empty() : Mono.just(val))
|
|
|
|
|
.collectList()
|
|
|
|
|
).singleOrEmpty());
|
|
|
|
|
result = run(shouldFail, () -> tempDb(getTempDbGenerator(), db -> {
|
|
|
|
|
var map = tempDatabaseMapDictionaryMap(tempDictionary(db, updateMode), mapType, 5);
|
|
|
|
|
var x1 = map.isEmpty(null);
|
|
|
|
|
map.putMulti(entries.entrySet().stream());
|
|
|
|
|
var x2 = map.isEmpty(null);
|
|
|
|
|
map.clear();
|
|
|
|
|
var x3 = map.isEmpty(null);
|
|
|
|
|
return List.of(x1, x2, x3);
|
|
|
|
|
}));
|
|
|
|
|
Assertions.assertEquals(true, result.get(0));
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals(entries.isEmpty(), result.get(1));
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals(true, result.get(2));
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
if (shouldFail) {
|
|
|
|
|
this.checkLeaks = false;
|
|
|
|
|
} else {
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals(true, result.get(0));
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals(entries.isEmpty(), result.get(1));
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals(true, result.get(2));
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|