use of com.aerospike.client.Value in project aerospike-client-java by aerospike.
the class TestAsyncOperate method asyncOperateMap.
@Test
public void asyncOperateMap() {
final Key key = new Key(args.namespace, args.set, "aopmkey1");
client.delete(eventLoop, new DeleteListener() {
public void onSuccess(Key key, boolean existed) {
Map<Value, Value> map = new HashMap<Value, Value>();
map.put(Value.get("a"), Value.get(1));
map.put(Value.get("b"), Value.get(2));
map.put(Value.get("c"), Value.get(3));
client.operate(eventLoop, new MapHandler(), null, key, MapOperation.putItems(MapPolicy.Default, binName, map), MapOperation.getByRankRange(binName, -1, 1, MapReturnType.KEY_VALUE));
}
public void onFailure(AerospikeException e) {
setError(e);
notifyComplete();
}
}, null, key);
waitTillComplete();
}
use of com.aerospike.client.Value in project aerospike-client-java by aerospike.
the class TestSerialize method serializeComplex.
@Test
public void serializeComplex() {
Key key = new Key(args.namespace, args.set, "serialcomplexkey");
// Delete record if it already exists.
client.delete(null, key);
ArrayList<Object> inner = new ArrayList<Object>();
inner.add("string2");
inner.add(8);
HashMap<Object, Object> innerMap = new HashMap<Object, Object>();
innerMap.put("a", 1);
innerMap.put(2, "b");
innerMap.put("list", inner);
ArrayList<Object> list = new ArrayList<Object>();
list.add("string1");
list.add(4);
list.add(inner);
list.add(innerMap);
Bin bin = new Bin(args.getBinName("complexbin"), new Value.BlobValue(list));
client.put(null, key, bin);
Record record = client.get(null, key, bin.name);
assertRecordFound(key, record);
Object received = null;
try {
received = (List<?>) record.getValue(bin.name);
} catch (Exception e) {
fail("Failed to parse returned value: namespace=" + key.namespace + " set=" + key.setName + " key=" + key.userKey + " bin=" + bin.name);
}
if (received == null || !received.equals(list)) {
fail("Data mismatch" + Environment.Newline + "Expected " + list + Environment.Newline + "Received " + received);
}
}
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);
}
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 operateList6.
@Test
public void operateList6() {
// Test clear.
Key key = new Key(args.namespace, args.set, "oplkey6");
client.delete(null, key);
WritePolicy policy = new WritePolicy();
policy.respondAllOps = true;
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(policy, key, Operation.put(new Bin("otherbin", 11)), Operation.get("otherbin"), ListOperation.appendItems(binName, itemList), ListOperation.clear(binName), ListOperation.size(binName));
assertRecordFound(key, record);
//System.out.println("Record: " + record);
List<?> list = record.getList("otherbin");
assertEquals(2, list.size());
assertNull(list.get(0));
assertEquals(11, (long) (Long) list.get(1));
list = record.getList(binName);
long size = (Long) list.get(0);
assertEquals(5, size);
// clear() does not return value by default, but we set respondAllOps, so it returns null.
assertNull(list.get(1));
size = (Long) list.get(2);
assertEquals(0, size);
}
Aggregations