use of com.aerospike.client.exp.Expression in project aerospike-client-java by aerospike.
the class TestExpOperation method expReadOnWriteEvalError.
@Test
public void expReadOnWriteEvalError() {
Expression wexp = Exp.build(Exp.intBin(binD));
Expression rexp = Exp.build(Exp.intBin(binA));
Record record = client.operate(null, keyA, ExpOperation.write(binD, wexp, ExpWriteFlags.DEFAULT), ExpOperation.read(expVar, rexp, ExpReadFlags.DEFAULT));
assertRecordFound(keyA, record);
// System.out.println(record);
AerospikeException ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {
public void run() {
client.operate(null, keyB, ExpOperation.write(binD, wexp, ExpWriteFlags.DEFAULT), ExpOperation.read(expVar, rexp, ExpReadFlags.DEFAULT));
}
});
assertEquals(ResultCode.OP_NOT_APPLICABLE, ae.getResultCode());
// Add NO_FAIL.
record = client.operate(null, keyB, ExpOperation.read(expVar, rexp, ExpReadFlags.EVAL_NO_FAIL));
assertRecordFound(keyB, record);
// System.out.println(record);
}
use of com.aerospike.client.exp.Expression 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();
}
use of com.aerospike.client.exp.Expression in project aerospike-client-java by aerospike.
the class TestExpOperation method expReturnsBlob.
@Test
public void expReturnsBlob() {
byte[] bytes = new byte[] { 0x78, 0x78, 0x78 };
Expression exp = Exp.build(Exp.val(bytes));
Record record = client.operate(null, keyA, ExpOperation.write(binC, exp, ExpWriteFlags.DEFAULT), Operation.get(binC), ExpOperation.read(expVar, exp, ExpReadFlags.DEFAULT));
assertRecordFound(keyA, record);
// System.out.println(record);
List<?> results = record.getList(binC);
byte[] val = (byte[]) results.get(1);
String resultString = "bytes not equal";
assertArrayEquals(resultString, bytes, val);
val = (byte[]) record.getValue(expVar);
assertArrayEquals(resultString, bytes, val);
record = client.operate(null, keyA, ExpOperation.read(expVar, exp, ExpReadFlags.DEFAULT));
val = (byte[]) record.getValue(expVar);
assertArrayEquals(resultString, bytes, val);
}
use of com.aerospike.client.exp.Expression in project aerospike-client-java by aerospike.
the class TestExpOperation method expWritePolicyError.
@Test
public void expWritePolicyError() {
Expression wexp = Exp.build(Exp.add(Exp.intBin(binA), Exp.val(4)));
AerospikeException ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {
public void run() {
client.operate(null, keyA, ExpOperation.write(binC, wexp, ExpWriteFlags.UPDATE_ONLY));
}
});
assertEquals(ResultCode.BIN_NOT_FOUND, ae.getResultCode());
Record record = client.operate(null, keyA, ExpOperation.write(binC, wexp, ExpWriteFlags.UPDATE_ONLY | ExpWriteFlags.POLICY_NO_FAIL));
assertRecordFound(keyA, record);
// System.out.println(record);
record = client.operate(null, keyA, ExpOperation.write(binC, wexp, ExpWriteFlags.CREATE_ONLY));
assertRecordFound(keyA, record);
// System.out.println(record);
ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {
public void run() {
client.operate(null, keyA, ExpOperation.write(binC, wexp, ExpWriteFlags.CREATE_ONLY));
}
});
assertEquals(ResultCode.BIN_EXISTS_ERROR, ae.getResultCode());
record = client.operate(null, keyA, ExpOperation.write(binC, wexp, ExpWriteFlags.CREATE_ONLY | ExpWriteFlags.POLICY_NO_FAIL));
assertRecordFound(keyA, record);
Expression dexp = Exp.build(Exp.nil());
ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {
public void run() {
client.operate(null, keyA, ExpOperation.write(binC, dexp, ExpWriteFlags.DEFAULT));
}
});
assertEquals(ResultCode.OP_NOT_APPLICABLE, ae.getResultCode());
record = client.operate(null, keyA, ExpOperation.write(binC, dexp, ExpWriteFlags.POLICY_NO_FAIL));
assertRecordFound(keyA, record);
record = client.operate(null, keyA, ExpOperation.write(binC, dexp, ExpWriteFlags.ALLOW_DELETE));
assertRecordFound(keyA, record);
record = client.operate(null, keyA, ExpOperation.write(binC, wexp, ExpWriteFlags.CREATE_ONLY));
assertRecordFound(keyA, record);
}
use of com.aerospike.client.exp.Expression in project aerospike-client-java by aerospike.
the class TestExpOperation method expReturnsNil.
@Test
public void expReturnsNil() {
Expression exp = Exp.build(Exp.nil());
Record record = client.operate(null, keyA, ExpOperation.read(expVar, exp, ExpReadFlags.DEFAULT), Operation.get(binC));
assertRecordFound(keyA, record);
// System.out.println(record);
Object val = record.getValue(expVar);
assertEquals(null, val);
}
Aggregations