use of com.aerospike.client.exp.Expression in project aerospike-client-java by aerospike.
the class TestExpOperation method expReturnsBoolean.
@Test
public void expReturnsBoolean() {
Expression exp = Exp.build(Exp.eq(Exp.intBin(binA), Exp.val(1)));
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);
boolean val = (Boolean) results.get(1);
assertTrue(val);
val = record.getBoolean(expVar);
assertTrue(val);
}
use of com.aerospike.client.exp.Expression in project aerospike-client-java by aerospike.
the class TestExpOperation method expReturnsString.
@Test
public void expReturnsString() {
String str = "xxx";
Expression exp = Exp.build(Exp.val(str));
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);
String val = (String) results.get(1);
assertEquals(str, val);
val = record.getString(expVar);
assertEquals(str, val);
record = client.operate(null, keyA, ExpOperation.read(expVar, exp, ExpReadFlags.DEFAULT));
val = record.getString(expVar);
assertEquals(str, val);
}
use of com.aerospike.client.exp.Expression in project aerospike-client-java by aerospike.
the class TestExpOperation method expReturnsUnknown.
@Test
public void expReturnsUnknown() {
Expression exp = Exp.build(Exp.cond(Exp.eq(Exp.intBin(binC), Exp.val(5)), Exp.unknown(), Exp.binExists(binA), Exp.val(5), Exp.unknown()));
AerospikeException ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {
public void run() {
client.operate(null, keyA, ExpOperation.write(binC, exp, ExpWriteFlags.DEFAULT), Operation.get(binC));
}
});
assertEquals(ResultCode.OP_NOT_APPLICABLE, ae.getResultCode());
Record record = client.operate(null, keyA, ExpOperation.write(binC, exp, ExpWriteFlags.EVAL_NO_FAIL), Operation.get(binC));
assertRecordFound(keyA, record);
// System.out.println(record);
List<?> results = record.getList(binC);
Object val = results.get(0);
assertEquals(null, val);
val = results.get(1);
assertEquals(null, val);
}
use of com.aerospike.client.exp.Expression in project aerospike-client-java by aerospike.
the class TestExpOperation method expReturnsHLL.
@Test
public void expReturnsHLL() {
Expression exp = Exp.build(HLLExp.init(HLLPolicy.Default, Exp.val(4), Exp.nil()));
Record record = client.operate(null, keyA, HLLOperation.init(HLLPolicy.Default, binH, 4), ExpOperation.write(binC, exp, ExpWriteFlags.DEFAULT), Operation.get(binH), Operation.get(binC), ExpOperation.read(expVar, exp, ExpReadFlags.DEFAULT));
assertRecordFound(keyA, record);
// System.out.println(record);
List<?> results = record.getList(binH);
HLLValue valH = (HLLValue) results.get(1);
results = record.getList(binC);
HLLValue valC = (HLLValue) results.get(1);
HLLValue valExp = record.getHLLValue(expVar);
String resultString = "bytes not equal";
assertArrayEquals(resultString, valH.getBytes(), valC.getBytes());
assertArrayEquals(resultString, valH.getBytes(), valExp.getBytes());
record = client.operate(null, keyA, ExpOperation.read(expVar, exp, ExpReadFlags.DEFAULT));
valExp = record.getHLLValue(expVar);
assertArrayEquals(resultString, valH.getBytes(), valExp.getBytes());
}
use of com.aerospike.client.exp.Expression in project aerospike-client-java by aerospike.
the class TestExpOperation method expReturnsInt.
@Test
public void expReturnsInt() {
Expression exp = Exp.build(Exp.add(Exp.intBin(binA), Exp.val(4)));
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);
long val = (Long) results.get(1);
assertEquals(5, val);
val = record.getLong(expVar);
assertEquals(5, val);
record = client.operate(null, keyA, ExpOperation.read(expVar, exp, ExpReadFlags.DEFAULT));
val = record.getLong(expVar);
assertEquals(5, val);
}
Aggregations