use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class TestOperateList method operateListWildcard.
@Test
public void operateListWildcard() {
Key key = new Key(args.namespace, args.set, "oplkey17");
client.delete(null, key);
List<Value> i1 = new ArrayList<Value>();
i1.add(Value.get("John"));
i1.add(Value.get(55));
List<Value> i2 = new ArrayList<Value>();
i2.add(Value.get("Jim"));
i2.add(Value.get(95));
List<Value> i3 = new ArrayList<Value>();
i3.add(Value.get("Joe"));
i3.add(Value.get(80));
List<Value> itemList = new ArrayList<Value>();
itemList.add(Value.get(i1));
itemList.add(Value.get(i2));
itemList.add(Value.get(i3));
Record record = client.operate(null, key, ListOperation.appendItems(binName, itemList));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
long size = record.getLong(binName);
assertEquals(3L, size);
itemList = new ArrayList<Value>();
itemList.add(Value.get("Jim"));
itemList.add(Value.WILDCARD);
record = client.operate(null, key, ListOperation.getByValue(binName, Value.get(itemList), ListReturnType.VALUE));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
List<?> results = record.getList(binName);
int i = 0;
List<?> items = (List<?>) results.get(i++);
String s = (String) items.get(0);
assertEquals("Jim", s);
long v = (Long) items.get(1);
assertEquals(95L, v);
}
use of com.aerospike.client.Record 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.Record in project aerospike-client-java by aerospike.
the class TestOperateList method operateNestedListMap.
@Test
public void operateNestedListMap() {
Key key = new Key(args.namespace, args.set, "oplkey19");
client.delete(null, key);
List<Value> l11 = new ArrayList<Value>();
l11.add(Value.get(7));
l11.add(Value.get(9));
l11.add(Value.get(5));
List<Value> l12 = new ArrayList<Value>();
l12.add(Value.get(13));
List<Value> l1 = new ArrayList<Value>();
l1.add(Value.get(l11));
l1.add(Value.get(l12));
List<Value> l21 = new ArrayList<Value>();
l21.add(Value.get(9));
List<Value> l22 = new ArrayList<Value>();
l22.add(Value.get(2));
l22.add(Value.get(4));
List<Value> l23 = new ArrayList<Value>();
l23.add(Value.get(6));
l23.add(Value.get(1));
l23.add(Value.get(9));
List<Value> l2 = new ArrayList<Value>();
l2.add(Value.get(l21));
l2.add(Value.get(l22));
l2.add(Value.get(l23));
Map<Value, Value> inputMap = new HashMap<Value, Value>();
inputMap.put(Value.get("key1"), Value.get(l1));
inputMap.put(Value.get("key2"), Value.get(l2));
// Create list.
client.put(null, key, new Bin(binName, inputMap));
// Append value to last list and retrieve map.
Record record = client.operate(null, key, ListOperation.append(binName, Value.get(11), CTX.mapKey(Value.get("key2")), CTX.listRank(0)), Operation.get(binName));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
List<?> results = record.getList(binName);
int i = 0;
long count = (Long) results.get(i++);
assertEquals(3, count);
Map<?, ?> map = (Map<?, ?>) results.get(i++);
assertEquals(2, map.size());
// Test affected nested list.
List<?> list = (List<?>) map.get("key2");
assertEquals(3, list.size());
list = (List<?>) list.get(1);
assertEquals(3, list.size());
assertEquals(2, (long) (Long) list.get(0));
assertEquals(4, (long) (Long) list.get(1));
assertEquals(11, (long) (Long) list.get(2));
}
use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class TestOperateList method operateListRemoveRelative.
@Test
public void operateListRemoveRelative() {
Key key = new Key(args.namespace, args.set, "oplkey14");
client.delete(null, key);
List<Value> itemList = new ArrayList<Value>();
itemList.add(Value.get(0));
itemList.add(Value.get(4));
itemList.add(Value.get(5));
itemList.add(Value.get(9));
itemList.add(Value.get(11));
itemList.add(Value.get(15));
Record record = client.operate(null, key, ListOperation.appendItems(new ListPolicy(ListOrder.ORDERED, ListWriteFlags.DEFAULT), binName, itemList), ListOperation.removeByValueRelativeRankRange(binName, Value.get(5), 0, ListReturnType.VALUE), ListOperation.removeByValueRelativeRankRange(binName, Value.get(5), 1, ListReturnType.VALUE), ListOperation.removeByValueRelativeRankRange(binName, Value.get(5), -1, ListReturnType.VALUE), ListOperation.removeByValueRelativeRankRange(binName, Value.get(3), -3, 1, ListReturnType.VALUE), ListOperation.removeByValueRelativeRankRange(binName, Value.get(3), -3, 2, ListReturnType.VALUE), ListOperation.removeByValueRelativeRankRange(binName, Value.get(3), -3, 3, ListReturnType.VALUE));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
List<?> results = record.getList(binName);
int i = 0;
long size = (Long) results.get(i++);
assertEquals(6L, size);
List<?> list = (List<?>) results.get(i++);
assertEquals(4L, list.size());
assertEquals(5L, list.get(0));
assertEquals(9L, list.get(1));
assertEquals(11L, list.get(2));
assertEquals(15L, list.get(3));
list = (List<?>) results.get(i++);
assertEquals(0L, list.size());
list = (List<?>) results.get(i++);
assertEquals(1L, list.size());
assertEquals(4L, list.get(0));
list = (List<?>) results.get(i++);
assertEquals(0L, list.size());
list = (List<?>) results.get(i++);
assertEquals(0L, list.size());
list = (List<?>) results.get(i++);
assertEquals(1L, list.size());
assertEquals(0L, list.get(0));
}
use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class TestQueryExecute method queryExecuteOperate.
@Test
public void queryExecuteOperate() {
int begin = 3;
int end = 9;
Statement stmt = new Statement();
stmt.setNamespace(args.namespace);
stmt.setSetName(args.set);
stmt.setFilter(Filter.range(binName1, begin, end));
Bin bin = new Bin("foo", "bar");
ExecuteTask task = client.execute(null, stmt, Operation.put(bin));
task.waitTillComplete(3000, 3000);
String expected = bin.value.toString();
stmt = new Statement();
stmt.setNamespace(args.namespace);
stmt.setSetName(args.set);
stmt.setFilter(Filter.range(binName1, begin, end));
RecordSet rs = client.query(null, stmt);
try {
int count = 0;
while (rs.next()) {
Record record = rs.getRecord();
String value = record.getString(bin.name);
if (value == null) {
fail("Bin " + bin.name + " not found");
}
if (!value.equals(expected)) {
fail("Data mismatch. Expected " + expected + ". Received " + value);
}
count++;
}
assertEquals(end - begin + 1, count);
} finally {
rs.close();
}
}
Aggregations