Search in sources :

Example 96 with AerospikeException

use of com.aerospike.client.AerospikeException 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 97 with AerospikeException

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

the class TestReplace method replaceOnly.

@Test
public void replaceOnly() {
    Key key = new Key(args.namespace, args.set, "replaceonlykey");
    Bin bin = new Bin("bin", "value");
    // Delete record if it already exists.
    client.delete(null, key);
    try {
        WritePolicy policy = new WritePolicy();
        policy.recordExistsAction = RecordExistsAction.REPLACE_ONLY;
        client.put(policy, key, bin);
        fail("Failure. This command should have resulted in an error.");
    } catch (AerospikeException ae) {
        if (ae.getResultCode() != ResultCode.KEY_NOT_FOUND_ERROR) {
            throw ae;
        }
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key) WritePolicy(com.aerospike.client.policy.WritePolicy) Test(org.junit.Test)

Example 98 with AerospikeException

use of com.aerospike.client.AerospikeException 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 99 with AerospikeException

use of com.aerospike.client.AerospikeException 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 100 with AerospikeException

use of com.aerospike.client.AerospikeException 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)175 Record (com.aerospike.client.Record)58 Test (org.junit.Test)58 Policy (com.aerospike.client.policy.Policy)57 Key (com.aerospike.client.Key)56 WritePolicy (com.aerospike.client.policy.WritePolicy)42 ThrowingRunnable (org.junit.function.ThrowingRunnable)41 Bin (com.aerospike.client.Bin)32 IndexTask (com.aerospike.client.task.IndexTask)29 BatchPolicy (com.aerospike.client.policy.BatchPolicy)28 BeforeClass (org.junit.BeforeClass)14 IOException (java.io.IOException)12 Node (com.aerospike.client.cluster.Node)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)8 RegisterTask (com.aerospike.client.task.RegisterTask)7 Expression (com.aerospike.client.exp.Expression)6 SocketTimeoutException (java.net.SocketTimeoutException)6 AerospikeClient (com.aerospike.client.AerospikeClient)5 Value (com.aerospike.client.Value)5