Skip to content

Commit

Permalink
FIX: use proper index when lop piped insert
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviarla committed Feb 21, 2025
1 parent 8c9a6e3 commit 09fcf74
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/main/java/net/spy/memcached/ArcusClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,9 @@ public <T> CollectionFuture<Map<Integer, CollectionOperationStatus>> asyncLopPip
PartitionedList<T> list = new PartitionedList<>(valueList, MAX_PIPED_ITEM_COUNT);
for (List<T> elementList : list) {
insertList.add(new ListPipedInsert<>(key, index, elementList, attributesForCreate, tc));
if (index >= 0) {
index += elementList.size();
}
}
}
return asyncCollectionPipedInsert(key, insertList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ void testBopPipeInsert2() {
}

try {
long start = System.currentTimeMillis();

CollectionAttributes attr = new CollectionAttributes();

CollectionFuture<Map<Integer, CollectionOperationStatus>> future = mc
Expand All @@ -109,8 +107,6 @@ void testBopPipeInsert2() {
Map<Integer, CollectionOperationStatus> map = future.get(5000L,
TimeUnit.MILLISECONDS);

// System.out.println(System.currentTimeMillis() - start + "ms");

assertTrue(map.isEmpty());

Map<Long, Element<Object>> map3 = mc.asyncBopGet(KEY, 0, 9999,
Expand All @@ -125,7 +121,7 @@ void testBopPipeInsert2() {
}

@Test
void testLopPipeInsert() {
void testLopPipeInsertLast() {
int elementCount = 5000;

List<Object> elements = new ArrayList<>(elementCount);
Expand All @@ -135,8 +131,6 @@ void testLopPipeInsert() {
}

try {
long start = System.currentTimeMillis();

CollectionAttributes attr = new CollectionAttributes();

CollectionFuture<Map<Integer, CollectionOperationStatus>> future = mc
Expand All @@ -145,14 +139,47 @@ void testLopPipeInsert() {
Map<Integer, CollectionOperationStatus> map = future.get(5000L,
TimeUnit.MILLISECONDS);

// System.out.println(System.currentTimeMillis() - start + "ms");
assertTrue(map.isEmpty());

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

assertEquals(4000, list.size());
assertEquals("value1000", list.get(0));
assertEquals("value1501", list.get(501));
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
void testLopPipeInsertFirst() {
int elementCount = 4000;

List<Object> elements = new ArrayList<>(elementCount);

for (int i = 0; i < elementCount; i++) {
elements.add("value" + i);
}

try {
CollectionAttributes attr = new CollectionAttributes();

CollectionFuture<Map<Integer, CollectionOperationStatus>> future = mc
.asyncLopPipedInsertBulk(KEY, 0, elements, attr);

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

assertTrue(map.isEmpty());

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

assertEquals(4000, list.size());
assertEquals("value0", list.get(0));
assertEquals("value501", list.get(501));
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
Expand Down Expand Up @@ -190,7 +217,7 @@ void testLopPipeInsertIndex() {
= future2.get(5000L, TimeUnit.MILLISECONDS);
Map<Integer, CollectionOperationStatus> map3
= future3.get(5000L, TimeUnit.MILLISECONDS);
assertEquals(map1.size() + map2.size() + map3.size(), 0);
assertEquals(0, map1.size() + map2.size() + map3.size());

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

0 comments on commit 09fcf74

Please sign in to comment.