-
Notifications
You must be signed in to change notification settings - Fork 49
FEATURE: Add attribute get/set APIs #1102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletions
201
src/test/java/net/spy/memcached/v2/AttributesAsyncArcusCommandsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| package net.spy.memcached.v2; | ||
|
|
||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.TimeoutException; | ||
|
|
||
| import net.spy.memcached.collection.CollectionOverflowAction; | ||
| import net.spy.memcached.collection.CreateAttributes; | ||
| import net.spy.memcached.collection.ElementValueType; | ||
| import net.spy.memcached.ops.OperationException; | ||
| import net.spy.memcached.v2.attribute.UpdateAttributes; | ||
| import net.spy.memcached.v2.vo.BKey; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| public class AttributesAsyncArcusCommandsTest extends AsyncArcusCommandsTest { | ||
|
|
||
| @Test | ||
| void setKVAttributesSuccess() throws ExecutionException, InterruptedException, TimeoutException { | ||
| // given | ||
| String key = keys.get(0); | ||
|
|
||
| async.set(key, 0, VALUE) | ||
| .thenAccept(Assertions::assertTrue) | ||
| .toCompletableFuture() | ||
| .get(300L, TimeUnit.MILLISECONDS); | ||
|
|
||
| // when | ||
| UpdateAttributes attributes = UpdateAttributes.builder() | ||
| .expireTime(100L) | ||
| .build(); | ||
|
|
||
| async.setAttributes(key, attributes) | ||
| // then | ||
| .thenAccept(Assertions::assertTrue) | ||
| .toCompletableFuture() | ||
| .get(300L, TimeUnit.MILLISECONDS); | ||
| } | ||
|
|
||
| @Test | ||
| void setBTreeAttributesSuccess() | ||
| throws ExecutionException, InterruptedException, TimeoutException { | ||
| // given | ||
| String key = keys.get(0); | ||
|
|
||
| CreateAttributes createAttributes = CreateAttributes.builder() | ||
| .readable(false) | ||
| .build(); | ||
|
|
||
| async.bopCreate(key, ElementValueType.STRING, createAttributes) | ||
| .thenAccept(Assertions::assertTrue) | ||
| .toCompletableFuture() | ||
| .get(300L, TimeUnit.MILLISECONDS); | ||
|
|
||
| // when | ||
| UpdateAttributes attributes = UpdateAttributes.builder() | ||
| .expireTime(100L) | ||
| .maxCount(5_000L) | ||
| .overflowAction(CollectionOverflowAction.largest_trim) | ||
| .maxBKeyRange(BKey.of(10L)) | ||
| .readable() | ||
| .build(); | ||
|
|
||
| async.setAttributes(key, attributes) | ||
| .thenCompose(result -> { | ||
| assertTrue(result); | ||
| return async.getAttributes(key); | ||
| }) | ||
| .thenAccept(result -> { | ||
| assertNotNull(result); | ||
| assertEquals(100L, result.getExpireTime()); | ||
| assertEquals(5_000L, result.getMaxCount()); | ||
| assertEquals(CollectionOverflowAction.largest_trim, result.getOverflowAction()); | ||
| assertEquals(true, result.getReadable()); | ||
| }) | ||
| .toCompletableFuture() | ||
| .get(300L, TimeUnit.MILLISECONDS); | ||
| } | ||
|
|
||
| @Test | ||
| void setAttributesFailureKeyNotFound() | ||
| throws ExecutionException, InterruptedException, TimeoutException { | ||
| // given | ||
| String key = keys.get(0); | ||
|
|
||
| UpdateAttributes attributes = UpdateAttributes.builder() | ||
| .expireTime(100L) | ||
| .build(); | ||
|
|
||
| // when | ||
| async.setAttributes(key, attributes) | ||
| // then | ||
| .thenAccept(Assertions::assertFalse) | ||
| .toCompletableFuture() | ||
| .get(300L, TimeUnit.MILLISECONDS); | ||
| } | ||
|
|
||
| @Test | ||
| void setAttributesFailureMapOverflowAction() | ||
| throws ExecutionException, InterruptedException, TimeoutException { | ||
| // given | ||
| String key = keys.get(0); | ||
|
|
||
| async.mopCreate(key, ElementValueType.STRING, CreateAttributes.DEFAULT) | ||
| .thenAccept(Assertions::assertTrue) | ||
| .toCompletableFuture() | ||
| .get(300L, TimeUnit.MILLISECONDS); | ||
|
|
||
| UpdateAttributes attributes = UpdateAttributes.builder() | ||
| .overflowAction(CollectionOverflowAction.smallest_trim) | ||
| .build(); | ||
|
|
||
| // when | ||
| async.setAttributes(key, attributes) | ||
| // then | ||
| .handle((result, ex) -> { | ||
| assertInstanceOf(OperationException.class, ex); | ||
| assertTrue(ex.getMessage().contains("ATTR_ERROR")); | ||
| return result; | ||
| }) | ||
| .toCompletableFuture() | ||
| .get(300L, TimeUnit.MILLISECONDS); | ||
| } | ||
|
|
||
| @Test | ||
| void setAttributesFailureSetOverflowAction() | ||
| throws ExecutionException, InterruptedException, TimeoutException { | ||
| // given | ||
| String key = keys.get(0); | ||
|
|
||
| async.sopCreate(key, ElementValueType.STRING, CreateAttributes.DEFAULT) | ||
| .thenAccept(Assertions::assertTrue) | ||
| .toCompletableFuture() | ||
| .get(300L, TimeUnit.MILLISECONDS); | ||
|
|
||
| UpdateAttributes attributes = UpdateAttributes.builder() | ||
| .overflowAction(CollectionOverflowAction.largest_trim) | ||
| .build(); | ||
|
|
||
| // when | ||
| async.setAttributes(key, attributes) | ||
| // then | ||
| .handle((result, ex) -> { | ||
| assertInstanceOf(OperationException.class, ex); | ||
| assertTrue(ex.getMessage().contains("ATTR_ERROR")); | ||
| return result; | ||
| }) | ||
| .toCompletableFuture() | ||
| .get(300L, TimeUnit.MILLISECONDS); | ||
| } | ||
|
|
||
| @Test | ||
| void getAttributesSuccess() throws ExecutionException, InterruptedException, TimeoutException { | ||
| // given | ||
| String key = keys.get(0); | ||
|
|
||
| CreateAttributes attributes = CreateAttributes.builder() | ||
| .expireTime(100L) | ||
| .maxCount(5000L) | ||
| .overflowAction(CollectionOverflowAction.smallest_trim) | ||
| .build(); | ||
|
|
||
| async.bopCreate(key, ElementValueType.STRING, attributes) | ||
| .thenAccept(Assertions::assertTrue) | ||
| .toCompletableFuture() | ||
| .get(300L, TimeUnit.MILLISECONDS); | ||
|
|
||
| // when | ||
| async.getAttributes(key) | ||
| // then | ||
| .thenAccept(result -> { | ||
| assertNotNull(result); | ||
| assertTrue(result.getExpireTime() <= 100L); | ||
| assertEquals(5_000L, result.getMaxCount()); | ||
| assertEquals(CollectionOverflowAction.smallest_trim, result.getOverflowAction()); | ||
| }) | ||
| .toCompletableFuture() | ||
| .get(300L, TimeUnit.MILLISECONDS); | ||
| } | ||
|
|
||
| @Test | ||
| void getAttributesFailureKeyNotFound() | ||
| throws ExecutionException, InterruptedException, TimeoutException { | ||
| // given | ||
| String key = keys.get(0); | ||
|
|
||
| // when | ||
| async.getAttributes(key) | ||
| // then | ||
| .thenAccept(Assertions::assertNull) | ||
| .toCompletableFuture() | ||
| .get(300L, TimeUnit.MILLISECONDS); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readable = true 설정 경우만 있어서, 인자를 제외한 것이네요.
collection create 하는 경우는 unreadble 설정만 가능하지만,
readable()에서 true/false 값을 받고 있습니다. 참고 바랍니다.