Search in sources :

Example 41 with AerospikeException

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

the class TestAsyncBatch method asyncBatchExistsSequence.

@Test
public void asyncBatchExistsSequence() throws Exception {
    client.exists(eventLoop, new ExistsSequenceListener() {

        public void onExists(Key key, boolean exists) {
            assertEquals(true, exists);
        }

        public void onSuccess() {
            notifyComplete();
        }

        public void onFailure(AerospikeException e) {
            setError(e);
            notifyComplete();
        }
    }, null, sendKeys);
    waitTillComplete();
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Key(com.aerospike.client.Key) ExistsSequenceListener(com.aerospike.client.listener.ExistsSequenceListener) Test(org.junit.Test)

Example 42 with AerospikeException

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

the class TestAsyncOperate method asyncOperateList.

@Test
public void asyncOperateList() {
    final Key key = new Key(args.namespace, args.set, "aoplkey1");
    client.delete(eventLoop, new DeleteListener() {

        public void onSuccess(Key key, boolean existed) {
            List<Value> itemList = new ArrayList<Value>();
            itemList.add(Value.get(55));
            itemList.add(Value.get(77));
            client.operate(eventLoop, new ReadHandler(), null, key, ListOperation.appendItems(binName, itemList), ListOperation.pop(binName, -1), ListOperation.size(binName));
        }

        public void onFailure(AerospikeException e) {
            setError(e);
            notifyComplete();
        }
    }, null, key);
    waitTillComplete();
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Value(com.aerospike.client.Value) DeleteListener(com.aerospike.client.listener.DeleteListener) ArrayList(java.util.ArrayList) List(java.util.List) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 43 with AerospikeException

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

the class TestAsyncOperate method asyncOperateMap.

@Test
public void asyncOperateMap() {
    final Key key = new Key(args.namespace, args.set, "aopmkey1");
    client.delete(eventLoop, new DeleteListener() {

        public void onSuccess(Key key, boolean existed) {
            Map<Value, Value> map = new HashMap<Value, Value>();
            map.put(Value.get("a"), Value.get(1));
            map.put(Value.get("b"), Value.get(2));
            map.put(Value.get("c"), Value.get(3));
            client.operate(eventLoop, new MapHandler(), null, key, MapOperation.putItems(MapPolicy.Default, binName, map), MapOperation.getByRankRange(binName, -1, 1, MapReturnType.KEY_VALUE));
        }

        public void onFailure(AerospikeException e) {
            setError(e);
            notifyComplete();
        }
    }, null, key);
    waitTillComplete();
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Value(com.aerospike.client.Value) DeleteListener(com.aerospike.client.listener.DeleteListener) HashMap(java.util.HashMap) Map(java.util.Map) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 44 with AerospikeException

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

the class TestAsyncPutGet method asyncPutGetInline.

@Test
public void asyncPutGetInline() {
    final Key key = new Key(args.namespace, args.set, "putgetkey1");
    final Bin bin = new Bin(binName, "value");
    client.put(eventLoop, new WriteListener() {

        public void onSuccess(final Key key) {
            try {
                // Write succeeded.  Now call read.
                client.get(eventLoop, new RecordListener() {

                    public void onSuccess(final Key key, final Record record) {
                        assertBinEqual(key, record, bin);
                        notifyComplete();
                    }

                    public void onFailure(AerospikeException e) {
                        setError(e);
                        notifyComplete();
                    }
                }, null, key);
            } catch (Exception e) {
                setError(e);
                notifyComplete();
            }
        }

        public void onFailure(AerospikeException e) {
            setError(e);
            notifyComplete();
        }
    }, null, key, bin);
    waitTillComplete();
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) RecordListener(com.aerospike.client.listener.RecordListener) Record(com.aerospike.client.Record) WriteListener(com.aerospike.client.listener.WriteListener) Key(com.aerospike.client.Key) IOException(java.io.IOException) ConnectException(java.net.ConnectException) AerospikeException(com.aerospike.client.AerospikeException) Test(org.junit.Test)

Example 45 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)

Aggregations

AerospikeException (com.aerospike.client.AerospikeException)107 Key (com.aerospike.client.Key)46 Bin (com.aerospike.client.Bin)24 Policy (com.aerospike.client.policy.Policy)24 IndexTask (com.aerospike.client.task.IndexTask)24 Record (com.aerospike.client.Record)19 Test (org.junit.Test)16 Node (com.aerospike.client.cluster.Node)12 IOException (java.io.IOException)10 BeforeClass (org.junit.BeforeClass)10 WritePolicy (com.aerospike.client.policy.WritePolicy)7 HashMap (java.util.HashMap)7 Statement (com.aerospike.client.query.Statement)6 RegisterTask (com.aerospike.client.task.RegisterTask)6 ArrayList (java.util.ArrayList)6 AerospikeClient (com.aerospike.client.AerospikeClient)5 Value (com.aerospike.client.Value)5 RecordSequenceListener (com.aerospike.client.listener.RecordSequenceListener)5 RecordSet (com.aerospike.client.query.RecordSet)5 HashedWheelTimeout (com.aerospike.client.async.HashedWheelTimer.HashedWheelTimeout)4