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 4b7d56a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ 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,
setArguments(bb, COMMAND, key, index + i, 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,41 @@ public void testLopPipeInsert() {
}
}

public void testLopPipeInsertIndex() {
int elementCount = 10;
List<Object> elements = new ArrayList<Object>(elementCount);

for (int i = 0; i < elementCount; i++) {
elements.add("value" + 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>> future = mc
.asyncLopPipedInsertBulk(KEY, 1, elements, attr);

Map<Integer, CollectionOperationStatus> map = future.get(5000L,
TimeUnit.MILLISECONDS);

Assert.assertTrue(map.isEmpty());

List<Object> list = mc.asyncLopGet(KEY, 0, 9999, false, false)
.get();

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

Assert.assertEquals(elements, list.subList(1, elementCount + 1));
} 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 4b7d56a

Please sign in to comment.