From 0e7ca1ecdb353ec7cb879bdd372487bee9ba790d Mon Sep 17 00:00:00 2001 From: f1v3-dev Date: Wed, 20 May 2026 14:10:33 +0900 Subject: [PATCH] FEATURE: Replace GetArgs with GetOption enum --- .../spy/memcached/v2/AsyncArcusCommands.java | 26 +- .../memcached/v2/AsyncArcusCommandsIF.java | 26 +- .../java/net/spy/memcached/v2/vo/GetArgs.java | 42 - .../net/spy/memcached/v2/vo/GetOption.java | 34 + .../v2/AdminAsyncArcusCommandsTest.java | 34 +- .../v2/BTreeAsyncArcusCommandsTest.java | 1270 ++++++++--------- .../v2/KVAsyncArcusCommandsTest.java | 586 ++++---- .../v2/ListAsyncArcusCommandsTest.java | 320 ++--- .../v2/MapAsyncArcusCommandsTest.java | 48 +- .../v2/SetAsyncArcusCommandsTest.java | 322 +++-- 10 files changed, 1341 insertions(+), 1367 deletions(-) delete mode 100644 src/main/java/net/spy/memcached/v2/vo/GetArgs.java create mode 100644 src/main/java/net/spy/memcached/v2/vo/GetOption.java diff --git a/src/main/java/net/spy/memcached/v2/AsyncArcusCommands.java b/src/main/java/net/spy/memcached/v2/AsyncArcusCommands.java index 1f1f4d658..61948ec83 100644 --- a/src/main/java/net/spy/memcached/v2/AsyncArcusCommands.java +++ b/src/main/java/net/spy/memcached/v2/AsyncArcusCommands.java @@ -110,7 +110,7 @@ import net.spy.memcached.v2.vo.BTreeUpdateElement; import net.spy.memcached.v2.vo.BopDeleteArgs; import net.spy.memcached.v2.vo.BopGetArgs; -import net.spy.memcached.v2.vo.GetArgs; +import net.spy.memcached.v2.vo.GetOption; import net.spy.memcached.v2.vo.SMGetElements; public class AsyncArcusCommands implements AsyncArcusCommandsIF { @@ -735,10 +735,10 @@ public ArcusFuture lopInsert(String key, int index, T value, } @Override - public ArcusFuture lopGet(String key, int index, GetArgs args) { + public ArcusFuture lopGet(String key, int index, GetOption option) { AbstractArcusResult result = new AbstractArcusResult<>(new AtomicReference<>()); ArcusFutureImpl future = new ArcusFutureImpl<>(result); - ListGet get = new ListGet(index, args.isWithDelete(), args.isDropIfEmpty()); + ListGet get = new ListGet(index, option.isWithDelete(), option.isDropIfEmpty()); ArcusClient client = arcusClientSupplier.get(); CollectionGetOperation.Callback cb = new CollectionGetOperation.Callback() { @@ -781,11 +781,11 @@ public void gotData(String subKey, int flags, byte[] data, byte[] eFlag) { } @Override - public ArcusFuture> lopGet(String key, int from, int to, GetArgs args) { + public ArcusFuture> lopGet(String key, int from, int to, GetOption option) { AbstractArcusResult> result = new AbstractArcusResult<>(new AtomicReference<>(new ArrayList<>())); ArcusFutureImpl> future = new ArcusFutureImpl<>(result); - ListGet get = new ListGet(from, to, args.isWithDelete(), args.isDropIfEmpty()); + ListGet get = new ListGet(from, to, option.isWithDelete(), option.isDropIfEmpty()); ArcusClient client = arcusClientSupplier.get(); CollectionGetOperation.Callback cb = new CollectionGetOperation.Callback() { @@ -864,11 +864,11 @@ public ArcusFuture sopInsert(String key, T value, CollectionAttributes } @Override - public ArcusFuture> sopGet(String key, int count, GetArgs args) { + public ArcusFuture> sopGet(String key, int count, GetOption option) { AbstractArcusResult> result = new AbstractArcusResult<>(new AtomicReference<>(new HashSet<>())); ArcusFutureImpl> future = new ArcusFutureImpl<>(result); - SetGet get = new SetGet(count, args.isWithDelete(), args.isDropIfEmpty()); + SetGet get = new SetGet(count, option.isWithDelete(), option.isDropIfEmpty()); ArcusClient client = arcusClientSupplier.get(); CollectionGetOperation.Callback cb = new CollectionGetOperation.Callback() { @@ -1009,18 +1009,18 @@ public ArcusFuture mopUpdate(String key, String mKey, T value) { } @Override - public ArcusFuture> mopGet(String key, GetArgs args) { - return mopGet(key, new ArrayList<>(), args); + public ArcusFuture> mopGet(String key, GetOption option) { + return mopGet(key, new ArrayList<>(), option); } @Override - public ArcusFuture mopGet(String key, String mKey, GetArgs args) { + public ArcusFuture mopGet(String key, String mKey, GetOption option) { keyValidator.validateMKey(mKey); AbstractArcusResult result = new AbstractArcusResult<>(new AtomicReference<>()); ArcusFutureImpl future = new ArcusFutureImpl<>(result); List mKeys = Collections.singletonList(mKey); - MapGet get = new MapGet(mKeys, args.isWithDelete(), args.isDropIfEmpty()); + MapGet get = new MapGet(mKeys, option.isWithDelete(), option.isDropIfEmpty()); ArcusClient client = arcusClientSupplier.get(); CollectionGetOperation.Callback cb = new CollectionGetOperation.Callback() { @@ -1063,7 +1063,7 @@ public void complete() { } @Override - public ArcusFuture> mopGet(String key, List mKeys, GetArgs args) { + public ArcusFuture> mopGet(String key, List mKeys, GetOption option) { if (mKeys == null) { throw new IllegalArgumentException("mKeys cannot be null"); } @@ -1075,7 +1075,7 @@ public ArcusFuture> mopGet(String key, List mKeys, GetArg AbstractArcusResult> result = new AbstractArcusResult<>(new AtomicReference<>(new HashMap<>())); ArcusFutureImpl> future = new ArcusFutureImpl<>(result); - MapGet get = new MapGet(mKeys, args.isWithDelete(), args.isDropIfEmpty()); + MapGet get = new MapGet(mKeys, option.isWithDelete(), option.isDropIfEmpty()); ArcusClient client = arcusClientSupplier.get(); CollectionGetOperation.Callback cb = new CollectionGetOperation.Callback() { diff --git a/src/main/java/net/spy/memcached/v2/AsyncArcusCommandsIF.java b/src/main/java/net/spy/memcached/v2/AsyncArcusCommandsIF.java index db4cb99b0..67f8463aa 100644 --- a/src/main/java/net/spy/memcached/v2/AsyncArcusCommandsIF.java +++ b/src/main/java/net/spy/memcached/v2/AsyncArcusCommandsIF.java @@ -34,7 +34,7 @@ import net.spy.memcached.v2.vo.BTreeUpdateElement; import net.spy.memcached.v2.vo.BopDeleteArgs; import net.spy.memcached.v2.vo.BopGetArgs; -import net.spy.memcached.v2.vo.GetArgs; +import net.spy.memcached.v2.vo.GetOption; import net.spy.memcached.v2.vo.SMGetElements; public interface AsyncArcusCommandsIF { @@ -260,10 +260,10 @@ ArcusFuture lopCreate(String key, ElementValueType type, * * @param key key of the list * @param index index of the element to get - * @param args arguments for get operation + * @param option get option - {@link GetOption} * @return the element value, {@code null} if the key or element is not found */ - ArcusFuture lopGet(String key, int index, GetArgs args); + ArcusFuture lopGet(String key, int index, GetOption option); /** * Get elements in an index range from a list. @@ -271,11 +271,11 @@ ArcusFuture lopCreate(String key, ElementValueType type, * @param key key of the list * @param from index range start (inclusive) * @param to index range end (inclusive) - * @param args arguments for get operation + * @param option get option - {@link GetOption} * @return list of element values in order, an empty list if no elements are found in the range, * {@code null} if the key is not found */ - ArcusFuture> lopGet(String key, int from, int to, GetArgs args); + ArcusFuture> lopGet(String key, int from, int to, GetOption option); /** * Delete an element at the given index from a list. @@ -342,11 +342,11 @@ ArcusFuture sopCreate(String key, ElementValueType type, * * @param key key of the set * @param count number of elements to retrieve randomly (0 means all elements, max 1000) - * @param args arguments for get operation + * @param option get option - {@link GetOption} * @return set of element values, an empty set if no elements are found, * {@code null} if the key is not found */ - ArcusFuture> sopGet(String key, int count, GetArgs args); + ArcusFuture> sopGet(String key, int count, GetOption option); /** * Check whether an element exists in a set. @@ -448,35 +448,35 @@ ArcusFuture mopCreate(String key, ElementValueType type, * Get all elements from a map. * * @param key key of the map - * @param args arguments for get operation + * @param option get option - {@link GetOption} * @return map of MKey to value, * empty map if no elements exist, * {@code null} if the key is not found */ - ArcusFuture> mopGet(String key, GetArgs args); + ArcusFuture> mopGet(String key, GetOption option); /** * Get an element with the given MKey from a map. * * @param key key of the map * @param mKey MKey of the element to get - * @param args arguments for get operation + * @param option get option - {@link GetOption} * @return the element value, * {@code null} if the key or MKey is not found */ - ArcusFuture mopGet(String key, String mKey, GetArgs args); + ArcusFuture mopGet(String key, String mKey, GetOption option); /** * Get elements with the MKeys from a map. * * @param key key of the map * @param mKeys list of MKeys to get - * @param args arguments for get operation + * @param option get option - {@link GetOption} * @return map of MKey to value for found elements, * empty map if no MKeys are found, * {@code null} if the key is not found */ - ArcusFuture> mopGet(String key, List mKeys, GetArgs args); + ArcusFuture> mopGet(String key, List mKeys, GetOption option); /** * Delete all elements from a map. diff --git a/src/main/java/net/spy/memcached/v2/vo/GetArgs.java b/src/main/java/net/spy/memcached/v2/vo/GetArgs.java deleted file mode 100644 index 59529469a..000000000 --- a/src/main/java/net/spy/memcached/v2/vo/GetArgs.java +++ /dev/null @@ -1,42 +0,0 @@ -package net.spy.memcached.v2.vo; - -public final class GetArgs { - - public static final GetArgs DEFAULT = new GetArgs.Builder().build(); - - private final boolean withDelete; - private final boolean dropIfEmpty; - - private GetArgs(boolean withDelete, boolean dropIfEmpty) { - this.withDelete = withDelete; - this.dropIfEmpty = dropIfEmpty; - } - - public boolean isWithDelete() { - return withDelete; - } - - public boolean isDropIfEmpty() { - return dropIfEmpty; - } - - public static class Builder { - private boolean withDelete = false; - private boolean dropIfEmpty = false; - - public Builder withDelete() { - this.withDelete = true; - return this; - } - - public Builder dropIfEmpty() { - this.dropIfEmpty = true; - return this; - } - - public GetArgs build() { - return new GetArgs(withDelete, dropIfEmpty); - } - } - -} diff --git a/src/main/java/net/spy/memcached/v2/vo/GetOption.java b/src/main/java/net/spy/memcached/v2/vo/GetOption.java new file mode 100644 index 000000000..f610ba024 --- /dev/null +++ b/src/main/java/net/spy/memcached/v2/vo/GetOption.java @@ -0,0 +1,34 @@ +package net.spy.memcached.v2.vo; + +public enum GetOption { + /** + * Retrieves elements without deleting them. + */ + NONE(false, false), + + /** + * Retrieves elements and deletes them from the collection. + */ + DELETE(true, false), + + /** + * Retrieves elements, deletes them, and drops the collection if it becomes empty. + */ + DROP(true, true); + + private final boolean withDelete; + private final boolean dropIfEmpty; + + GetOption(boolean withDelete, boolean dropIfEmpty) { + this.withDelete = withDelete; + this.dropIfEmpty = dropIfEmpty; + } + + public boolean isWithDelete() { + return withDelete; + } + + public boolean isDropIfEmpty() { + return dropIfEmpty; + } +} diff --git a/src/test/java/net/spy/memcached/v2/AdminAsyncArcusCommandsTest.java b/src/test/java/net/spy/memcached/v2/AdminAsyncArcusCommandsTest.java index e4699878b..e71e5ce68 100644 --- a/src/test/java/net/spy/memcached/v2/AdminAsyncArcusCommandsTest.java +++ b/src/test/java/net/spy/memcached/v2/AdminAsyncArcusCommandsTest.java @@ -128,19 +128,19 @@ void flushNonPrefix() throws ExecutionException, InterruptedException, TimeoutEx // when async.flush("") - // then - .thenCompose(result -> { - assertTrue(result); - return async.get(prefixKey); - }) - .thenCompose(result -> { - assertNotNull(result); - assertEquals(VALUE, result); - return async.get(nonPrefixKey); - }) - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertTrue(result); + return async.get(prefixKey); + }) + .thenCompose(result -> { + assertNotNull(result); + assertEquals(VALUE, result); + return async.get(nonPrefixKey); + }) + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -166,10 +166,10 @@ void statsAllArgs() throws ExecutionException, InterruptedException, TimeoutExce for (StatsArg arg : StatsArg.values()) { // when async.stats(arg) - // then - .thenAccept(Assertions::assertNotNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNotNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } } diff --git a/src/test/java/net/spy/memcached/v2/BTreeAsyncArcusCommandsTest.java b/src/test/java/net/spy/memcached/v2/BTreeAsyncArcusCommandsTest.java index 8017576da..211cf3e3d 100644 --- a/src/test/java/net/spy/memcached/v2/BTreeAsyncArcusCommandsTest.java +++ b/src/test/java/net/spy/memcached/v2/BTreeAsyncArcusCommandsTest.java @@ -841,38 +841,38 @@ void bopUpdateSuccess() throws ExecutionException, InterruptedException, Timeout String key = keys.get(0); async.bopInsert(key, ELEMENTS.get(0), new CollectionAttributes()) - .thenCompose(result -> { - assertTrue(result); - return async.bopGet(key, BKey.of(1L), BopGetArgs.DEFAULT); - }) - .thenAccept(element -> { - assertNotNull(element); - assertEquals(ELEMENTS.get(0).getBKey(), element.getBKey()); - assertEquals(ELEMENTS.get(0).getValue(), element.getValue()); - assertNull(element.getEFlag()); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.bopGet(key, BKey.of(1L), BopGetArgs.DEFAULT); + }) + .thenAccept(element -> { + assertNotNull(element); + assertEquals(ELEMENTS.get(0).getBKey(), element.getBKey()); + assertEquals(ELEMENTS.get(0).getValue(), element.getValue()); + assertNull(element.getEFlag()); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); ElementFlagUpdate eFlagUpdate = new ElementFlagUpdate(new byte[]{1, 2, 3}); BTreeUpdateElement updatedElement = BTreeUpdateElement - .withValueAndEFlag(BKey.of(1L), "updated_value", eFlagUpdate); + .withValueAndEFlag(BKey.of(1L), "updated_value", eFlagUpdate); // when async.bopUpdate(key, updatedElement) - // then - .thenCompose(result -> { - assertTrue(result); - return async.bopGet(key, BKey.of(1L), BopGetArgs.DEFAULT); - }) - .thenAccept(result -> { - assertNotNull(result); - assertEquals(updatedElement.getBKey(), result.getBKey()); - assertEquals(updatedElement.getValue(), result.getValue()); - assertArrayEquals(eFlagUpdate.getElementFlag(), result.getEFlag()); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertTrue(result); + return async.bopGet(key, BKey.of(1L), BopGetArgs.DEFAULT); + }) + .thenAccept(result -> { + assertNotNull(result); + assertEquals(updatedElement.getBKey(), result.getBKey()); + assertEquals(updatedElement.getValue(), result.getValue()); + assertArrayEquals(eFlagUpdate.getElementFlag(), result.getEFlag()); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -881,28 +881,28 @@ void bopUpdateValueSuccess() throws ExecutionException, InterruptedException, Ti String key = keys.get(0); async.bopInsert(key, ELEMENTS.get(0), new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); BTreeUpdateElement updatedElement = BTreeUpdateElement - .withValue(BKey.of(1L), "updated_value"); + .withValue(BKey.of(1L), "updated_value"); // when async.bopUpdate(key, updatedElement) - // then - .thenCompose(result -> { - assertTrue(result); - return async.bopGet(key, BKey.of(1L), BopGetArgs.DEFAULT); - }) - .thenAccept(result -> { - assertNotNull(result); - assertEquals(updatedElement.getBKey(), result.getBKey()); - assertEquals(updatedElement.getValue(), result.getValue()); - assertNull(result.getEFlag()); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertTrue(result); + return async.bopGet(key, BKey.of(1L), BopGetArgs.DEFAULT); + }) + .thenAccept(result -> { + assertNotNull(result); + assertEquals(updatedElement.getBKey(), result.getBKey()); + assertEquals(updatedElement.getValue(), result.getValue()); + assertNull(result.getEFlag()); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -911,53 +911,53 @@ void bopUpdateEFlagSuccess() throws ExecutionException, InterruptedException, Ti String key = keys.get(0); async.bopInsert(key, ELEMENTS.get(0), new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); ElementFlagUpdate eFlagUpdate = new ElementFlagUpdate(new byte[]{1, 2, 3}); BTreeUpdateElement updatedElement = BTreeUpdateElement - .withEFlagUpdate(BKey.of(1L), eFlagUpdate); + .withEFlagUpdate(BKey.of(1L), eFlagUpdate); // when async.bopUpdate(key, updatedElement) - // then - .thenCompose(result -> { - assertTrue(result); - return async.bopGet(key, BKey.of(1L), BopGetArgs.DEFAULT); - }) - .thenAccept(result -> { - assertNotNull(result); - assertEquals(updatedElement.getBKey(), result.getBKey()); - assertEquals(ELEMENTS.get(0).getValue(), result.getValue()); - assertArrayEquals(eFlagUpdate.getElementFlag(), result.getEFlag()); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertTrue(result); + return async.bopGet(key, BKey.of(1L), BopGetArgs.DEFAULT); + }) + .thenAccept(result -> { + assertNotNull(result); + assertEquals(updatedElement.getBKey(), result.getBKey()); + assertEquals(ELEMENTS.get(0).getValue(), result.getValue()); + assertArrayEquals(eFlagUpdate.getElementFlag(), result.getEFlag()); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopUpdateNotFoundElement() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); ElementFlagUpdate eFlagUpdate = new ElementFlagUpdate(new byte[]{1, 2, 3}); BTreeUpdateElement updatedElement = BTreeUpdateElement - .withValueAndEFlag(BKey.of(1L), "updated_value", eFlagUpdate); + .withValueAndEFlag(BKey.of(1L), "updated_value", eFlagUpdate); // when async.bopUpdate(key, updatedElement) - // then - .thenAccept(Assertions::assertFalse) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertFalse) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -967,14 +967,14 @@ void bopUpdateNotFound() throws ExecutionException, InterruptedException, Timeou ElementFlagUpdate eFlagUpdate = new ElementFlagUpdate(new byte[]{1, 2, 3}); BTreeUpdateElement updatedElement = BTreeUpdateElement - .withValueAndEFlag(BKey.of(1L), "updated_value", eFlagUpdate); + .withValueAndEFlag(BKey.of(1L), "updated_value", eFlagUpdate); // when async.bopUpdate(key, updatedElement) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -985,16 +985,16 @@ void bopIncrSuccess() throws ExecutionException, InterruptedException, TimeoutEx BTreeElement element = new BTreeElement<>(bKey, "100", null); async.bopInsert(key, element, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopIncr(key, bKey, 10) - // then - .thenAccept(result -> assertEquals(110L, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(110L, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1005,10 +1005,10 @@ void bopIncrNotFound() throws ExecutionException, InterruptedException, TimeoutE // when async.bopIncr(key, bKey, 10) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1018,65 +1018,65 @@ void bopIncrNotFoundElement() throws ExecutionException, InterruptedException, T BKey bKey = BKey.of(999L); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopIncr(key, bKey, 10) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopIncrInitialNotExistsElement() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey bKey = BKey.of(999L); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopIncr(key, bKey, 10, 100L, null) - // then - .thenCompose(result -> { - assertEquals(100L, result); - return async.bopGet(key, bKey, BopGetArgs.DEFAULT); - }) - .thenAccept(result -> { - assertEquals(bKey, result.getBKey()); - assertEquals("100", result.getValue()); - assertNull(result.getEFlag()); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertEquals(100L, result); + return async.bopGet(key, bKey, BopGetArgs.DEFAULT); + }) + .thenAccept(result -> { + assertEquals(bKey, result.getBKey()); + assertEquals("100", result.getValue()); + assertNull(result.getEFlag()); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopIncrInitialExistingElement() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey bKey = BKey.of(1L); BTreeElement element = new BTreeElement<>(bKey, "100", null); async.bopInsert(key, element, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopIncr(key, bKey, 10, 1000L, null) - // then - .thenAccept(result -> assertEquals(110L, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(110L, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1086,20 +1086,20 @@ void bopIncrTypeMismatch() throws ExecutionException, InterruptedException, Time BKey bKey = BKey.of(1L); async.set(key, 60, "invalid-type-value") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopIncr(key, bKey, 10) - // then - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1108,20 +1108,20 @@ void bopIncrBKeyMismatch() throws ExecutionException, InterruptedException, Time String key = keys.get(0); async.bopInsert(key, ELEMENTS.get(0), new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopIncr(key, BKey.of(new byte[]{0x01}), 10) - // then - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("BKEY_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("BKEY_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1132,16 +1132,16 @@ void bopDecrSuccess() throws ExecutionException, InterruptedException, TimeoutEx BTreeElement element = new BTreeElement<>(bKey, "100", null); async.bopInsert(key, element, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDecr(key, bKey, 10) - // then - .thenAccept(result -> assertEquals(90L, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(90L, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1152,10 +1152,10 @@ void bopDecrNotFound() throws ExecutionException, InterruptedException, TimeoutE // when async.bopDecr(key, bKey, 10) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1165,57 +1165,57 @@ void bopDecrNotFoundElement() throws ExecutionException, InterruptedException, T BKey bKey = BKey.of(999L); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDecr(key, bKey, 10) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopDecrInitialNotExistsElement() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey bKey = BKey.of(999L); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDecr(key, bKey, 10, 100L, null) - // then - .thenAccept(result -> assertEquals(100L, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(100L, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopDecrInitialExistingElement() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey bKey = BKey.of(1L); BTreeElement element = new BTreeElement<>(bKey, "100", null); async.bopInsert(key, element, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDecr(key, bKey, 10, 1000L, null) - // then - .thenAccept(result -> assertEquals(90L, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(90L, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1226,16 +1226,16 @@ void bopDecrResultUnderZero() throws ExecutionException, InterruptedException, T BTreeElement element = new BTreeElement<>(bKey, "5", null); async.bopInsert(key, element, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDecr(key, bKey, 10) - // then - .thenAccept(result -> assertEquals(0L, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(0L, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1245,20 +1245,20 @@ void bopDecrTypeMismatch() throws ExecutionException, InterruptedException, Time BKey bKey = BKey.of(1L); async.set(key, 60, "invalid-type-value") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDecr(key, bKey, 10) - // then - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1267,51 +1267,51 @@ void bopDecrBKeyMismatch() throws ExecutionException, InterruptedException, Time String key = keys.get(0); async.bopInsert(key, ELEMENTS.get(0), new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDecr(key, BKey.of(new byte[]{0x01}), 10) - // then - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("BKEY_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("BKEY_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopGetPositionSuccess() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey bKey = ELEMENTS.get(1).getBKey(); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(0)); - }) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(1)); - }) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(0)); + }) + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(1)); + }) + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopGetPosition(key, bKey, BTreeOrder.ASC) - // then - .thenAccept(result -> { - assertNotNull(result); - assertEquals(1, result); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> { + assertNotNull(result); + assertEquals(1, result); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1322,53 +1322,53 @@ void bopGetPositionNotFound() throws ExecutionException, InterruptedException, T // when async.bopGetPosition(key, bKey, BTreeOrder.ASC) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopGetPositionNotFoundElement() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey bKey = BKey.of(1L); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopGetPosition(key, bKey, BTreeOrder.ASC) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopGetPositionTypeMismatch() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey bKey = BKey.of(1L); async.set(key, 60, "invalid-type-value") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopGetPosition(key, bKey, BTreeOrder.ASC) - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1379,308 +1379,306 @@ void bopGetByPositionSuccess() throws ExecutionException, InterruptedException, BTreeElement element = new BTreeElement<>(bKey, "value", null); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, element); - }) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, element); + }) + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopGetByPosition(key, 0, BTreeOrder.ASC) - // then - .thenAccept(result -> { - assertNotNull(result); - assertEquals(result, element); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> { + assertNotNull(result); + assertEquals(result, element); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopGetByPositionNotFound() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); // when async.bopGetByPosition(key, 0, BTreeOrder.ASC) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopGetByPositionNotFoundElement() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopGetByPosition(key, 0, BTreeOrder.ASC) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopGetByPositionTypeMismatch() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); async.set(key, 60, "invalid-type-value") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopGetByPosition(key, 0, BTreeOrder.ASC) - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopGetByPositionRangeSuccess() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(0)); - }) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(1)); - }) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(2)); - }) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(0)); + }) + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(1)); + }) + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(2)); + }) + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopGetByPosition(key, 0, 2, BTreeOrder.ASC) - // then - .thenAccept(result -> { - assertNotNull(result); - assertEquals(3, result.size()); - assertEquals(ELEMENTS.get(0), result.get(0)); - assertEquals(ELEMENTS.get(1), result.get(1)); - assertEquals(ELEMENTS.get(2), result.get(2)); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> { + assertNotNull(result); + assertEquals(3, result.size()); + assertEquals(ELEMENTS.get(0), result.get(0)); + assertEquals(ELEMENTS.get(1), result.get(1)); + assertEquals(ELEMENTS.get(2), result.get(2)); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopGetByPositionRangeNotFound() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); // when async.bopGetByPosition(key, 0, 2, BTreeOrder.ASC) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopGetByPositionRangeNotFoundElement() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopGetByPosition(key, 0, 2, BTreeOrder.ASC) - // then - .thenAccept(result -> { - assertNotNull(result); - assertTrue(result.isEmpty()); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> { + assertNotNull(result); + assertTrue(result.isEmpty()); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopGetByPositionRangeTypeMismatch() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); async.set(key, 60, "invalid-type-value") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopGetByPosition(key, 0, 2, BTreeOrder.ASC) - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopPositionWithGetSuccess() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey bKey = ELEMENTS.get(1).getBKey(); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(0)); - }) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(1)); - }) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(2)); - }) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(0)); + }) + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(1)); + }) + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(2)); + }) + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopPositionWithGet(key, bKey, 1, BTreeOrder.ASC) - // then - .thenAccept(result -> { - assertNotNull(result); - assertEquals(3, result.size()); - assertEquals(ELEMENTS.get(0).getBKey(), result.get(0).getBKey()); - assertEquals(ELEMENTS.get(0).getValue(), result.get(0).getValue()); - assertEquals(ELEMENTS.get(0).getEFlag(), result.get(0).getEFlag()); - assertEquals(0, result.get(0).getPosition()); - assertEquals(ELEMENTS.get(1).getBKey(), result.get(1).getBKey()); - assertEquals(ELEMENTS.get(1).getValue(), result.get(1).getValue()); - assertEquals(ELEMENTS.get(1).getEFlag(), result.get(1).getEFlag()); - assertEquals(1, result.get(1).getPosition()); - assertEquals(ELEMENTS.get(2).getBKey(), result.get(2).getBKey()); - assertEquals(ELEMENTS.get(2).getValue(), result.get(2).getValue()); - assertEquals(ELEMENTS.get(2).getEFlag(), result.get(2).getEFlag()); - assertEquals(2, result.get(2).getPosition()); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> { + assertNotNull(result); + assertEquals(3, result.size()); + assertEquals(ELEMENTS.get(0).getBKey(), result.get(0).getBKey()); + assertEquals(ELEMENTS.get(0).getValue(), result.get(0).getValue()); + assertEquals(ELEMENTS.get(0).getEFlag(), result.get(0).getEFlag()); + assertEquals(0, result.get(0).getPosition()); + assertEquals(ELEMENTS.get(1).getBKey(), result.get(1).getBKey()); + assertEquals(ELEMENTS.get(1).getValue(), result.get(1).getValue()); + assertEquals(ELEMENTS.get(1).getEFlag(), result.get(1).getEFlag()); + assertEquals(1, result.get(1).getPosition()); + assertEquals(ELEMENTS.get(2).getBKey(), result.get(2).getBKey()); + assertEquals(ELEMENTS.get(2).getValue(), result.get(2).getValue()); + assertEquals(ELEMENTS.get(2).getEFlag(), result.get(2).getEFlag()); + assertEquals(2, result.get(2).getPosition()); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopPositionWithGetNotFound() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey bKey = BKey.of(1L); // when async.bopPositionWithGet(key, bKey, 1, BTreeOrder.ASC) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopPositionWithGetNotFoundElement() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey bKey = BKey.of(999L); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(0)); - }) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(0)); + }) + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopPositionWithGet(key, bKey, 1, BTreeOrder.ASC) - // then - .thenAccept(result -> { - assertEquals(0, result.size()); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(0, result.size())) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopPositionWithGetTypeMismatch() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey bKey = BKey.of(1L); async.set(key, 60, "invalid-type-value") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopPositionWithGet(key, bKey, 1, BTreeOrder.ASC) - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopPositionWithGetBKeyMismatch() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey bKey = BKey.of(new byte[]{0x01}); async.bopInsert(key, ELEMENTS.get(0), new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopPositionWithGet(key, bKey, 1, BTreeOrder.ASC) - // then - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("BKEY_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("BKEY_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1690,23 +1688,23 @@ void bopDeleteSuccess() throws ExecutionException, InterruptedException, Timeout BKey bKey = ELEMENTS.get(0).getBKey(); async.bopInsert(key, ELEMENTS.get(0), new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDelete(key, bKey, BopDeleteArgs.DEFAULT) - // then - .thenCompose(result -> { - assertTrue(result); - return async.bopGet(key, bKey, BopGetArgs.DEFAULT); - }) - .thenAccept(result -> { - assertNotNull(result); - assertNull(result.getValue()); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertTrue(result); + return async.bopGet(key, bKey, BopGetArgs.DEFAULT); + }) + .thenAccept(result -> { + assertNotNull(result); + assertNull(result.getValue()); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1715,24 +1713,24 @@ void bopDeleteDropIfEmpty() throws ExecutionException, InterruptedException, Tim String key = keys.get(0); BKey bKey = ELEMENTS.get(0).getBKey(); BopDeleteArgs args = new BopDeleteArgs.Builder() - .dropIfEmpty() - .build(); + .dropIfEmpty() + .build(); async.bopInsert(key, ELEMENTS.get(0), new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDelete(key, bKey, args) - // then - .thenCompose(result -> { - assertTrue(result); - return async.bopGet(key, bKey, BopGetArgs.DEFAULT); - }) - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertTrue(result); + return async.bopGet(key, bKey, BopGetArgs.DEFAULT); + }) + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1743,30 +1741,30 @@ void bopDeleteNotFound() throws ExecutionException, InterruptedException, Timeou // when async.bopDelete(key, bKey, BopDeleteArgs.DEFAULT) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopDeleteNotFoundElement() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey bKey = BKey.of(999L); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDelete(key, bKey, BopDeleteArgs.DEFAULT) - // then - .thenAccept(Assertions::assertFalse) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertFalse) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1776,19 +1774,19 @@ void bopDeleteTypeMismatch() throws ExecutionException, InterruptedException, Ti BKey bKey = BKey.of(1L); async.set(key, 60, "invalid-type-value") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDelete(key, bKey, BopDeleteArgs.DEFAULT) - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1798,19 +1796,19 @@ void bopDeleteBKeyMismatch() throws ExecutionException, InterruptedException, Ti BKey bKey = BKey.of(new byte[]{0x01}); async.bopInsert(key, ELEMENTS.get(0) /* long BKey */, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDelete(key, bKey, BopDeleteArgs.DEFAULT) - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("BKEY_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("BKEY_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1820,38 +1818,38 @@ void bopDeleteByRangeSuccess() throws ExecutionException, InterruptedException, BKey from = ELEMENTS.get(0).getBKey(); BKey to = ELEMENTS.get(2).getBKey(); BopDeleteArgs deleteArgs = new BopDeleteArgs.Builder() - .count(1) - .build(); + .count(1) + .build(); async.bopInsert(key, ELEMENTS.get(0), new CollectionAttributes()) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(1)); - }) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(2)); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(1)); + }) + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(2)); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDelete(key, from, to, deleteArgs) - .thenCompose(result -> { - assertTrue(result); - return async.bopGet(key, from, to, BopGetArgs.DEFAULT); - }) - .thenAccept(result -> { - List> elements = result.getElements(); - assertEquals(2, elements.size()); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.bopGet(key, from, to, BopGetArgs.DEFAULT); + }) + .thenAccept(result -> { + List> elements = result.getElements(); + assertEquals(2, elements.size()); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopDeleteByRangeCountZero() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey from = BKey.of(0L); @@ -1859,33 +1857,33 @@ void bopDeleteByRangeCountZero() throws ExecutionException, InterruptedException BopDeleteArgs args = BopDeleteArgs.DEFAULT; async.bopInsert(key, ELEMENTS.get(0), new CollectionAttributes()) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(1)); - }) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(2)); - }) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(3)); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(1)); + }) + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(2)); + }) + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(3)); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDelete(key, from, to, args) - .thenCompose(result -> { - assertTrue(result); - return async.bopGet(key, from, to, BopGetArgs.DEFAULT); - }) - .thenAccept(result -> { - assertNotNull(result); - assertTrue(result.getElements().isEmpty()); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.bopGet(key, from, to, BopGetArgs.DEFAULT); + }) + .thenAccept(result -> { + assertNotNull(result); + assertTrue(result.getElements().isEmpty()); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -1898,40 +1896,40 @@ void bopDeleteByRangeEFlag() throws ExecutionException, InterruptedException, Ti ElementFlagFilter filter = new ElementFlagFilter(ElementFlagFilter.CompOperands.Equal, eFlag); BopDeleteArgs args = new BopDeleteArgs.Builder() - .eFlagFilter(filter) - .build(); + .eFlagFilter(filter) + .build(); BKey from = BKey.of(0L); BKey to = BKey.of(10L); async.bopInsert(key, elementWithFlag, new CollectionAttributes()) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, elementWithoutFlag); - }) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, elementWithoutFlag); + }) + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDelete(key, from, to, args) - // then - .thenCompose(result -> { - assertTrue(result); - return async.bopGet(key, from, to, BopGetArgs.DEFAULT); - }) - .thenAccept(result -> { - assertNotNull(result); - assertEquals(1, result.getElements().size()); - assertEquals(elementWithoutFlag, result.getElements().get(0)); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertTrue(result); + return async.bopGet(key, from, to, BopGetArgs.DEFAULT); + }) + .thenAccept(result -> { + assertNotNull(result); + assertEquals(1, result.getElements().size()); + assertEquals(elementWithoutFlag, result.getElements().get(0)); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopDeleteByRangeNotFound() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey from = BKey.of(0L); @@ -1939,79 +1937,79 @@ void bopDeleteByRangeNotFound() throws ExecutionException, InterruptedException, // when async.bopDelete(key, from, to, BopDeleteArgs.DEFAULT) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopDeleteByRangeNotFoundElement() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey from = BKey.of(100L); BKey to = BKey.of(200L); async.bopInsert(key, ELEMENTS.get(0), new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDelete(key, from, to, BopDeleteArgs.DEFAULT) - // then - .thenAccept(Assertions::assertFalse) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertFalse) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopDeleteByRangeTypeMismatch() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey from = BKey.of(0L); BKey to = BKey.of(10L); async.set(key, 60, "invalid-type-value") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDelete(key, from, to, BopDeleteArgs.DEFAULT) - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void bopDeleteByRangeBKeyMismatch() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); BKey from = BKey.of(new byte[]{0x00}); BKey to = BKey.of(new byte[]{0x10}); async.bopInsert(key, ELEMENTS.get(0), new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.bopDelete(key, from, to, BopDeleteArgs.DEFAULT) - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("BKEY_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("BKEY_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -2020,27 +2018,27 @@ void bopCountSuccess() throws ExecutionException, InterruptedException, TimeoutE String key = keys.get(0); async.bopInsert(key, ELEMENTS.get(0), new CollectionAttributes()) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(1)); - }) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, ELEMENTS.get(2)); - }) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(1)); + }) + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, ELEMENTS.get(2)); + }) + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when BKey from = ELEMENTS.get(0).getBKey(); BKey to = ELEMENTS.get(2).getBKey(); async.bopCount(key, from, to, ElementFlagFilter.DO_NOT_FILTER) - // then - .thenAccept(result -> assertEquals(3L, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(3L, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -2053,17 +2051,17 @@ void bopCountEFlagFilter() throws ExecutionException, InterruptedException, Time BTreeElement elementWithoutFlag = new BTreeElement<>(BKey.of(3L), "value3", null); async.bopInsert(key, elementWithFlag1, new CollectionAttributes()) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, elementWithFlag2); - }) - .thenCompose(result -> { - assertTrue(result); - return async.bopInsert(key, elementWithoutFlag); - }) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, elementWithFlag2); + }) + .thenCompose(result -> { + assertTrue(result); + return async.bopInsert(key, elementWithoutFlag); + }) + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when ElementFlagFilter filter = new ElementFlagFilter(ElementFlagFilter.CompOperands.Equal, eFlag); @@ -2071,10 +2069,10 @@ void bopCountEFlagFilter() throws ExecutionException, InterruptedException, Time BKey to = BKey.of(10L); async.bopCount(key, from, to, filter) - // then - .thenAccept(result -> assertEquals(2L, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(2L, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -2083,19 +2081,19 @@ void bopCountZero() throws ExecutionException, InterruptedException, TimeoutExce String key = keys.get(0); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when BKey from = BKey.of(0L); BKey to = BKey.of(100L); async.bopCount(key, from, to, ElementFlagFilter.DO_NOT_FILTER) - // then - .thenAccept(result -> assertEquals(0L, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(0L, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -2107,10 +2105,10 @@ void bopCountNotFound() throws ExecutionException, InterruptedException, Timeout // when async.bopCount(key, from, to, ElementFlagFilter.DO_NOT_FILTER) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -2119,23 +2117,23 @@ void bopCountTypeMismatch() throws ExecutionException, InterruptedException, Tim String key = keys.get(0); async.set(key, 60, "invalid-type-value") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when BKey from = BKey.of(0L); BKey to = BKey.of(10L); async.bopCount(key, from, to, ElementFlagFilter.DO_NOT_FILTER) - // then - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -2144,22 +2142,22 @@ void bopCountBKeyMismatch() throws ExecutionException, InterruptedException, Tim String key = keys.get(0); async.bopInsert(key, ELEMENTS.get(0), new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when BKey from = BKey.of(new byte[]{0x00}); BKey to = BKey.of(new byte[]{0x10}); async.bopCount(key, from, to, ElementFlagFilter.DO_NOT_FILTER) - // then - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("BKEY_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("BKEY_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } } diff --git a/src/test/java/net/spy/memcached/v2/KVAsyncArcusCommandsTest.java b/src/test/java/net/spy/memcached/v2/KVAsyncArcusCommandsTest.java index 170c28b8c..a4f42b737 100644 --- a/src/test/java/net/spy/memcached/v2/KVAsyncArcusCommandsTest.java +++ b/src/test/java/net/spy/memcached/v2/KVAsyncArcusCommandsTest.java @@ -19,8 +19,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -114,20 +114,20 @@ void appendString() throws ExecutionException, InterruptedException, TimeoutExce String key = keys.get(0); async.set(key, 60, "Hello, ") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.append(key, "Arcus!") - .thenCompose(result -> { - assertTrue(result); - return async.get(key); - }) - // then - .thenAccept(result -> assertEquals(expected, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.get(key); + }) + // then + .thenAccept(result -> assertEquals(expected, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -137,40 +137,40 @@ void prependString() throws ExecutionException, InterruptedException, TimeoutExc String key = keys.get(1); async.set(key, 60, "World!") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.prepend(key, "Hello, ") - .thenCompose(result -> { - assertTrue(result); - return async.get(key); - }) - // then - .thenAccept(result -> assertEquals(expected, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.get(key); + }) + // then + .thenAccept(result -> assertEquals(expected, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void appendNonStringException() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); async.set(key, 60, 123) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when CompletableFuture future = async.append(key, "Arcus!") - .thenCompose(result -> { - assertTrue(result); - return async.get(key); - }) - .toCompletableFuture(); + .thenCompose(result -> { + assertTrue(result); + return async.get(key); + }) + .toCompletableFuture(); // then assertThrows(ExecutionException.class, () -> future.get(300L, TimeUnit.MILLISECONDS)); } @@ -181,19 +181,19 @@ void testGets() throws ExecutionException, InterruptedException, TimeoutExceptio String key = keys.get(0); async.set(key, 60, VALUE) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.gets(key) - // then - .thenAccept(result -> { - assertEquals(VALUE, result.getValue()); - assertTrue(result.getCas() > 0); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> { + assertEquals(VALUE, result.getValue()); + assertTrue(result.getCas() > 0); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -202,56 +202,56 @@ void testCas() throws ExecutionException, InterruptedException, TimeoutException String key = keys.get(0); CASValue casValue = async.set(key, 60, "Hello") - .thenCompose(result -> { - assertTrue(result); - return async.gets(key); - }) - .thenApply(result -> { - assertEquals("Hello", result.getValue()); - assertTrue(result.getCas() >= 0); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.gets(key); + }) + .thenApply(result -> { + assertEquals("Hello", result.getValue()); + assertTrue(result.getCas() >= 0); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.cas(key, 60, "Arcus", casValue.getCas()) - .thenCompose(result -> { - assertTrue(result); - return async.get(key); - }) - // then - .thenAccept(result -> assertEquals("Arcus", result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.get(key); + }) + // then + .thenAccept(result -> assertEquals("Arcus", result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void casNotFound() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); long fakeCas = 1234L; async.set(key, 60, "Hello") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.cas(key, 60, "Arcus", fakeCas) - // then - .thenCompose(result -> { - assertFalse(result); - return async.get(key); - }) - .thenAccept(result -> { - assertNotEquals("Arcus", result); - assertEquals("Hello", result); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertFalse(result); + return async.get(key); + }) + .thenAccept(result -> { + assertNotEquals("Arcus", result); + assertEquals("Hello", result); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -260,83 +260,83 @@ void casExists() throws ExecutionException, InterruptedException, TimeoutExcepti String key = keys.get(0); CASValue casValue = async.set(key, 60, "Hello") - .thenCompose(result -> { - assertTrue(result); - return async.gets(key); - }) - .thenApply(result -> { - assertEquals("Hello", result.getValue()); - assertTrue(result.getCas() >= 0); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> { + assertTrue(result); + return async.gets(key); + }) + .thenApply(result -> { + assertEquals("Hello", result.getValue()); + assertTrue(result.getCas() >= 0); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); /* already updated by another client */ async.cas(key, 60, "Update", casValue.getCas()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.cas(key, 60, "Arcus", 0L) - // then - .thenCompose(result -> { - assertFalse(result); - return async.get(key); - }) - .thenAccept(result -> { - assertNotEquals("Arcus", result); - assertEquals("Update", result); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertFalse(result); + return async.get(key); + }) + .thenAccept(result -> { + assertNotEquals("Arcus", result); + assertEquals("Update", result); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void multiGetsSuccess() throws ExecutionException, InterruptedException, TimeoutException { // given async.multiSet(items, 60) - .thenAccept(result -> { - for (Boolean b : result.values()) { - assertTrue(b); - } - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(result -> { + for (Boolean b : result.values()) { + assertTrue(b); + } + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.multiGets(keys) - // then - .thenAccept(result -> { - assertEquals(keys.size(), result.size()); - for (Map.Entry> entry : result.entrySet()) { - assertEquals(VALUE, entry.getValue().getValue()); - assertTrue(entry.getValue().getCas() >= 0); - } - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> { + assertEquals(keys.size(), result.size()); + for (Map.Entry> entry : result.entrySet()) { + assertEquals(VALUE, entry.getValue().getValue()); + assertTrue(entry.getValue().getCas() >= 0); + } + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void multiGetsPartialFailure() throws ExecutionException, InterruptedException, TimeoutException { // given async.set(keys.get(0), 60, VALUE) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.multiGets(keys) - // then - .thenAccept(result -> { - assertEquals(1, result.size()); - assertTrue(result.containsKey(keys.get(0))); - assertEquals(VALUE, result.get(keys.get(0)).getValue()); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> { + assertEquals(1, result.size()); + assertTrue(result.containsKey(keys.get(0))); + assertEquals(VALUE, result.get(keys.get(0)).getValue()); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -344,10 +344,10 @@ void multiGetsNotFound() throws ExecutionException, InterruptedException, Timeou // given // when async.multiGets(keys) - // then - .thenAccept(result -> assertTrue(result.isEmpty())) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertTrue(result.isEmpty())) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -528,20 +528,20 @@ void deleteSuccess() throws ExecutionException, InterruptedException, TimeoutExc String key = keys.get(0); async.set(key, 0, VALUE) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.delete(key) - // then - .thenCompose(result -> { - assertTrue(result); - return async.get(key); - }) - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertTrue(result); + return async.get(key); + }) + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -551,59 +551,59 @@ void deleteNotFound() throws ExecutionException, InterruptedException, TimeoutEx // when async.delete(key) - // then - .thenAccept(Assertions::assertFalse) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertFalse) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void multiDeleteSuccess() throws ExecutionException, InterruptedException, TimeoutException { // given async.multiSet(items, 0) - .thenAccept(result -> { - for (Boolean b : result.values()) { - assertTrue(b); - } - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(result -> { + for (Boolean b : result.values()) { + assertTrue(b); + } + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.multiDelete(keys) - // then - .thenCompose(result -> { - assertEquals(keys.size(), result.size()); - result.values().forEach(Assertions::assertTrue); - return async.multiGet(keys); - }) - .thenAccept(result -> assertEquals(0, result.size())) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertEquals(keys.size(), result.size()); + result.values().forEach(Assertions::assertTrue); + return async.multiGet(keys); + }) + .thenAccept(result -> assertEquals(0, result.size())) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void multiDeletePartialSuccess() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given async.set(keys.get(0), 0, VALUE) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.multiDelete(keys) - // then - .thenAccept(result -> { - assertEquals(keys.size(), result.size()); - assertTrue(result.get(keys.get(0))); - for (int i = 1; i < keys.size(); i++) { - assertFalse(result.get(keys.get(i))); - } - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> { + assertEquals(keys.size(), result.size()); + assertTrue(result.get(keys.get(0))); + for (int i = 1; i < keys.size(); i++) { + assertFalse(result.get(keys.get(i))); + } + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -611,15 +611,15 @@ void multiDeleteNotFound() throws ExecutionException, InterruptedException, Time // given // when async.multiDelete(keys) - // then - .thenAccept(result -> { - assertEquals(keys.size(), result.size()); - for (Boolean b : result.values()) { - assertFalse(b); - } - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> { + assertEquals(keys.size(), result.size()); + for (Boolean b : result.values()) { + assertFalse(b); + } + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -629,16 +629,16 @@ void incrSuccess() throws ExecutionException, InterruptedException, TimeoutExcep int delta = 10; async.set(key, 60, "100") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.incr(key, delta) - // then - .thenAccept(result -> assertEquals(110L, result)) - .toCompletableFuture() - .get(300, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(110L, result)) + .toCompletableFuture() + .get(300, TimeUnit.MILLISECONDS); } @Test @@ -649,15 +649,15 @@ void incrNonExistingKey() throws ExecutionException, InterruptedException, Timeo // when async.incr(key, delta) - // then - .thenAccept(result -> assertEquals(-1, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(-1, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void incrInitialNonExistingKeySuccess() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); @@ -665,10 +665,10 @@ void incrInitialNonExistingKeySuccess() throws ExecutionException, InterruptedEx // when async.incr(key, delta, 100, 60) - // then - .thenAccept(result -> assertEquals(100L, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(100L, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -678,65 +678,65 @@ void incrInitialExistingKeySuccess() { int delta = 10; async.set(key, 60, "100") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .join(); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .join(); // when async.incr(key, delta, 1000, 60) - // then - .thenAccept(result -> assertEquals(110L, result)) - .toCompletableFuture() - .join(); + // then + .thenAccept(result -> assertEquals(110L, result)) + .toCompletableFuture() + .join(); } @Test void incrTypeNotNumberException() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); async.set(key, 60, "not a number") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.incr(key, 10) - // then - .handle((res, ex) -> { - assertInstanceOf(ExecutionException.class, ex); - Throwable cause = ex.getCause(); - assertTrue(cause.getMessage().contains("CLIENT_ERROR")); - return res; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((res, ex) -> { + assertInstanceOf(ExecutionException.class, ex); + Throwable cause = ex.getCause(); + assertTrue(cause.getMessage().contains("CLIENT_ERROR")); + return res; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void incrTypeMisMatchException() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.incr(key, 10) - // then - .handle((res, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return res; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((res, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return res; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -746,21 +746,21 @@ void decrSuccess() throws ExecutionException, InterruptedException, TimeoutExcep int delta = 10; async.set(key, 60, "100") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.decr(key, delta) - // then - .thenAccept(result -> assertEquals(90L, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(90L, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void decrNonExistingKey() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); @@ -768,15 +768,15 @@ void decrNonExistingKey() throws ExecutionException, InterruptedException, // when async.decr(key, delta) - // then - .thenAccept(result -> assertEquals(-1, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(-1, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void decrInitialNonExistingKeySuccess() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); @@ -784,102 +784,102 @@ void decrInitialNonExistingKeySuccess() throws ExecutionException, InterruptedEx // when async.decr(key, delta, 100, 60) - // then - .thenAccept(result -> assertEquals(100L, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(100L, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void decrInitialExistingKeySuccess() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); int delta = 10; async.set(key, 60, "100") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.decr(key, delta, 1000, 60) - // then - .thenAccept(result -> assertEquals(90L, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(90L, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void decrTypeNotNumberException() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); async.set(key, 60, "not a number") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.decr(key, 10) - // then - .handle((res, ex) -> { - assertInstanceOf(ExecutionException.class, ex); - Throwable cause = ex.getCause(); - assertTrue(cause.getMessage().contains("CLIENT_ERROR")); - return res; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((res, ex) -> { + assertInstanceOf(ExecutionException.class, ex); + Throwable cause = ex.getCause(); + assertTrue(cause.getMessage().contains("CLIENT_ERROR")); + return res; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void decrTypeMismatchException() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); // collection 타입 키를 생성해서 TypeMismatch 발생 async.bopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.decr(key, 10) - // then - .handle((res, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return res; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((res, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return res; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void decrResultUnderZero() throws ExecutionException, InterruptedException, - TimeoutException { + TimeoutException { // given String key = keys.get(0); int delta = 10; async.set(key, 60, "5") - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.decr(key, delta) - // then - .thenAccept(result -> assertEquals(0L, result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(result -> assertEquals(0L, result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } } diff --git a/src/test/java/net/spy/memcached/v2/ListAsyncArcusCommandsTest.java b/src/test/java/net/spy/memcached/v2/ListAsyncArcusCommandsTest.java index 6db6b67b6..ef191a911 100644 --- a/src/test/java/net/spy/memcached/v2/ListAsyncArcusCommandsTest.java +++ b/src/test/java/net/spy/memcached/v2/ListAsyncArcusCommandsTest.java @@ -7,7 +7,7 @@ import net.spy.memcached.collection.CollectionAttributes; import net.spy.memcached.collection.ElementValueType; import net.spy.memcached.ops.OperationException; -import net.spy.memcached.v2.vo.GetArgs; +import net.spy.memcached.v2.vo.GetOption; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -29,10 +29,10 @@ void lopCreate() throws Exception { // when async.lopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - // then - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -41,16 +41,16 @@ void lopCreateAlreadyExists() throws Exception { String key = keys.get(0); async.lopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.lopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - // then - .thenAccept(Assertions::assertFalse) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertFalse) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -59,16 +59,16 @@ void lopInsert() throws Exception { String key = keys.get(0); async.lopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.lopInsert(key, 0, VALUES.get(0)) - // then - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -76,10 +76,10 @@ void lopInsertNotFound() throws Exception { // given // when async.lopInsert(keys.get(0), 0, VALUES.get(0)) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -89,14 +89,14 @@ void lopInsertWithAttributes() throws Exception { // when async.lopInsert(key, 0, VALUES.get(0), new CollectionAttributes()) - // then - .thenCompose(result -> { - assertTrue(result); - return async.lopGet(key, 0, GetArgs.DEFAULT); - }) - .thenAccept(result -> assertEquals(VALUES.get(0), result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertTrue(result); + return async.lopGet(key, 0, GetOption.NONE); + }) + .thenAccept(result -> assertEquals(VALUES.get(0), result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -105,20 +105,20 @@ void lopInsertTypeMismatch() throws Exception { String key = keys.get(0); async.set(key, 0, VALUE) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.lopInsert(key, 0, VALUES.get(0), new CollectionAttributes()) - // then - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -127,27 +127,27 @@ void lopGetSingle() throws Exception { String key = keys.get(0); async.lopInsert(key, 0, VALUES.get(0), new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when - async.lopGet(key, 0, GetArgs.DEFAULT) - // then - .thenAccept(result -> assertEquals(VALUES.get(0), result)) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + async.lopGet(key, 0, GetOption.NONE) + // then + .thenAccept(result -> assertEquals(VALUES.get(0), result)) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void lopGetSingleNotFound() throws Exception { // given // when - async.lopGet(keys.get(0), 0, GetArgs.DEFAULT) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + async.lopGet(keys.get(0), 0, GetOption.NONE) + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -156,42 +156,38 @@ void lopGetSingleNotFoundElement() throws Exception { String key = keys.get(0); async.lopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when - async.lopGet(key, 5, GetArgs.DEFAULT) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + async.lopGet(key, 5, GetOption.NONE) + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void lopGetSingleWithDelete() throws Exception { // given String key = keys.get(0); - GetArgs args = new GetArgs.Builder() - .withDelete() - .dropIfEmpty() - .build(); async.lopInsert(key, 0, VALUES.get(0), new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when - async.lopGet(key, 0, args) - // then - .thenCompose(result -> { - assertEquals(VALUES.get(0), result); - return async.lopGet(key, 0, GetArgs.DEFAULT); - }) - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + async.lopGet(key, 0, GetOption.DROP) + // then + .thenCompose(result -> { + assertEquals(VALUES.get(0), result); + return async.lopGet(key, 0, GetOption.NONE); + }) + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -200,31 +196,31 @@ void lopGetRange() throws Exception { String key = keys.get(0); async.lopInsert(key, 0, VALUES.get(0), new CollectionAttributes()) - .thenCompose(result -> async.lopInsert(key, 1, VALUES.get(1))) - .thenCompose(result -> async.lopInsert(key, 2, VALUES.get(2))) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> async.lopInsert(key, 1, VALUES.get(1))) + .thenCompose(result -> async.lopInsert(key, 2, VALUES.get(2))) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when - async.lopGet(key, 0, 2, GetArgs.DEFAULT) - // then - .thenAccept(result -> { - result.forEach(Assertions::assertNotNull); - assertIterableEquals(VALUES.subList(0, 3), result); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + async.lopGet(key, 0, 2, GetOption.NONE) + // then + .thenAccept(result -> { + result.forEach(Assertions::assertNotNull); + assertIterableEquals(VALUES.subList(0, 3), result); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void lopGetRangeNotFound() throws Exception { // given // when - async.lopGet(keys.get(0), 0, 2, GetArgs.DEFAULT) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + async.lopGet(keys.get(0), 0, 2, GetOption.NONE) + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -233,43 +229,39 @@ void lopGetRangeNotFoundElement() throws Exception { String key = keys.get(0); async.lopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when - async.lopGet(key, 5, 10, GetArgs.DEFAULT) - // then - .thenAccept(result -> assertTrue(result.isEmpty())) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + async.lopGet(key, 5, 10, GetOption.NONE) + // then + .thenAccept(result -> assertTrue(result.isEmpty())) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void lopGetRangeWithDeleteAndDropIfEmpty() throws Exception { // given String key = keys.get(0); - GetArgs args = new GetArgs.Builder() - .withDelete() - .dropIfEmpty() - .build(); async.lopInsert(key, 0, VALUES.get(0), new CollectionAttributes()) - .thenCompose(result -> async.lopInsert(key, 1, VALUES.get(1))) - .thenCompose(result -> async.lopInsert(key, 2, VALUES.get(2))) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> async.lopInsert(key, 1, VALUES.get(1))) + .thenCompose(result -> async.lopInsert(key, 2, VALUES.get(2))) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when - async.lopGet(key, 0, 2, args) - .thenCompose(result -> { - assertNotNull(result); - assertIterableEquals(VALUES.subList(0, 3), result); - return async.lopGet(key, 0, 2, GetArgs.DEFAULT); - }) - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + async.lopGet(key, 0, 2, GetOption.DROP) + .thenCompose(result -> { + assertNotNull(result); + assertIterableEquals(VALUES.subList(0, 3), result); + return async.lopGet(key, 0, 2, GetOption.NONE); + }) + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -278,19 +270,19 @@ void lopDeleteSuccess() throws Exception { String key = keys.get(0); async.lopInsert(key, 0, VALUES.get(0), new CollectionAttributes()) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.lopDelete(key, 0, false) - // then - .thenCompose(result -> { - assertTrue(result); - return async.lopGet(key, 0, GetArgs.DEFAULT); - }) - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertTrue(result); + return async.lopGet(key, 0, GetOption.NONE); + }) + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -299,21 +291,21 @@ void lopDeleteRangeSuccess() throws Exception { String key = keys.get(0); async.lopInsert(key, 0, VALUES.get(0), new CollectionAttributes()) - .thenCompose(result -> async.lopInsert(key, 1, VALUES.get(1))) - .thenCompose(result -> async.lopInsert(key, 2, VALUES.get(2))) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> async.lopInsert(key, 1, VALUES.get(1))) + .thenCompose(result -> async.lopInsert(key, 2, VALUES.get(2))) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.lopDelete(key, 0, 2, false) - // then - .thenCompose(result -> { - assertTrue(result); - return async.lopGet(key, 0, 2, GetArgs.DEFAULT); - }) - .thenAccept(result -> assertTrue(result.isEmpty())) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertTrue(result); + return async.lopGet(key, 0, 2, GetOption.NONE); + }) + .thenAccept(result -> assertTrue(result.isEmpty())) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -322,25 +314,25 @@ void lopDeleteNotFoundElement() throws Exception { String key = keys.get(0); async.lopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.lopDelete(key, 0, false) - // then - .thenAccept(Assertions::assertFalse) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertFalse) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void lopDeleteNotFound() throws Exception { // when async.lopDelete(keys.get(0), 0, false) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -349,20 +341,20 @@ void lopDeleteTypeMismatch() throws Exception { String key = keys.get(0); async.set(key, 0, VALUE) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.lopDelete(key, 0, false) - // then - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } } diff --git a/src/test/java/net/spy/memcached/v2/MapAsyncArcusCommandsTest.java b/src/test/java/net/spy/memcached/v2/MapAsyncArcusCommandsTest.java index 721bb3c33..3915e637e 100644 --- a/src/test/java/net/spy/memcached/v2/MapAsyncArcusCommandsTest.java +++ b/src/test/java/net/spy/memcached/v2/MapAsyncArcusCommandsTest.java @@ -9,7 +9,7 @@ import net.spy.memcached.collection.CollectionAttributes; import net.spy.memcached.collection.ElementValueType; import net.spy.memcached.ops.OperationException; -import net.spy.memcached.v2.vo.GetArgs; +import net.spy.memcached.v2.vo.GetOption; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -99,7 +99,7 @@ void mopInsertWithAttributes() throws ExecutionException, InterruptedException, // then .thenCompose(result -> { assertTrue(result); - return async.mopGet(key, MKEY1, GetArgs.DEFAULT); + return async.mopGet(key, MKEY1, GetOption.NONE); }) .thenAccept(result -> assertEquals(VALUE1, result)) .toCompletableFuture() @@ -161,7 +161,7 @@ void mopUpsertInsert() throws ExecutionException, InterruptedException, TimeoutE // then .thenCompose(result -> { assertTrue(result); - return async.mopGet(key, MKEY1, GetArgs.DEFAULT); + return async.mopGet(key, MKEY1, GetOption.NONE); }) .thenAccept(result -> assertEquals(VALUE1, result)) .toCompletableFuture() @@ -183,7 +183,7 @@ void mopUpsertReplace() throws ExecutionException, InterruptedException, Timeout // then .thenCompose(result -> { assertTrue(result); - return async.mopGet(key, MKEY1, GetArgs.DEFAULT); + return async.mopGet(key, MKEY1, GetOption.NONE); }) .thenAccept(result -> assertEquals(VALUE2, result)) .toCompletableFuture() @@ -215,7 +215,7 @@ void mopUpdate() throws ExecutionException, InterruptedException, TimeoutExcepti // then .thenCompose(result -> { assertTrue(result); - return async.mopGet(key, MKEY1, GetArgs.DEFAULT); + return async.mopGet(key, MKEY1, GetOption.NONE); }) .thenAccept(result -> assertEquals(VALUE2, result)) .toCompletableFuture() @@ -264,7 +264,7 @@ void mopGetAll() throws ExecutionException, InterruptedException, TimeoutExcepti .get(300L, TimeUnit.MILLISECONDS); // when - async.mopGet(key, GetArgs.DEFAULT) + async.mopGet(key, GetOption.NONE) // then .thenAccept(result -> { assertNotNull(result); @@ -281,7 +281,7 @@ void mopGetAll() throws ExecutionException, InterruptedException, TimeoutExcepti void mopGetAllNotFound() throws ExecutionException, InterruptedException, TimeoutException { // given // when - async.mopGet(keys.get(0), GetArgs.DEFAULT) + async.mopGet(keys.get(0), GetOption.NONE) // then .thenAccept(Assertions::assertNull) .toCompletableFuture() @@ -300,7 +300,7 @@ void mopGetAllNotFoundElement() throws ExecutionException, InterruptedException, .get(300L, TimeUnit.MILLISECONDS); // when - async.mopGet(key, GetArgs.DEFAULT) + async.mopGet(key, GetOption.NONE) // then .thenAccept(result -> { assertNotNull(result); @@ -321,7 +321,7 @@ void mopGetSingle() throws ExecutionException, InterruptedException, TimeoutExce .get(300L, TimeUnit.MILLISECONDS); // when - async.mopGet(key, MKEY1, GetArgs.DEFAULT) + async.mopGet(key, MKEY1, GetOption.NONE) // then .thenAccept(result -> assertEquals(VALUE1, result)) .toCompletableFuture() @@ -332,7 +332,7 @@ void mopGetSingle() throws ExecutionException, InterruptedException, TimeoutExce void mopGetSingleNotFound() throws ExecutionException, InterruptedException, TimeoutException { // given // when - async.mopGet(keys.get(0), MKEY1, GetArgs.DEFAULT) + async.mopGet(keys.get(0), MKEY1, GetOption.NONE) // then .thenAccept(Assertions::assertNull) .toCompletableFuture() @@ -351,7 +351,7 @@ void mopGetSingleNotFoundElement() throws ExecutionException, InterruptedExcepti .get(300L, TimeUnit.MILLISECONDS); // when - async.mopGet(key, MKEY1, GetArgs.DEFAULT) + async.mopGet(key, MKEY1, GetOption.NONE) // then .thenAccept(Assertions::assertNull) .toCompletableFuture() @@ -371,7 +371,7 @@ void mopGetMultipleKeys() throws ExecutionException, InterruptedException, Timeo .get(300L, TimeUnit.MILLISECONDS); // when - async.mopGet(key, mKeys, GetArgs.DEFAULT) + async.mopGet(key, mKeys, GetOption.NONE) // then .thenAccept(result -> { assertNotNull(result); @@ -395,7 +395,7 @@ void mopGetMultipleKeysNotFoundElement() throws ExecutionException, InterruptedE .get(300L, TimeUnit.MILLISECONDS); // when - async.mopGet(key, Arrays.asList(MKEY1, MKEY2), GetArgs.DEFAULT) + async.mopGet(key, Arrays.asList(MKEY1, MKEY2), GetOption.NONE) // then .thenAccept(result -> { assertNotNull(result); @@ -417,7 +417,7 @@ void mopGetMultipleKeysPartialFound() throws ExecutionException, InterruptedExce .get(300L, TimeUnit.MILLISECONDS); // when - async.mopGet(key, Arrays.asList(MKEY1, MKEY2, MKEY3), GetArgs.DEFAULT) + async.mopGet(key, Arrays.asList(MKEY1, MKEY2, MKEY3), GetOption.NONE) // then .thenAccept(result -> { assertNotNull(result); @@ -433,10 +433,6 @@ void mopGetMultipleKeysPartialFound() throws ExecutionException, InterruptedExce void mopGetAllWithDelete() throws ExecutionException, InterruptedException, TimeoutException { // given String key = keys.get(0); - GetArgs args = new GetArgs.Builder() - .withDelete() - .dropIfEmpty() - .build(); async.mopInsert(key, MKEY1, VALUE1, new CollectionAttributes()) .thenAccept(Assertions::assertTrue) @@ -444,11 +440,11 @@ void mopGetAllWithDelete() throws ExecutionException, InterruptedException, Time .get(300L, TimeUnit.MILLISECONDS); // when - async.mopGet(key, args) + async.mopGet(key, GetOption.DROP) .thenCompose(result -> { assertNotNull(result); assertEquals(1, result.size()); - return async.mopGet(key, GetArgs.DEFAULT); + return async.mopGet(key, GetOption.NONE); }) // then .thenAccept(Assertions::assertNull) @@ -471,7 +467,7 @@ void mopDelete() throws ExecutionException, InterruptedException, TimeoutExcepti // then .thenCompose(result -> { assertTrue(result); - return async.mopGet(key, GetArgs.DEFAULT); + return async.mopGet(key, GetOption.NONE); }) .thenAccept(result -> { assertNotNull(result); @@ -495,7 +491,7 @@ void mopDeleteDropIfEmpty() throws ExecutionException, InterruptedException, Tim async.mopDelete(key, true) .thenCompose(result -> { assertTrue(result); - return async.mopGet(key, GetArgs.DEFAULT); + return async.mopGet(key, GetOption.NONE); }) // then .thenAccept(Assertions::assertNull) @@ -528,7 +524,7 @@ void mopDeleteSingle() throws ExecutionException, InterruptedException, TimeoutE // then .thenCompose(result -> { assertTrue(result); - return async.mopGet(key, GetArgs.DEFAULT); + return async.mopGet(key, GetOption.NONE); }) .thenAccept(result -> { assertNotNull(result); @@ -584,7 +580,7 @@ void mopDeleteSingleDropIfEmpty() throws ExecutionException, InterruptedExceptio async.mopDelete(key, MKEY1, true) .thenCompose(result -> { assertTrue(result); - return async.mopGet(key, GetArgs.DEFAULT); + return async.mopGet(key, GetOption.NONE); }) // then .thenAccept(Assertions::assertNull) @@ -615,7 +611,7 @@ void mopDeleteMultiple() throws ExecutionException, InterruptedException, Timeou // then .thenCompose(result -> { assertTrue(result); - return async.mopGet(key, GetArgs.DEFAULT); + return async.mopGet(key, GetOption.NONE); }) .thenAccept(result -> { assertNotNull(result); @@ -667,7 +663,7 @@ void mopDeleteMultipleDropIfEmpty() throws ExecutionException, InterruptedExcept // then .thenCompose(result -> { assertTrue(result); - return async.mopGet(key, GetArgs.DEFAULT); + return async.mopGet(key, GetOption.NONE); }) .thenAccept(Assertions::assertNull) .toCompletableFuture() diff --git a/src/test/java/net/spy/memcached/v2/SetAsyncArcusCommandsTest.java b/src/test/java/net/spy/memcached/v2/SetAsyncArcusCommandsTest.java index 307871909..5d499a69a 100644 --- a/src/test/java/net/spy/memcached/v2/SetAsyncArcusCommandsTest.java +++ b/src/test/java/net/spy/memcached/v2/SetAsyncArcusCommandsTest.java @@ -5,7 +5,7 @@ import net.spy.memcached.collection.CollectionAttributes; import net.spy.memcached.collection.ElementValueType; import net.spy.memcached.ops.OperationException; -import net.spy.memcached.v2.vo.GetArgs; +import net.spy.memcached.v2.vo.GetOption; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -24,10 +24,10 @@ void sopCreate() throws Exception { // when async.sopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - // then - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -36,16 +36,16 @@ void sopCreateAlreadyExists() throws Exception { String key = keys.get(0); async.sopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.sopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - // then - .thenAccept(Assertions::assertFalse) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertFalse) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -54,26 +54,26 @@ void sopInsert() throws Exception { String key = keys.get(0); async.sopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.sopInsert(key, VALUE) - // then - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void sopInsertNotFound() throws Exception { // when async.sopInsert(keys.get(0), VALUE) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -83,14 +83,14 @@ void sopInsertWithAttributes() throws Exception { // when async.sopInsert(key, VALUE, new CollectionAttributes()) - // then - .thenCompose(result -> { - assertTrue(result); - return async.sopExist(key, VALUE); - }) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertTrue(result); + return async.sopExist(key, VALUE); + }) + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -99,16 +99,16 @@ void sopInsertDuplicate() throws Exception { String key = keys.get(0); async.sopInsert(key, VALUE, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.sopInsert(key, VALUE) - // then - .thenAccept(Assertions::assertFalse) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertFalse) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -117,20 +117,20 @@ void sopInsertTypeMismatch() throws Exception { String key = keys.get(0); async.set(key, 0, VALUE) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.sopInsert(key, VALUE, new CollectionAttributes()) - // then - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -139,16 +139,16 @@ void sopExistTrue() throws Exception { String key = keys.get(0); async.sopInsert(key, VALUE, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.sopExist(key, VALUE) - // then - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -157,16 +157,16 @@ void sopExistFalse() throws Exception { String key = keys.get(0); async.sopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when: 존재하지 않는 값 조회 async.sopExist(key, VALUE) - // then - .thenAccept(Assertions::assertFalse) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertFalse) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -174,10 +174,10 @@ void sopExistNotFound() throws Exception { // given // when async.sopExist(keys.get(0), VALUE) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -186,20 +186,20 @@ void sopExistTypeMismatch() throws Exception { String key = keys.get(0); async.set(key, 0, VALUE) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.sopExist(key, VALUE) - // then - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -208,31 +208,31 @@ void sopGet() throws Exception { String key = keys.get(0); async.sopInsert(key, "v0", new CollectionAttributes()) - .thenCompose(result -> async.sopInsert(key, "v1")) - .thenCompose(result -> async.sopInsert(key, "v2")) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenCompose(result -> async.sopInsert(key, "v1")) + .thenCompose(result -> async.sopInsert(key, "v2")) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when - async.sopGet(key, 10, GetArgs.DEFAULT) - // then - .thenAccept(result -> { - assertNotNull(result); - assertEquals(3, result.size()); - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + async.sopGet(key, 10, GetOption.NONE) + // then + .thenAccept(result -> { + assertNotNull(result); + assertEquals(3, result.size()); + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void sopGetNotFound() throws Exception { // given // when - async.sopGet(keys.get(0), 10, GetArgs.DEFAULT) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + async.sopGet(keys.get(0), 10, GetOption.NONE) + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -241,42 +241,38 @@ void sopGetNotFoundElement() throws Exception { String key = keys.get(0); async.sopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when - async.sopGet(key, 10, GetArgs.DEFAULT) - // then - .thenAccept(result -> assertTrue(result.isEmpty())) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + async.sopGet(key, 10, GetOption.NONE) + // then + .thenAccept(result -> assertTrue(result.isEmpty())) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void sopGetWithDelete() throws Exception { // given String key = keys.get(0); - GetArgs args = new GetArgs.Builder() - .withDelete() - .dropIfEmpty() - .build(); async.sopInsert(key, VALUE, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when - async.sopGet(key, 10, args) - .thenCompose(result -> { - assertNotNull(result); - assertEquals(1, result.size()); - return async.sopGet(key, 10, GetArgs.DEFAULT); - }) - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + async.sopGet(key, 10, GetOption.DROP) + .thenCompose(result -> { + assertNotNull(result); + assertEquals(1, result.size()); + return async.sopGet(key, 10, GetOption.NONE); + }) + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -285,30 +281,30 @@ void sopDelete() throws Exception { String key = keys.get(0); async.sopInsert(key, VALUE, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.sopDelete(key, VALUE, false) - // then - .thenCompose(result -> { - assertTrue(result); - return async.sopExist(key, VALUE); - }) - .thenAccept(Assertions::assertFalse) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenCompose(result -> { + assertTrue(result); + return async.sopExist(key, VALUE); + }) + .thenAccept(Assertions::assertFalse) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test void sopDeleteNotFound() throws Exception { // when async.sopDelete(keys.get(0), VALUE, false) - // then - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -317,16 +313,16 @@ void sopDeleteNotFoundElement() throws Exception { String key = keys.get(0); async.sopCreate(key, ElementValueType.STRING, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.sopDelete(key, VALUE, false) - // then - .thenAccept(Assertions::assertFalse) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .thenAccept(Assertions::assertFalse) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -335,20 +331,20 @@ void sopDeleteDropIfEmpty() throws Exception { String key = keys.get(0); async.sopInsert(key, VALUE, new CollectionAttributes()) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when: 마지막 요소 삭제 + dropIfEmpty=true async.sopDelete(key, VALUE, true) - // then: set 자체가 삭제되어 null - .thenCompose(result -> { - assertTrue(result); - return async.sopGet(key, 10, GetArgs.DEFAULT); - }) - .thenAccept(Assertions::assertNull) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then: set 자체가 삭제되어 null + .thenCompose(result -> { + assertTrue(result); + return async.sopGet(key, 10, GetOption.NONE); + }) + .thenAccept(Assertions::assertNull) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } @Test @@ -357,19 +353,19 @@ void sopDeleteTypeMismatch() throws Exception { String key = keys.get(0); async.set(key, 0, VALUE) - .thenAccept(Assertions::assertTrue) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + .thenAccept(Assertions::assertTrue) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); // when async.sopDelete(key, VALUE, false) - // then - .handle((result, ex) -> { - assertInstanceOf(OperationException.class, ex); - assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); - return result; - }) - .toCompletableFuture() - .get(300L, TimeUnit.MILLISECONDS); + // then + .handle((result, ex) -> { + assertInstanceOf(OperationException.class, ex); + assertTrue(ex.getMessage().contains("TYPE_MISMATCH")); + return result; + }) + .toCompletableFuture() + .get(300L, TimeUnit.MILLISECONDS); } }