use of com.aerospike.client.Value in project aerospike-client-java by aerospike.
the class TestOperateList method operateListSort.
@Test
public void operateListSort() {
Key key = new Key(args.namespace, args.set, "oplkey10");
client.delete(null, key);
List<Value> itemList = new ArrayList<Value>();
itemList.add(Value.get(-44));
itemList.add(Value.get(33));
itemList.add(Value.get(-1));
itemList.add(Value.get(33));
itemList.add(Value.get(-2));
Record record = client.operate(null, key, ListOperation.appendItems(ListPolicy.Default, binName, itemList), ListOperation.sort(binName, ListSortFlags.DROP_DUPLICATES), ListOperation.size(binName));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
List<?> results = record.getList(binName);
int i = 0;
long size = (Long) results.get(i++);
assertEquals(5L, size);
long val = (Long) results.get(i++);
assertEquals(4L, val);
}
use of com.aerospike.client.Value in project aerospike-client-java by aerospike.
the class TestOperateList method operateList7.
@Test
public void operateList7() {
// Test null values.
Key key = new Key(args.namespace, args.set, "oplkey7");
client.delete(null, key);
List<Value> itemList = new ArrayList<Value>();
itemList.add(Value.get("s11"));
itemList.add(Value.getAsNull());
itemList.add(Value.get("s3333333"));
Record record = client.operate(null, key, ListOperation.appendItems(binName, itemList), ListOperation.get(binName, 0), ListOperation.get(binName, 1), ListOperation.get(binName, 2));
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);
String str = (String) results.get(i++);
assertEquals("s11", str);
str = (String) results.get(i++);
assertNull(str);
str = (String) results.get(i++);
assertEquals("s3333333", str);
}
use of com.aerospike.client.Value in project aerospike-client-java by aerospike.
the class TestOperateList method operateListInverted.
@Test
public void operateListInverted() {
Key key = new Key(args.namespace, args.set, "oplkey12");
client.delete(null, key);
List<Value> itemList = new ArrayList<Value>();
itemList.add(Value.get(4));
itemList.add(Value.get(3));
itemList.add(Value.get(1));
itemList.add(Value.get(5));
itemList.add(Value.get(2));
List<Value> valueList = new ArrayList<Value>();
valueList.add(Value.get(4));
valueList.add(Value.get(2));
Record record = client.operate(null, key, ListOperation.appendItems(ListPolicy.Default, binName, itemList), ListOperation.getByValue(binName, Value.get(3), ListReturnType.INDEX | ListReturnType.INVERTED), ListOperation.getByValueRange(binName, Value.get(-1), Value.get(3), ListReturnType.COUNT | ListReturnType.INVERTED), ListOperation.getByValueList(binName, valueList, ListReturnType.RANK | ListReturnType.INVERTED), ListOperation.getByIndexRange(binName, -2, 2, ListReturnType.VALUE | ListReturnType.INVERTED), ListOperation.getByRankRange(binName, 2, 3, ListReturnType.VALUE | ListReturnType.INVERTED));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
List<?> results = record.getList(binName);
int i = 0;
long size = (Long) results.get(i++);
assertEquals(5L, size);
List<?> list = (List<?>) results.get(i++);
assertEquals(4L, list.size());
assertEquals(0L, list.get(0));
assertEquals(2L, list.get(1));
assertEquals(3L, list.get(2));
assertEquals(4L, list.get(3));
long val = (Long) results.get(i++);
assertEquals(3L, val);
list = (List<?>) results.get(i++);
assertEquals(3L, list.size());
assertEquals(0L, list.get(0));
assertEquals(2L, list.get(1));
assertEquals(4L, list.get(2));
list = (List<?>) results.get(i++);
assertEquals(3L, list.size());
assertEquals(4L, list.get(0));
assertEquals(3L, list.get(1));
assertEquals(1L, list.get(2));
list = (List<?>) results.get(i++);
assertEquals(2L, list.size());
assertEquals(1L, list.get(0));
assertEquals(2L, list.get(1));
}
use of com.aerospike.client.Value in project aerospike-client-java by aerospike.
the class TestOperateMap method operateMapRank.
@Test
public void operateMapRank() {
// Test rank.
if (!args.validateMap()) {
return;
}
Key key = new Key(args.namespace, args.set, "opmkey6");
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);
// System.out.println("Record: " + record);
// Increment some user scores.
record = client.operate(null, key, MapOperation.increment(MapPolicy.Default, binName, Value.get("John"), Value.get(5)), MapOperation.decrement(MapPolicy.Default, binName, Value.get("Jim"), Value.get(4)));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
// Get scores.
record = client.operate(null, key, MapOperation.getByRankRange(binName, -2, 2, MapReturnType.KEY), MapOperation.getByRankRange(binName, 0, 2, MapReturnType.KEY_VALUE), MapOperation.getByRank(binName, 0, MapReturnType.VALUE), MapOperation.getByRank(binName, 2, MapReturnType.KEY), MapOperation.getByValueRange(binName, Value.get(90), Value.get(95), MapReturnType.RANK), MapOperation.getByValueRange(binName, Value.get(90), Value.get(95), MapReturnType.COUNT), MapOperation.getByValueRange(binName, Value.get(90), Value.get(95), MapReturnType.KEY_VALUE), MapOperation.getByValueRange(binName, Value.get(81), Value.get(82), MapReturnType.KEY), MapOperation.getByValue(binName, Value.get(77), MapReturnType.KEY), MapOperation.getByValue(binName, Value.get(81), MapReturnType.RANK), MapOperation.getByKey(binName, Value.get("Charlie"), MapReturnType.RANK), MapOperation.getByKey(binName, Value.get("Charlie"), MapReturnType.REVERSE_RANK));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
List<?> results = record.getList(binName);
int i = 0;
List<?> list = (List<?>) results.get(i++);
String str;
long val;
str = (String) list.get(0);
assertEquals("Harry", str);
str = (String) list.get(1);
assertEquals("Jim", str);
list = (List<?>) results.get(i++);
Entry<?, ?> entry = (Entry<?, ?>) list.get(0);
assertEquals("Charlie", entry.getKey());
assertEquals(55L, entry.getValue());
entry = (Entry<?, ?>) list.get(1);
assertEquals("John", entry.getKey());
assertEquals(81L, entry.getValue());
val = (Long) results.get(i++);
assertEquals(55, val);
str = (String) results.get(i++);
assertEquals("Harry", str);
list = (List<?>) results.get(i++);
val = (Long) list.get(0);
assertEquals(3, val);
val = (Long) results.get(i++);
assertEquals(1, val);
list = (List<?>) results.get(i++);
entry = (Entry<?, ?>) list.get(0);
assertEquals("Jim", entry.getKey());
assertEquals(94L, entry.getValue());
list = (List<?>) results.get(i++);
str = (String) list.get(0);
assertEquals("John", str);
list = (List<?>) results.get(i++);
assertEquals(0, list.size());
list = (List<?>) results.get(i++);
val = (Long) list.get(0);
assertEquals(1, val);
val = (Long) results.get(i++);
assertEquals(0, val);
val = (Long) results.get(i++);
assertEquals(3, val);
}
use of com.aerospike.client.Value in project aerospike-client-java by aerospike.
the class TestOperateMap method operateMapPutItems.
@Test
public void operateMapPutItems() {
if (!args.validateMap()) {
return;
}
Key key = new Key(args.namespace, args.set, "opmkey2");
client.delete(null, key);
Map<Value, Value> addMap = new HashMap<Value, Value>();
addMap.put(Value.get(12), Value.get("myval"));
addMap.put(Value.get(-8734), Value.get("str2"));
addMap.put(Value.get(1), Value.get("my default"));
Map<Value, Value> putMap = new HashMap<Value, Value>();
putMap.put(Value.get(12), Value.get("myval12222"));
putMap.put(Value.get(13), Value.get("str13"));
Map<Value, Value> updateMap = new HashMap<Value, Value>();
updateMap.put(Value.get(13), Value.get("myval2"));
Map<Value, Value> replaceMap = new HashMap<Value, Value>();
replaceMap.put(Value.get(12), Value.get(23));
replaceMap.put(Value.get(-8734), Value.get("changed"));
MapPolicy putMode = MapPolicy.Default;
MapPolicy addMode = new MapPolicy(MapOrder.KEY_ORDERED, MapWriteMode.CREATE_ONLY);
MapPolicy updateMode = new MapPolicy(MapOrder.KEY_ORDERED, MapWriteMode.UPDATE_ONLY);
Record record = client.operate(null, key, MapOperation.putItems(addMode, binName, addMap), MapOperation.putItems(putMode, binName, putMap), MapOperation.putItems(updateMode, binName, updateMap), MapOperation.putItems(updateMode, binName, replaceMap), MapOperation.getByKey(binName, Value.get(1), MapReturnType.VALUE), MapOperation.getByKey(binName, Value.get(-8734), MapReturnType.VALUE), MapOperation.getByKeyRange(binName, Value.get(12), Value.get(15), MapReturnType.KEY_VALUE));
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);
size = (Long) results.get(i++);
assertEquals(4, size);
size = (Long) results.get(i++);
assertEquals(4, size);
size = (Long) results.get(i++);
assertEquals(4, size);
String str = (String) results.get(i++);
assertEquals("my default", str);
str = (String) results.get(i++);
assertEquals("changed", str);
List<?> list = (List<?>) results.get(i++);
assertEquals(2, list.size());
}
Aggregations