Search in sources :

Example 16 with IndexTask

use of com.aerospike.client.task.IndexTask in project aerospike-client-java by aerospike.

the class TestQueryKey method prepare.

@BeforeClass
public static void prepare() {
    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;
        }
    }
    WritePolicy writePolicy = new WritePolicy();
    writePolicy.sendKey = true;
    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(writePolicy, key, bin);
    }
}
Also used : Policy(com.aerospike.client.policy.Policy) WritePolicy(com.aerospike.client.policy.WritePolicy) AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) IndexTask(com.aerospike.client.task.IndexTask) Key(com.aerospike.client.Key) WritePolicy(com.aerospike.client.policy.WritePolicy) BeforeClass(org.junit.BeforeClass)

Example 17 with IndexTask

use of com.aerospike.client.task.IndexTask in project aerospike-client-java by aerospike.

the class TestQueryString 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.STRING);
        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, valuePrefix + 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 18 with IndexTask

use of com.aerospike.client.task.IndexTask in project aerospike-client-java by aerospike.

the class TestIndex method createDrop.

@Test
public void createDrop() {
    Policy policy = new Policy();
    policy.setTimeout(0);
    IndexTask task;
    // Drop index if it already exists.
    try {
        task = client.dropIndex(policy, args.namespace, args.set, indexName);
        task.waitTillComplete();
    } catch (AerospikeException ae) {
        if (ae.getResultCode() != ResultCode.INDEX_NOTFOUND) {
            throw ae;
        }
    }
    task = client.createIndex(policy, args.namespace, args.set, indexName, binName, IndexType.NUMERIC);
    task.waitTillComplete();
    task = client.dropIndex(policy, args.namespace, args.set, indexName);
    task.waitTillComplete();
    task = client.createIndex(policy, args.namespace, args.set, indexName, binName, IndexType.NUMERIC);
    task.waitTillComplete();
    task = client.dropIndex(policy, args.namespace, args.set, indexName);
    task.waitTillComplete();
}
Also used : Policy(com.aerospike.client.policy.Policy) AerospikeException(com.aerospike.client.AerospikeException) IndexTask(com.aerospike.client.task.IndexTask) Test(org.junit.Test)

Example 19 with IndexTask

use of com.aerospike.client.task.IndexTask in project aerospike-client-java by aerospike.

the class TestQueryCollection method prepare.

@BeforeClass
public static void prepare() {
    RegisterTask rtask = client.register(null, TestQueryCollection.class.getClassLoader(), "udf/record_example.lua", "record_example.lua", Language.LUA);
    rtask.waitTillComplete();
    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.STRING, IndexCollectionType.MAPKEYS);
        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);
        HashMap<String, String> map = new HashMap<String, String>();
        map.put(mapKeyPrefix + 1, mapValuePrefix + i);
        if (i % 2 == 0) {
            map.put(mapKeyPrefix + 2, mapValuePrefix + i);
        }
        if (i % 3 == 0) {
            map.put(mapKeyPrefix + 3, mapValuePrefix + i);
        }
        Bin bin = new Bin(binName, map);
        client.put(null, key, bin);
    }
}
Also used : Policy(com.aerospike.client.policy.Policy) AerospikeException(com.aerospike.client.AerospikeException) HashMap(java.util.HashMap) 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 20 with IndexTask

use of com.aerospike.client.task.IndexTask in project aerospike-client-java by aerospike.

the class TestQueryFilter method prepare.

@BeforeClass
public static void prepare() {
    RegisterTask rtask = client.register(null, TestQueryFilter.class.getClassLoader(), "udf/filter_example.lua", "filter_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.STRING);
        itask.waitTillComplete();
    } catch (AerospikeException ae) {
        if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
            throw ae;
        }
    }
    writeRecord(keyPrefix + 1, "Charlie", "cpass");
    writeRecord(keyPrefix + 2, "Bill", "hknfpkj");
    writeRecord(keyPrefix + 3, "Doug", "dj6554");
}
Also used : Policy(com.aerospike.client.policy.Policy) AerospikeException(com.aerospike.client.AerospikeException) IndexTask(com.aerospike.client.task.IndexTask) RegisterTask(com.aerospike.client.task.RegisterTask) BeforeClass(org.junit.BeforeClass)

Aggregations

AerospikeException (com.aerospike.client.AerospikeException)29 IndexTask (com.aerospike.client.task.IndexTask)29 Policy (com.aerospike.client.policy.Policy)28 BeforeClass (org.junit.BeforeClass)13 Bin (com.aerospike.client.Bin)11 Key (com.aerospike.client.Key)11 RegisterTask (com.aerospike.client.task.RegisterTask)6 QueryPolicy (com.aerospike.client.policy.QueryPolicy)3 WritePolicy (com.aerospike.client.policy.WritePolicy)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 Test (org.junit.Test)1