Search in sources :

Example 1 with HLLPolicy

use of com.aerospike.client.operation.HLLPolicy in project aerospike-client-java by aerospike.

the class TestOperateHll method operateAddFlags.

@Test
public void operateAddFlags() {
    int nIndexBits = 4;
    // Keep record around win binName is removed.
    assertSuccess("other bin", key, Operation.delete(), HLLOperation.init(HLLPolicy.Default, binName + "other", nIndexBits));
    // create_only
    HLLPolicy c = new HLLPolicy(HLLWriteFlags.CREATE_ONLY);
    assertSuccess("create_only", key, HLLOperation.add(c, binName, entries, nIndexBits));
    assertThrows("create_only - error", key, AerospikeException.class, ResultCode.BIN_EXISTS_ERROR, HLLOperation.add(c, binName, entries, nIndexBits));
    // update_only
    HLLPolicy u = new HLLPolicy(HLLWriteFlags.UPDATE_ONLY);
    assertThrows("update_only - error", key, AerospikeException.class, ResultCode.PARAMETER_ERROR, HLLOperation.add(u, binName, entries, nIndexBits));
    // create_only no_fail
    HLLPolicy cn = new HLLPolicy(HLLWriteFlags.CREATE_ONLY | HLLWriteFlags.NO_FAIL);
    assertSuccess("create_only nofail", key, HLLOperation.add(cn, binName, entries, nIndexBits));
    assertSuccess("create_only nofail - no error", key, HLLOperation.add(cn, binName, entries, nIndexBits));
    // fold
    assertSuccess("init", key, HLLOperation.init(HLLPolicy.Default, binName, nIndexBits));
    HLLPolicy f = new HLLPolicy(HLLWriteFlags.ALLOW_FOLD);
    assertThrows("fold", key, AerospikeException.class, ResultCode.PARAMETER_ERROR, HLLOperation.add(f, binName, entries, nIndexBits));
}
Also used : HLLPolicy(com.aerospike.client.operation.HLLPolicy) Test(org.junit.Test)

Example 2 with HLLPolicy

use of com.aerospike.client.operation.HLLPolicy in project aerospike-client-java by aerospike.

the class TestOperateHll method operateHLLFlags.

@Test
public void operateHLLFlags() {
    int nIndexBits = 4;
    // Keep record around win binName is removed.
    assertSuccess("other bin", key, Operation.delete(), HLLOperation.init(HLLPolicy.Default, binName + "other", nIndexBits));
    // create_only
    HLLPolicy c = new HLLPolicy(HLLWriteFlags.CREATE_ONLY);
    assertSuccess("create_only", key, HLLOperation.init(c, binName, nIndexBits));
    assertThrows("create_only - error", key, AerospikeException.class, ResultCode.BIN_EXISTS_ERROR, HLLOperation.init(c, binName, nIndexBits));
    // update_only
    HLLPolicy u = new HLLPolicy(HLLWriteFlags.UPDATE_ONLY);
    assertSuccess("update_only", key, HLLOperation.init(u, binName, nIndexBits));
    assertSuccess("remove bin", key, Operation.put(Bin.asNull(binName)));
    assertThrows("update_only - error", key, AerospikeException.class, ResultCode.BIN_NOT_FOUND, HLLOperation.init(u, binName, nIndexBits));
    // create_only no_fail
    HLLPolicy cn = new HLLPolicy(HLLWriteFlags.CREATE_ONLY | HLLWriteFlags.NO_FAIL);
    assertSuccess("create_only nofail", key, HLLOperation.init(cn, binName, nIndexBits));
    assertSuccess("create_only nofail - no error", key, HLLOperation.init(cn, binName, nIndexBits));
    // update_only no_fail
    HLLPolicy un = new HLLPolicy(HLLWriteFlags.UPDATE_ONLY | HLLWriteFlags.NO_FAIL);
    assertSuccess("update_only nofail", key, HLLOperation.init(un, binName, nIndexBits));
    assertSuccess("remove bin", key, Operation.put(Bin.asNull(binName)));
    assertSuccess("update_only nofail - no error", key, HLLOperation.init(un, binName, nIndexBits));
    // fold
    assertSuccess("create_only", key, HLLOperation.init(c, binName, nIndexBits));
    HLLPolicy f = new HLLPolicy(HLLWriteFlags.ALLOW_FOLD);
    assertThrows("fold", key, AerospikeException.class, ResultCode.PARAMETER_ERROR, HLLOperation.init(f, binName, nIndexBits));
}
Also used : HLLPolicy(com.aerospike.client.operation.HLLPolicy) Test(org.junit.Test)

Example 3 with HLLPolicy

use of com.aerospike.client.operation.HLLPolicy in project aerospike-client-java by aerospike.

the class TestOperateHll method assertAddInit.

