Search in sources :

Example 36 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class TestListExp method modifyWithContext.

@Test
public void modifyWithContext() {
    List<Value> listSubA = new ArrayList<Value>();
    listSubA.add(Value.get("e"));
    listSubA.add(Value.get("d"));
    listSubA.add(Value.get("c"));
    listSubA.add(Value.get("b"));
    listSubA.add(Value.get("a"));
    List<Value> listA = new ArrayList<Value>();
    listA.add(Value.get("a"));
    listA.add(Value.get("b"));
    listA.add(Value.get("c"));
    listA.add(Value.get("d"));
    listA.add(Value.get(listSubA));
    List<Value> listB = new ArrayList<Value>();
    listB.add(Value.get("x"));
    listB.add(Value.get("y"));
    listB.add(Value.get("z"));
    client.operate(null, keyA, ListOperation.appendItems(ListPolicy.Default, binA, listA), ListOperation.appendItems(ListPolicy.Default, binB, listB), Operation.put(new Bin(binC, "M")));
    CTX ctx = CTX.listIndex(4);
    Record record;
    List<?> result;
    policy.filterExp = Exp.build(Exp.eq(ListExp.size(// Temporarily append binB/binC to binA in expression.
    ListExp.appendItems(ListPolicy.Default, Exp.listBin(binB), ListExp.append(ListPolicy.Default, Exp.stringBin(binC), Exp.listBin(binA), ctx), ctx), ctx), Exp.val(9)));
    record = client.get(policy, keyA, binA);
    assertRecordFound(keyA, record);
    result = record.getList(binA);
    assertEquals(5, result.size());
    policy.filterExp = Exp.build(Exp.eq(ListExp.size(// Temporarily append local listB and local "M" string to binA in expression.
    ListExp.appendItems(ListPolicy.Default, Exp.val(listB), ListExp.append(ListPolicy.Default, Exp.val("M"), Exp.listBin(binA), ctx), ctx), ctx), Exp.val(9)));
    record = client.get(policy, keyA, binA);
    assertRecordFound(keyA, record);
    result = record.getList(binA);
    assertEquals(5, result.size());
}
Also used : Bin(com.aerospike.client.Bin) CTX(com.aerospike.client.cdt.CTX) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) Test(org.junit.Test)

Example 37 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class TestOperate method operate.

@Test
public void operate() {
    // Write initial record.
    Key key = new Key(args.namespace, args.set, "opkey");
    Bin bin1 = new Bin("optintbin", 7);
    Bin bin2 = new Bin("optstringbin", "string value");
    client.put(null, key, bin1, bin2);
    // Add integer, write new string and read record.
    Bin bin3 = new Bin(bin1.name, 4);
    Bin bin4 = new Bin(bin2.name, "new string");
    Record record = client.operate(null, key, Operation.add(bin3), Operation.put(bin4), Operation.get());
    assertBinEqual(key, record, bin3.name, 11);
    assertBinEqual(key, record, bin4);
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 38 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class TestOperateHll method operateGetUnion.

@Test
public void operateGetUnion() {
    int nIndexBits = 14;
    long expectedUnionCount = 0;
    ArrayList<List<Value>> vals = new ArrayList<List<Value>>();
    List<HLLValue> hlls = new ArrayList<HLLValue>();
    for (int i = 0; i < keys.length; i++) {
        ArrayList<Value> subVals = new ArrayList<Value>();
        for (int j = 0; j < nEntries / 3; j++) {
            subVals.add(new StringValue("key" + i + " " + j));
        }
        Record record = assertSuccess("init other keys", keys[i], Operation.delete(), HLLOperation.add(HLLPolicy.Default, binName, subVals, nIndexBits), Operation.get(binName));
        List<?> resultList = record.getList(binName);
        hlls.add((HLLValue) resultList.get(1));
        expectedUnionCount += subVals.size();
        vals.add(subVals);
    }
    // Keep record around win binName is removed.
    assertSuccess("other bin", key, Operation.delete(), HLLOperation.init(HLLPolicy.Default, binName + "other", nIndexBits), HLLOperation.add(HLLPolicy.Default, binName, vals.get(0), nIndexBits));
    Record record = assertSuccess("union and unionCount", key, HLLOperation.getUnion(binName, hlls), HLLOperation.getUnionCount(binName, hlls));
    List<?> resultList = record.getList(binName);
    long unionCount = (Long) resultList.get(1);
    assertHLLCount("verify union count", nIndexBits, unionCount, expectedUnionCount);
    HLLValue unionHll = (HLLValue) resultList.get(0);
    record = assertSuccess("", key, Operation.put(new Bin(binName, unionHll)), HLLOperation.getCount(binName));
    resultList = record.getList(binName);
    long unionCount2 = (Long) resultList.get(1);
    assertEquals("unions equal", unionCount, unionCount2);
}
Also used : HLLValue(com.aerospike.client.Value.HLLValue) Bin(com.aerospike.client.Bin) ArrayList(java.util.ArrayList) HLLValue(com.aerospike.client.Value.HLLValue) StringValue(com.aerospike.client.Value.StringValue) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) List(java.util.List) Record(com.aerospike.client.Record) StringValue(com.aerospike.client.Value.StringValue) Test(org.junit.Test)

Example 39 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class TestExpOperation method setUp.

@Before
public void setUp() throws Exception {
    client.delete(null, keyA);
    client.delete(null, keyB);
    client.put(null, keyA, new Bin(binA, 1), new Bin(binD, 2));
    client.put(null, keyB, new Bin(binB, 2), new Bin(binD, 2));
}
Also used : Bin(com.aerospike.client.Bin) Before(org.junit.Before)

Example 40 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class TestFilterExp method operateWrite.

@Test
public void operateWrite() {
    WritePolicy policy = new WritePolicy();
    policy.filterExp = Exp.build(Exp.eq(Exp.intBin(binA), Exp.val(1)));
    Bin bin = new Bin(binA, 3);
    Record r = client.operate(policy, keyA, Operation.put(bin), Operation.get(binA));
    assertBinEqual(keyA, r, binA, 3);
    r = client.operate(policy, keyB, Operation.put(bin), Operation.get(binA));
    assertEquals(null, r);
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) WritePolicy(com.aerospike.client.policy.WritePolicy) Test(org.junit.Test)

Aggregations

Bin (com.aerospike.client.Bin)151 Key (com.aerospike.client.Key)129 Record (com.aerospike.client.Record)70 Test (org.junit.Test)54 AerospikeException (com.aerospike.client.AerospikeException)34 ArrayList (java.util.ArrayList)31 WritePolicy (com.aerospike.client.policy.WritePolicy)27 HashMap (java.util.HashMap)22 Value (com.aerospike.client.Value)20 List (java.util.List)15 BeforeClass (org.junit.BeforeClass)14 Map (java.util.Map)13 Policy (com.aerospike.client.policy.Policy)12 IndexTask (com.aerospike.client.task.IndexTask)11 WriteListener (com.aerospike.client.listener.WriteListener)5 RegisterTask (com.aerospike.client.task.RegisterTask)5 AbstractMap (java.util.AbstractMap)4 TreeMap (java.util.TreeMap)4 CTX (com.aerospike.client.cdt.CTX)3 BitPolicy (com.aerospike.client.operation.BitPolicy)3