Search in sources :

Example 6 with Expression

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);
}
Also used : Expression(com.aerospike.client.exp.Expression) Record(com.aerospike.client.Record) Test(org.junit.Test)

Example 7 with Expression

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);
}
Also used : Expression(com.aerospike.client.exp.Expression) Record(com.aerospike.client.Record) Test(org.junit.Test)

Example 8 with Expression

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);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Expression(com.aerospike.client.exp.Expression) Record(com.aerospike.client.Record) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 9 with Expression

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());
}
Also used : HLLValue(com.aerospike.client.Value.HLLValue) Expression(com.aerospike.client.exp.Expression) Record(com.aerospike.client.Record) Test(org.junit.Test)

Example 10 with Expression

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);
}
Also used : Expression(com.aerospike.client.exp.Expression) Record(com.aerospike.client.Record) Test(org.junit.Test)

Aggregations

Expression (com.aerospike.client.exp.Expression)19 Record (com.aerospike.client.Record)18 Test (org.junit.Test)17 AerospikeException (com.aerospike.client.AerospikeException)6 ThrowingRunnable (org.junit.function.ThrowingRunnable)5 Key (com.aerospike.client.Key)4 ArrayList (java.util.ArrayList)4 BatchRead (com.aerospike.client.BatchRead)3 Operation (com.aerospike.client.Operation)3 ListOperation (com.aerospike.client.cdt.ListOperation)3 ExpOperation (com.aerospike.client.exp.ExpOperation)3 Value (com.aerospike.client.Value)1 HLLValue (com.aerospike.client.Value.HLLValue)1 BatchListListener (com.aerospike.client.listener.BatchListListener)1 RecordSet (com.aerospike.client.query.RecordSet)1 Statement (com.aerospike.client.query.Statement)1 ExecuteTask (com.aerospike.client.task.ExecuteTask)1 List (java.util.List)1