use of com.aerospike.client.Value in project aerospike-client-java by aerospike.
the class TestOperateList method operateList3.
@Test
public void operateList3() {
// Test out of bounds conditions
Key key = new Key(args.namespace, args.set, "oplkey3");
client.delete(null, key);
List<Value> itemList = new ArrayList<Value>();
itemList.add(Value.get("str1"));
itemList.add(Value.get("str2"));
itemList.add(Value.get("str3"));
itemList.add(Value.get("str4"));
itemList.add(Value.get("str5"));
itemList.add(Value.get("str6"));
itemList.add(Value.get("str7"));
Record record = client.operate(null, key, ListOperation.appendItems(binName, itemList), ListOperation.get(binName, 2), ListOperation.getRange(binName, 6, 4), ListOperation.getRange(binName, -7, 3), ListOperation.getRange(binName, 0, 2), ListOperation.getRange(binName, -2, 4));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
List<?> list = record.getList(binName);
long size = (Long) list.get(0);
assertEquals(7, size);
assertEquals("str3", (String) list.get(1));
List<?> rangeList = (List<?>) list.get(2);
assertEquals(1, rangeList.size());
assertEquals("str7", (String) rangeList.get(0));
rangeList = (List<?>) list.get(3);
assertEquals(3, rangeList.size());
assertEquals("str1", (String) rangeList.get(0));
assertEquals("str2", (String) rangeList.get(1));
assertEquals("str3", (String) rangeList.get(2));
rangeList = (List<?>) list.get(4);
assertEquals(2, rangeList.size());
assertEquals("str1", (String) rangeList.get(0));
assertEquals("str2", (String) rangeList.get(1));
rangeList = (List<?>) list.get(5);
assertEquals(2, rangeList.size());
assertEquals("str6", (String) rangeList.get(0));
assertEquals("str7", (String) rangeList.get(1));
}
use of com.aerospike.client.Value in project aerospike-client-java by aerospike.
the class TestOperateList method operateList8.
@Test
public void operateList8() {
// Test increment.
Key key = new Key(args.namespace, args.set, "oplkey8");
client.delete(null, key);
List<Value> itemList = new ArrayList<Value>();
itemList.add(Value.get(1));
itemList.add(Value.get(2));
itemList.add(Value.get(3));
Record record = client.operate(null, key, ListOperation.appendItems(binName, itemList), ListOperation.increment(binName, 2), ListOperation.increment(ListPolicy.Default, binName, 2), ListOperation.increment(binName, 1, Value.get(7)), ListOperation.increment(ListPolicy.Default, binName, 1, Value.get(7)), ListOperation.get(binName, 0));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
List<?> results = record.getList(binName);
int i = 0;
long size = (Long) results.get(i++);
assertEquals(3, size);
long val = (Long) results.get(i++);
assertEquals(4, val);
val = (Long) results.get(i++);
assertEquals(5, val);
val = (Long) results.get(i++);
assertEquals(9, val);
val = (Long) results.get(i++);
assertEquals(16, val);
val = (Long) results.get(i++);
assertEquals(1, val);
}
use of com.aerospike.client.Value in project aerospike-client-java by aerospike.
the class TestOperateMap method operateMapInverted.
@Test
public void operateMapInverted() {
if (!args.validateMap()) {
return;
}
Key key = new Key(args.namespace, args.set, "opmkey12");
client.delete(null, key);
Map<Value, Value> inputMap = new HashMap<Value, Value>();
inputMap.put(Value.get("Charlie"), Value.get(55));
inputMap.put(Value.get("Jim"), Value.get(98));
inputMap.put(Value.get("John"), Value.get(76));
inputMap.put(Value.get("Harry"), Value.get(82));
// Write values to empty map.
Record record = client.operate(null, key, MapOperation.putItems(MapPolicy.Default, binName, inputMap));
assertRecordFound(key, record);
List<Value> valueList = new ArrayList<Value>();
valueList.add(Value.get(76));
valueList.add(Value.get(55));
valueList.add(Value.get(98));
valueList.add(Value.get(50));
record = client.operate(null, key, MapOperation.getByValue(binName, Value.get(81), MapReturnType.RANK | MapReturnType.INVERTED), MapOperation.getByValue(binName, Value.get(82), MapReturnType.RANK | MapReturnType.INVERTED), MapOperation.getByValueRange(binName, Value.get(90), Value.get(95), MapReturnType.RANK | MapReturnType.INVERTED), MapOperation.getByValueRange(binName, Value.get(90), Value.get(100), MapReturnType.RANK | MapReturnType.INVERTED), MapOperation.getByValueList(binName, valueList, MapReturnType.KEY_VALUE | MapReturnType.INVERTED), MapOperation.getByRankRange(binName, -2, 2, MapReturnType.KEY | MapReturnType.INVERTED), MapOperation.getByRankRange(binName, 0, 3, MapReturnType.KEY_VALUE | MapReturnType.INVERTED));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
List<?> results = record.getList(binName);
int i = 0;
List<?> list = (List<?>) results.get(i++);
assertEquals(4L, list.size());
list = (List<?>) results.get(i++);
assertEquals(3L, list.size());
list = (List<?>) results.get(i++);
assertEquals(4L, list.size());
list = (List<?>) results.get(i++);
assertEquals(3L, list.size());
assertEquals(0L, list.get(0));
assertEquals(1L, list.get(1));
assertEquals(2L, list.get(2));
list = (List<?>) results.get(i++);
assertEquals(1L, list.size());
Entry<?, ?> entry = (Entry<?, ?>) list.get(0);
assertEquals("Harry", entry.getKey());
assertEquals(82L, entry.getValue());
list = (List<?>) results.get(i++);
assertEquals(2L, list.size());
assertEquals("Charlie", list.get(0));
assertEquals("John", list.get(1));
list = (List<?>) results.get(i++);
assertEquals(1L, list.size());
entry = (Entry<?, ?>) list.get(0);
assertEquals("Jim", entry.getKey());
assertEquals(98L, entry.getValue());
}
use of com.aerospike.client.Value in project aerospike-client-java by aerospike.
the class TestOperateMap method operateMapRemoveRange.
@Test
public void operateMapRemoveRange() {
// Test remove ranges.
if (!args.validateMap()) {
return;
}
Key key = new Key(args.namespace, args.set, "opmkey8");
client.delete(null, key);
Map<Value, Value> inputMap = new HashMap<Value, Value>();
inputMap.put(Value.get("Charlie"), Value.get(55));
inputMap.put(Value.get("Jim"), Value.get(98));
inputMap.put(Value.get("John"), Value.get(76));
inputMap.put(Value.get("Harry"), Value.get(82));
inputMap.put(Value.get("Sally"), Value.get(79));
inputMap.put(Value.get("Lenny"), Value.get(84));
inputMap.put(Value.get("Abe"), Value.get(88));
Record record = client.operate(null, key, MapOperation.putItems(MapPolicy.Default, binName, inputMap), MapOperation.removeByKeyRange(binName, Value.get("J"), Value.get("K"), MapReturnType.COUNT), MapOperation.removeByValueRange(binName, Value.get(80), Value.get(85), MapReturnType.COUNT), MapOperation.removeByIndexRange(binName, 0, 2, MapReturnType.COUNT), MapOperation.removeByRankRange(binName, 0, 2, MapReturnType.COUNT));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
List<?> results = record.getList(binName);
int i = 0;
long val = (Long) results.get(i++);
assertEquals(7, val);
val = (Long) results.get(i++);
assertEquals(2, val);
val = (Long) results.get(i++);
assertEquals(2, val);
val = (Long) results.get(i++);
assertEquals(2, val);
val = (Long) results.get(i++);
assertEquals(1, val);
}
Aggregations