use of com.aerospike.client.Key in project aerospike-client-java by aerospike.
the class TestOperateList method operateList4.
@Test
public void operateList4() {
// Test all value types.
Key key = new Key(args.namespace, args.set, "oplkey4");
client.delete(null, key);
List<Value> inputList = new ArrayList<Value>();
inputList.add(Value.get(12));
inputList.add(Value.get(-8734.81));
inputList.add(Value.get("my string"));
Map<Integer, String> inputMap = new HashMap<Integer, String>();
inputMap.put(9, "data 9");
inputMap.put(-2, "data -2");
byte[] bytes = "string bytes".getBytes();
List<Value> itemList = new ArrayList<Value>();
itemList.add(Value.get(true));
itemList.add(Value.get(55));
itemList.add(Value.get("string value"));
itemList.add(Value.get(inputList));
itemList.add(Value.get(bytes));
itemList.add(Value.get(99.99));
itemList.add(Value.get(inputMap));
Record record = client.operate(null, key, ListOperation.appendItems(binName, itemList), ListOperation.getRange(binName, 0, 100), ListOperation.set(binName, 1, Value.get("88")), ListOperation.get(binName, 1), ListOperation.popRange(binName, -2, 1), ListOperation.popRange(binName, -1), ListOperation.remove(binName, 3), ListOperation.removeRange(binName, 0, 1), ListOperation.removeRange(binName, 2), ListOperation.size(binName));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
List<?> list = record.getList(binName);
long size = (Long) list.get(0);
assertEquals(7, size);
List<?> rangeList = (List<?>) list.get(1);
assertTrue((boolean) (Boolean) rangeList.get(0));
assertEquals(55, (long) (Long) rangeList.get(1));
assertEquals("string value", (String) rangeList.get(2));
List<?> subList = (List<?>) rangeList.get(3);
assertEquals(3, subList.size());
assertEquals(12, (long) (Long) subList.get(0));
assertEquals(-8734.81, (double) (Double) subList.get(1), 0.00001);
assertEquals("my string", (String) subList.get(2));
byte[] bt = (byte[]) rangeList.get(4);
assertArrayEquals("bytes not equal", bytes, bt);
assertEquals(99.99, (double) (Double) rangeList.get(5), 0.00001);
Map<?, ?> subMap = (Map<?, ?>) rangeList.get(6);
assertEquals(2, subMap.size());
assertEquals("data 9", (String) subMap.get(9L));
assertEquals("data -2", (String) subMap.get(-2L));
// Set does not return a result.
assertEquals("88", (String) list.get(2));
subList = (List<?>) list.get(3);
assertEquals(1, subList.size());
assertEquals(99.99, (double) (Double) subList.get(0), 0.00001);
subList = (List<?>) list.get(4);
assertEquals(1, subList.size());
assertTrue(subList.get(0) instanceof Map);
assertEquals(1, (long) (Long) list.get(5));
assertEquals(1, (long) (Long) list.get(6));
assertEquals(1, (long) (Long) list.get(7));
size = (Long) list.get(8);
assertEquals(2, size);
}
use of com.aerospike.client.Key in project aerospike-client-java by aerospike.
the class TestOperateList method operateList5.
@Test
public void operateList5() {
// Test trim.
Key key = new Key(args.namespace, args.set, "oplkey5");
client.delete(null, key);
List<Value> itemList = new ArrayList<Value>();
itemList.add(Value.get("s11"));
itemList.add(Value.get("s22222"));
itemList.add(Value.get("s3333333"));
itemList.add(Value.get("s4444444444"));
itemList.add(Value.get("s5555555555555555"));
Record record = client.operate(null, key, ListOperation.insertItems(binName, 0, itemList), ListOperation.trim(binName, -5, 5), ListOperation.trim(binName, 1, -5), ListOperation.trim(binName, 1, 2));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
List<?> list = record.getList(binName);
long size = (Long) list.get(0);
assertEquals(5, size);
size = (Long) list.get(1);
assertEquals(0, size);
size = (Long) list.get(2);
assertEquals(1, size);
size = (Long) list.get(3);
assertEquals(2, size);
}
use of com.aerospike.client.Key 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.Key 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.Key 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));
}
Aggregations