Update Example.java and FixedLengthSerializer.java

This commit is contained in:
Andrea Cavalli 2021-01-31 22:54:26 +01:00
parent 5ae015b701
commit 6d63ff3edf
2 changed files with 19 additions and 23 deletions

View File

@ -57,7 +57,7 @@ public class Example {
tempDb() tempDb()
.flatMap(db -> db.getDictionary("testmap").map(dict -> Tuples.of(db, dict))) .flatMap(db -> db.getDictionary("testmap").map(dict -> Tuples.of(db, dict)))
.map(tuple -> tuple.mapT2(dict -> DatabaseMapDictionaryDeep.simple(dict, ssg, ser))), .map(tuple -> tuple.mapT2(dict -> DatabaseMapDictionaryDeep.simple(dict, ssg, ser))),
tuple -> Mono tuple -> Flux.range(0, batchSize).flatMap(n -> Mono
.defer(() -> Mono .defer(() -> Mono
.fromRunnable(() -> { .fromRunnable(() -> {
if (printPreviousValue) if (printPreviousValue)
@ -69,8 +69,7 @@ public class Example {
if (printPreviousValue) if (printPreviousValue)
System.out.println("Old value: " + (oldValue == null ? "None" : Arrays.toString(oldValue))); System.out.println("Old value: " + (oldValue == null ? "None" : Arrays.toString(oldValue)));
}) })
) ))
.repeat(batchSize)
.then(), .then(),
numRepeats, numRepeats,
tuple -> tuple.getT1().close()); tuple -> tuple.getT1().close());
@ -86,7 +85,7 @@ public class Example {
tempDb() tempDb()
.flatMap(db -> db.getDictionary("testmap").map(dict -> Tuples.of(db, dict))) .flatMap(db -> db.getDictionary("testmap").map(dict -> Tuples.of(db, dict)))
.map(tuple -> tuple.mapT2(dict -> DatabaseMapDictionaryDeep.simple(dict, ssg, ser))), .map(tuple -> tuple.mapT2(dict -> DatabaseMapDictionaryDeep.simple(dict, ssg, ser))),
tuple -> Mono tuple -> Flux.range(0, batchSize).flatMap(n -> Mono
.defer(() -> Mono .defer(() -> Mono
.fromRunnable(() -> { .fromRunnable(() -> {
if (printPreviousValue) if (printPreviousValue)
@ -97,8 +96,7 @@ public class Example {
if (printPreviousValue) if (printPreviousValue)
System.out.println("Old value: " + (oldValue == null ? "None" : Arrays.toString(oldValue))); System.out.println("Old value: " + (oldValue == null ? "None" : Arrays.toString(oldValue)));
}) })
) ))
.repeat(batchSize)
.then(), .then(),
numRepeats, numRepeats,
tuple -> tuple.getT1().close()); tuple -> tuple.getT1().close());
@ -114,15 +112,14 @@ public class Example {
tempDb() tempDb()
.flatMap(db -> db.getDictionary("testmap").map(dict -> Tuples.of(db, dict))) .flatMap(db -> db.getDictionary("testmap").map(dict -> Tuples.of(db, dict)))
.map(tuple -> tuple.mapT2(dict -> DatabaseMapDictionaryDeep.simple(dict, ssg, ser))), .map(tuple -> tuple.mapT2(dict -> DatabaseMapDictionaryDeep.simple(dict, ssg, ser))),
tuple -> Mono tuple -> Flux.range(0, batchSize).flatMap(n -> Mono
.defer(() -> Mono .defer(() -> Mono
.fromRunnable(() -> { .fromRunnable(() -> {
if (printPreviousValue) if (printPreviousValue)
System.out.println("Setting new value at key " + Arrays.toString(itemKey) + ": " + Arrays.toString(newValue)); System.out.println("Setting new value at key " + Arrays.toString(itemKey) + ": " + Arrays.toString(newValue));
}) })
.then(tuple.getT2().putValue(itemKeyBuffer, newValue)) .then(tuple.getT2().putValue(itemKeyBuffer, newValue))
) ))
.repeat(batchSize)
.then(), .then(),
numRepeats, numRepeats,
tuple -> tuple.getT1().close()); tuple -> tuple.getT1().close());
@ -158,7 +155,7 @@ public class Example {
tempDb() tempDb()
.flatMap(db -> db.getDictionary("testmap").map(dict -> Tuples.of(db, dict))) .flatMap(db -> db.getDictionary("testmap").map(dict -> Tuples.of(db, dict)))
.map(tuple -> tuple.mapT2(dict -> DatabaseMapDictionary.simple(dict, ser, vser))), .map(tuple -> tuple.mapT2(dict -> DatabaseMapDictionary.simple(dict, ser, vser))),
tuple -> Mono tuple -> Flux.range(0, batchSize).flatMap(n -> Mono
.defer(() -> Mono .defer(() -> Mono
.fromRunnable(() -> { .fromRunnable(() -> {
if (printPreviousValue) if (printPreviousValue)
@ -170,8 +167,7 @@ public class Example {
if (printPreviousValue) if (printPreviousValue)
System.out.println("Old value: " + (oldValue == null ? "None" : Arrays.toString(oldValue))); System.out.println("Old value: " + (oldValue == null ? "None" : Arrays.toString(oldValue)));
}) })
) ))
.repeat(batchSize)
.then(), .then(),
numRepeats, numRepeats,
tuple -> tuple.getT1().close()); tuple -> tuple.getT1().close());
@ -187,7 +183,7 @@ public class Example {
tempDb() tempDb()
.flatMap(db -> db.getDictionary("testmap").map(dict -> Tuples.of(db, dict))) .flatMap(db -> db.getDictionary("testmap").map(dict -> Tuples.of(db, dict)))
.map(tuple -> tuple.mapT2(dict -> DatabaseMapDictionary.simple(dict, ser, vser))), .map(tuple -> tuple.mapT2(dict -> DatabaseMapDictionary.simple(dict, ser, vser))),
tuple -> Mono tuple -> Flux.range(0, batchSize).flatMap(n -> Mono
.defer(() -> Mono .defer(() -> Mono
.fromRunnable(() -> { .fromRunnable(() -> {
if (printPreviousValue) if (printPreviousValue)
@ -198,8 +194,7 @@ public class Example {
if (printPreviousValue) if (printPreviousValue)
System.out.println("Old value: " + (oldValue == null ? "None" : Arrays.toString(oldValue))); System.out.println("Old value: " + (oldValue == null ? "None" : Arrays.toString(oldValue)));
}) })
) ))
.repeat(batchSize)
.then(), .then(),
numRepeats, numRepeats,
tuple -> tuple.getT1().close()); tuple -> tuple.getT1().close());
@ -215,15 +210,14 @@ public class Example {
tempDb() tempDb()
.flatMap(db -> db.getDictionary("testmap").map(dict -> Tuples.of(db, dict))) .flatMap(db -> db.getDictionary("testmap").map(dict -> Tuples.of(db, dict)))
.map(tuple -> tuple.mapT2(dict -> DatabaseMapDictionary.simple(dict, ser, vser))), .map(tuple -> tuple.mapT2(dict -> DatabaseMapDictionary.simple(dict, ser, vser))),
tuple -> Mono tuple -> Flux.range(0, batchSize).flatMap(n -> Mono
.defer(() -> Mono .defer(() -> Mono
.fromRunnable(() -> { .fromRunnable(() -> {
if (printPreviousValue) if (printPreviousValue)
System.out.println("Setting new value at key " + Arrays.toString(itemKey) + ": " + Arrays.toString(newValue)); System.out.println("Setting new value at key " + Arrays.toString(itemKey) + ": " + Arrays.toString(newValue));
}) })
.then(tuple.getT2().putValue(itemKeyBuffer, newValue)) .then(tuple.getT2().putValue(itemKeyBuffer, newValue))
) ))
.repeat(batchSize)
.then(), .then(),
numRepeats, numRepeats,
tuple -> tuple.getT1().close()); tuple -> tuple.getT1().close());
@ -259,14 +253,17 @@ public class Example {
One<Instant> instantInitTest = Sinks.one(); One<Instant> instantInitTest = Sinks.one();
One<Instant> instantEndTest = Sinks.one(); One<Instant> instantEndTest = Sinks.one();
One<Instant> instantEnd = Sinks.one(); One<Instant> instantEnd = Sinks.one();
Duration WAIT_TIME = Duration.ofSeconds(5);
Duration WAIT_TIME_END = Duration.ofSeconds(5);
return Mono return Mono
.fromRunnable(() -> instantInit.tryEmitValue(now())) .fromRunnable(() -> instantInit.tryEmitValue(now()))
.then(setup) .then(setup)
.delayElement(WAIT_TIME)
.doOnSuccess(s -> instantInitTest.tryEmitValue(now())) .doOnSuccess(s -> instantInitTest.tryEmitValue(now()))
.flatMap(a -> Mono.defer(() -> test.apply(a)) .flatMap(a ->Mono.defer(() -> test.apply(a)).repeat(numRepeats)
.repeat(numRepeats)
.then() .then()
.doOnSuccess(s -> instantEndTest.tryEmitValue(now())) .doOnSuccess(s -> instantEndTest.tryEmitValue(now()))
.delayElement(WAIT_TIME_END)
.then(close.apply(a))) .then(close.apply(a)))
.doOnSuccess(s -> instantEnd.tryEmitValue(now())) .doOnSuccess(s -> instantEnd.tryEmitValue(now()))
.then(Mono.zip(instantInit.asMono(), instantInitTest.asMono(), instantEndTest.asMono(), instantEnd.asMono())) .then(Mono.zip(instantInit.asMono(), instantInitTest.asMono(), instantEndTest.asMono(), instantEnd.asMono()))
@ -288,7 +285,7 @@ public class Example {
.format(Duration.between(tuple.getT2(), tuple.getT3()).toNanos() / (double) 1000000) + "ms"); .format(Duration.between(tuple.getT2(), tuple.getT3()).toNanos() / (double) 1000000) + "ms");
System.out.println("\t - Total time (setup+test+end): " + DecimalFormat System.out.println("\t - Total time (setup+test+end): " + DecimalFormat
.getInstance(Locale.ITALY) .getInstance(Locale.ITALY)
.format(Duration.between(tuple.getT1(), tuple.getT4()).toNanos() / (double) 1000000) + "ms"); .format(Duration.between(tuple.getT1(), tuple.getT4().minus(WAIT_TIME)).toNanos() / (double) 1000000) + "ms");
System.out.println("----------------------------------------------------------------------"); System.out.println("----------------------------------------------------------------------");
}) })
.then(); .then();

View File

@ -15,8 +15,7 @@ public interface FixedLengthSerializer<B> extends Serializer<B> {
@Override @Override
public void serialize(ByteBuf deserialized, ByteBuf output) { public void serialize(ByteBuf deserialized, ByteBuf output) {
deserialized.resetReaderIndex(); output.writeBytes(deserialized.slice(), length);
output.writeBytes(deserialized, length);
} }
@Override @Override