public void assertAddInit(int nIndexBits, int nMinhashBits) {
    client.delete(null, key);
    String msg = "Fail - nIdexBits " + nIndexBits + " nMinhashBits " + nMinhashBits;
    HLLPolicy p = HLLPolicy.Default;
    Operation[] ops = new Operation[] { HLLOperation.add(p, binName, entries, nIndexBits, nMinhashBits), HLLOperation.getCount(binName), HLLOperation.refreshCount(binName), HLLOperation.describe(binName), HLLOperation.add(p, binName, entries) };
    if (!checkBits(nIndexBits, nMinhashBits)) {
        assertThrows(msg, key, AerospikeException.class, ResultCode.PARAMETER_ERROR, ops);
        return;
    }
    Record record = assertSuccess(msg, key, ops);
    List<?> resultList = record.getList(binName);
    long count = (Long) resultList.get(1);
    long count1 = (Long) resultList.get(2);
    List<?> description = (List<?>) resultList.get(3);
    long nAdded = (Long) resultList.get(4);
    assertDescription(msg, description, nIndexBits, nMinhashBits);
    assertHLLCount(msg, nIndexBits, count, entries.size());
    assertEquals(count, count1);
    assertEquals(nAdded, 0);
}
Also used : Record(com.aerospike.client.Record) ArrayList(java.util.ArrayList) List(java.util.List) Operation(com.aerospike.client.Operation) HLLOperation(com.aerospike.client.operation.HLLOperation) HLLPolicy(com.aerospike.client.operation.HLLPolicy)

Example 4 with HLLPolicy

use of com.aerospike.client.operation.HLLPolicy in project aerospike-client-java by aerospike.

the class TestOperateHll method assertInit.

public void assertInit(int nIndexBits, int nMinhashBits, boolean shouldPass) {
    String msg = "Fail - nIndexBits " + nIndexBits + " nMinhashBits " + nMinhashBits;
    HLLPolicy p = HLLPolicy.Default;
    Operation[] ops = new Operation[] { HLLOperation.init(p, binName, nIndexBits, nMinhashBits), HLLOperation.getCount(binName), HLLOperation.refreshCount(binName), HLLOperation.describe(binName) };
    if (!shouldPass) {
        assertThrows(msg, key, AerospikeException.class, ResultCode.PARAMETER_ERROR, ops);
        return;
    }
    Record record = assertSuccess(msg, key, ops);
    List<?> resultList = record.getList(binName);
    long count = (Long) resultList.get(1);
    long count1 = (Long) resultList.get(2);
    List<?> description = (List<?>) resultList.get(3);
    assertDescription(msg, description, nIndexBits, nMinhashBits);
    assertEquals(0, count);
    assertEquals(0, count1);
}
Also used : Record(com.aerospike.client.Record) ArrayList(java.util.ArrayList) List(java.util.List) Operation(com.aerospike.client.Operation) HLLOperation(com.aerospike.client.operation.HLLOperation) HLLPolicy(com.aerospike.client.operation.HLLPolicy)

Example 5 with HLLPolicy

use of com.aerospike.client.operation.HLLPolicy in project aerospike-client-java by aerospike.

the class TestOperateHll method assertFold.

public void assertFold(List<Value> vals0, List<Value> vals1, int nIndexBits) {
    String msg = "Fail - nIndexBits " + nIndexBits;
    HLLPolicy p = HLLPolicy.Default;
    for (int ix = minNIndexBits; ix <= nIndexBits; ix++) {
        if (!checkBits(nIndexBits, 0) || !checkBits(ix, 0)) {
            assertTrue("Expected valid inputs: " + msg, false);
        }
        Record recorda = assertSuccess(msg, key, Operation.delete(), HLLOperation.add(p, binName, vals0, nIndexBits), HLLOperation.getCount(binName), HLLOperation.refreshCount(binName), HLLOperation.describe(binName));
        List<?> resultAList = recorda.getList(binName);
        long counta = (Long) resultAList.get(1);
        long counta1 = (Long) resultAList.get(2);
        List<?> descriptiona = (List<?>) resultAList.get(3);
        assertDescription(msg, descriptiona, nIndexBits, 0);
        assertHLLCount(msg, nIndexBits, counta, vals0.size());
        assertEquals(counta, counta1);
        Record recordb = assertSuccess(msg, key, HLLOperation.fold(binName, ix), HLLOperation.getCount(binName), HLLOperation.add(p, binName, vals0), HLLOperation.add(p, binName, vals1), HLLOperation.getCount(binName), HLLOperation.describe(binName));
        List<?> resultBList = recordb.getList(binName);
        long countb = (Long) resultBList.get(1);
        long nAdded0 = (Long) resultBList.get(2);
        long countb1 = (Long) resultBList.get(4);
        List<?> descriptionb = (List<?>) resultBList.get(5);
        assertEquals(0, nAdded0);
        assertDescription(msg, descriptionb, ix, 0);
        assertHLLCount(msg, ix, countb, vals0.size());
        assertHLLCount(msg, ix, countb1, vals0.size() + vals1.size());
    }
}
Also used : Record(com.aerospike.client.Record) ArrayList(java.util.ArrayList) List(java.util.List) HLLPolicy(com.aerospike.client.operation.HLLPolicy)

Aggregations

HLLPolicy (com.aerospike.client.operation.HLLPolicy)8 Record (com.aerospike.client.Record)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 Operation (com.aerospike.client.Operation)3 HLLOperation (com.aerospike.client.operation.HLLOperation)3 List (java.util.List)3 HLLValue (com.aerospike.client.Value.HLLValue)2 Value (com.aerospike.client.Value)1 StringValue (com.aerospike.client.Value.StringValue)1