Skip to content

Commit

Permalink
FIX: Element sequence when using asyncLopInsert api.
Browse files Browse the repository at this point in the history
  • Loading branch information
brido4125 committed Jun 29, 2023
1 parent 81b2465 commit 2984dca
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ public ByteBuffer getAsciiCommand() {
CollectionCreate.makeCreateClause(attribute, cd.getFlags()) : "";
for (int i = this.nextOpIndex; i < eSize; i++) {
byte[] each = encodedList.get(i);
setArguments(bb, COMMAND, key, index, each.length,
int eIndex = index;
if (index >= 0) {
eIndex += i;
}
setArguments(bb, COMMAND, key, eIndex, each.length,
createOption, (i < eSize - 1) ? PIPE : "");
bb.put(each);
bb.put(CRLF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,53 @@ public void testLopPipeInsert() {
}
}

public void testLopPipeInsertIndex() {
int elementCount = 3;
List<Object> middleElements = new ArrayList<Object>(elementCount);
List<Object> headerElements = new ArrayList<Object>(elementCount);
List<Object> footerElements = new ArrayList<Object>(elementCount);

for (int i = 0; i < elementCount; i++) {
middleElements.add("middleValue" + i);
headerElements.add("headerValue" + i);
footerElements.add("footerValue" + i);
}

try {
CollectionAttributes attr = new CollectionAttributes();
mc.asyncLopInsert(KEY, 0, "FirstValue", attr).get(5000L, TimeUnit.MILLISECONDS);
mc.asyncLopInsert(KEY, -1, "LastValue", attr).get(5000L, TimeUnit.MILLISECONDS);

CollectionFuture<Map<Integer, CollectionOperationStatus>> future1 =
mc.asyncLopPipedInsertBulk(KEY, 1, middleElements, attr);
CollectionFuture<Map<Integer, CollectionOperationStatus>> future2 =
mc.asyncLopPipedInsertBulk(KEY, 0, headerElements, attr);
CollectionFuture<Map<Integer, CollectionOperationStatus>> future3 =
mc.asyncLopPipedInsertBulk(KEY, -1, footerElements, attr);

Map<Integer, CollectionOperationStatus> map1
= future1.get(5000L, TimeUnit.MILLISECONDS);
Map<Integer, CollectionOperationStatus> map2
= future2.get(5000L, TimeUnit.MILLISECONDS);
Map<Integer, CollectionOperationStatus> map3
= future3.get(5000L, TimeUnit.MILLISECONDS);
Assert.assertEquals(map1.size() + map2.size() + map3.size(), 0);

List<Object> list = mc.asyncLopGet(KEY, 0, 9999, false, false).get();
Assert.assertEquals((elementCount * 3) + 2, list.size());

int offset = 0;
Assert.assertEquals(headerElements, list.subList(offset, offset + elementCount));
offset += (elementCount + 1);
Assert.assertEquals(middleElements, list.subList(offset, offset + elementCount));
offset += (elementCount + 1);
Assert.assertEquals(footerElements, list.subList(offset, offset + elementCount));
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}

public void testMopPipeInsert() {
int elementCount = 5000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testInsertWithAttribute() {
attr.setMaxCount(3333);

List<Object> valueList = new ArrayList<Object>();
for (int i = 1; i < 11; i++) {
for (int i = 1; i <= 10; i++) {
valueList.add(i);
}

Expand All @@ -73,8 +73,8 @@ public void testInsertWithAttribute() {

// check values
List<Object> list2 = mc.asyncLopGet(KEY, 0, 10, false, false).get();
for (int i = 0; i < list2.size(); i++) {
Assert.assertEquals(10 - i, list2.get(i));
for (int i = 1; i <= list2.size(); i++) {
Assert.assertEquals(i, list2.get(i - 1));
}

// check expire time
Expand All @@ -96,7 +96,7 @@ public void testInsertWithDefaultAttribute() {
CollectionAttributes attr = new CollectionAttributes();

List<Object> valueList = new ArrayList<Object>();
for (int i = 1; i < 11; i++) {
for (int i = 1; i <= 10; i++) {
valueList.add(i);
}

Expand All @@ -113,8 +113,8 @@ public void testInsertWithDefaultAttribute() {

// check values
List<Object> list2 = mc.asyncLopGet(KEY, 0, 10, false, false).get();
for (int i = 0; i < list2.size(); i++) {
Assert.assertEquals(10 - i, list2.get(i));
for (int i = 1; i <= list2.size(); i++) {
Assert.assertEquals(i, list2.get(i - 1));
}
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -128,7 +128,7 @@ public void testInsertWithoutAttributeCreate() {
Assert.assertNull(mc.asyncGetAttr(KEY).get());

List<Object> valueList = new ArrayList<Object>();
for (int i = 1; i < 11; i++) {
for (int i = 1; i <= 10; i++) {
valueList.add(i);
}

Expand All @@ -146,8 +146,8 @@ public void testInsertWithoutAttributeCreate() {

// check values
List<Object> list2 = mc.asyncLopGet(KEY, 0, 10, false, false).get();
for (int i = 0; i < list2.size(); i++) {
Assert.assertEquals(10 - i, list2.get(i));
for (int i = 1; i <= list2.size(); i++) {
Assert.assertEquals(i, list2.get(i - 1));
}
} catch (Exception e) {
e.printStackTrace();
Expand Down

0 comments on commit 2984dca

Please sign in to comment.