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 28, 2023
1 parent 81b2465 commit ec5b3eb
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 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 offset = i;
if (index < 0) {
offset = 0;
}
setArguments(bb, COMMAND, key, index + offset, 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,57 @@ 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();

System.out.println("list = " + list);

Assert.assertEquals((elementCount * 3) + 2, list.size());

Assert.assertEquals(headerElements, list.subList(0, elementCount));
Assert.assertEquals(middleElements, list.subList(elementCount + 1, elementCount * 2 + 1));
Assert.assertEquals(footerElements, list.subList(elementCount * 3 - 1 , elementCount * 3 + 2));
} 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 @@ -74,7 +74,7 @@ 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));
Assert.assertEquals(i + 1, list2.get(i));
}

// check expire time
Expand Down Expand Up @@ -114,7 +114,7 @@ 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));
Assert.assertEquals(i + 1, list2.get(i));
}
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -147,7 +147,7 @@ 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));
Assert.assertEquals(i + 1, list2.get(i));
}
} catch (Exception e) {
e.printStackTrace();
Expand Down

0 comments on commit ec5b3eb

Please sign in to comment.