Search in sources :

Example 51 with Bin

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

the class TestQueryInteger method prepare.

@BeforeClass
public static void prepare() {
    Policy policy = new Policy();
    // Do not timeout on index create.
    policy.socketTimeout = 0;
    try {
        IndexTask task = client.createIndex(policy, args.namespace, args.set, indexName, binName, IndexType.NUMERIC);
        task.waitTillComplete();
    } catch (AerospikeException ae) {
        if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
            throw ae;
        }
    }
    for (int i = 1; i <= size; i++) {
        Key key = new Key(args.namespace, args.set, keyPrefix + i);
        Bin bin = new Bin(binName, i);
        client.put(null, key, bin);
    }
}
Also used : Policy(com.aerospike.client.policy.Policy) AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) IndexTask(com.aerospike.client.task.IndexTask) Key(com.aerospike.client.Key) BeforeClass(org.junit.BeforeClass)

Example 52 with Bin

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

the class TestQueryRPS method bgQueryWithOps.

@Ignore
@Test
public void bgQueryWithOps() {
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setFilter(Filter.range(binName1, 0, n_records));
    stmt.setRecordsPerSecond(rps);
    ExecuteTask task = client.execute(null, stmt, Operation.put(new Bin(binName3, 1)));
    task.waitTillComplete();
    for (Node n : client.getNodes()) {
        checkRuntime(n, stmt);
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Bin(com.aerospike.client.Bin) Node(com.aerospike.client.cluster.Node) ExecuteTask(com.aerospike.client.task.ExecuteTask) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 53 with Bin

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

the class TestQuerySum method prepare.

@BeforeClass
public static void prepare() {
    RegisterTask rtask = client.register(null, TestQuerySum.class.getClassLoader(), "udf/sum_example.lua", "sum_example.lua", Language.LUA);
    rtask.waitTillComplete();
    Policy policy = new Policy();
    // Do not timeout on index create.
    policy.socketTimeout = 0;
    try {
        IndexTask itask = client.createIndex(policy, args.namespace, args.set, indexName, binName, IndexType.NUMERIC);
        itask.waitTillComplete();
    } catch (AerospikeException ae) {
        if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
            throw ae;
        }
    }
    for (int i = 1; i <= size; i++) {
        Key key = new Key(args.namespace, args.set, keyPrefix + i);
        Bin bin = new Bin(binName, i);
        client.put(null, key, bin);
    }
}
Also used : Policy(com.aerospike.client.policy.Policy) AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) IndexTask(com.aerospike.client.task.IndexTask) RegisterTask(com.aerospike.client.task.RegisterTask) Key(com.aerospike.client.Key) BeforeClass(org.junit.BeforeClass)

Example 54 with Bin

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

the class TestQueryAverage method prepare.

@BeforeClass
public static void prepare() {
    RegisterTask rtask = client.register(null, TestQueryAverage.class.getClassLoader(), "udf/average_example.lua", "average_example.lua", Language.LUA);
    rtask.waitTillComplete();
    Policy policy = new Policy();
    // Do not timeout on index create.
    policy.socketTimeout = 0;
    try {
        IndexTask itask = client.createIndex(policy, args.namespace, args.set, indexName, binName, IndexType.NUMERIC);
        itask.waitTillComplete();
    } catch (AerospikeException ae) {
        if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
            throw ae;
        }
    }
    for (int i = 1; i <= size; i++) {
        Key key = new Key(args.namespace, args.set, keyPrefix + i);
        Bin bin = new Bin("l1", i);
        client.put(null, key, bin, new Bin("l2", 1));
    }
}
Also used : Policy(com.aerospike.client.policy.Policy) AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) IndexTask(com.aerospike.client.task.IndexTask) RegisterTask(com.aerospike.client.task.RegisterTask) Key(com.aerospike.client.Key) BeforeClass(org.junit.BeforeClass)

Example 55 with Bin

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

the class ListMap method testMapStrings.

/**
 * Write/Read HashMap<String,String> directly instead of relying on java serializer.
 */
private void testMapStrings(AerospikeClient client, Parameters params) throws Exception {
    console.info("Read/Write HashMap<String,String>");
    Key key = new Key(params.namespace, params.set, "mapkey1");
    client.delete(params.writePolicy, key);
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("key1", "string1");
    map.put("key2", "string2");
    map.put("key3", "string3");
    Bin bin = new Bin(params.getBinName("mapbin1"), map);
    client.put(params.writePolicy, key, bin);
    Record record = client.get(params.policy, key, bin.name);
    Map<?, ?> receivedMap = (Map<?, ?>) record.getValue(bin.name);
    validateSize(3, receivedMap.size());
    validate("string1", receivedMap.get("key1"));
    validate("string2", receivedMap.get("key2"));
    validate("string3", receivedMap.get("key3"));
    console.info("Read/Write HashMap<String,String> successful");
}
Also used : HashMap(java.util.HashMap) Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) Map(java.util.Map) HashMap(java.util.HashMap) Key(com.aerospike.client.Key)

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