use of com.aerospike.client.Operation in project aerospike-client-java by aerospike.
the class TestAsyncBatch method asyncBatchReadComplex.
@Test
public void asyncBatchReadComplex() throws Exception {
// Batch gets into one call.
// Batch allows multiple namespaces in one call, but example test environment may only have one namespace.
// bin * 8
Expression exp = Exp.build(Exp.mul(Exp.intBin(BinName), Exp.val(8)));
Operation[] ops = Operation.array(ExpOperation.read(BinName, exp, ExpReadFlags.DEFAULT));
String[] bins = new String[] { BinName };
List<BatchRead> records = new ArrayList<BatchRead>();
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 1), bins));
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 2), true));
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 3), true));
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 4), false));
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 5), true));
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 6), ops));
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 7), bins));
// This record should be found, but the requested bin will not be found.
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 8), new String[] { "binnotfound" }));
// This record should not be found.
records.add(new BatchRead(new Key(args.namespace, args.set, "keynotfound"), bins));
// Execute batch.
client.get(eventLoop, new BatchListListener() {
public void onSuccess(List<BatchRead> records) {
// Show results.
int found = 0;
int count = 0;
for (BatchRead record : records) {
Record rec = record.record;
count++;
if (rec != null) {
found++;
if (count != 4 && count != 6 && count <= 7) {
Object value = rec.getValue(BinName);
if (!assertEquals(ValuePrefix + count, value)) {
notifyComplete();
return;
}
} else if (count == 6) {
int value = rec.getInt(BinName);
if (!assertEquals(48, value)) {
notifyComplete();
return;
}
} else {
Object value = rec.getValue(BinName);
if (!assertNull(value)) {
notifyComplete();
return;
}
}
}
}
assertEquals(8, found);
notifyComplete();
}
public void onFailure(AerospikeException e) {
setError(e);
notifyComplete();
}
}, null, records);
waitTillComplete();
}
Aggregations