Search in sources :

Example 36 with Key

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

the class TestAsyncBatch method asyncBatchGetHeaders.

@Test
public void asyncBatchGetHeaders() throws Exception {
    client.getHeader(eventLoop, new RecordArrayListener() {

        public void onSuccess(Key[] keys, Record[] records) {
            if (assertEquals(size, records.length)) {
                for (int i = 0; i < records.length; i++) {
                    Record record = records[i];
                    if (!assertRecordFound(keys[i], record)) {
                        break;
                    }
                    if (!assertGreaterThanZero(record.generation)) {
                        break;
                    }
                    if (!assertGreaterThanZero(record.expiration)) {
                        break;
                    }
                }
            }
            notifyComplete();
        }

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

Example 37 with Key

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

the class TestAsyncPutGet method asyncPutGetWithRetry.

@Test
public void asyncPutGetWithRetry() {
    final Key key = new Key(args.namespace, args.set, "putgetkey2");
    final Bin bin = new Bin(binName, "value");
    client.put(eventLoop, new WriteHandler(client, null, key, bin), null, key, bin);
    waitTillComplete();
}
Also used : Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 38 with Key

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

the class TestAsyncBatch method asyncBatchExistsArray.

@Test
public void asyncBatchExistsArray() {
    client.exists(eventLoop, new ExistsArrayListener() {

        public void onSuccess(Key[] keys, boolean[] existsArray) {
            for (int i = 0; i < existsArray.length; i++) {
                if (!assertEquals(true, existsArray[i])) {
                    break;
                }
            }
            notifyComplete();
        }

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

Example 39 with Key

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

the class LargeMap method runExample.

/**
	 * Perform operations on a Large Map within a single bin.
	 */
@Override
public void runExample(AerospikeClient client, Parameters params) throws Exception {
    if (!params.hasLargeDataTypes) {
        console.info("Large Map functions are not supported by the connected Aerospike server.");
        return;
    }
    Key key = new Key(params.namespace, params.set, "setkey");
    String binName = params.getBinName("setbin");
    // Delete record if it already exists.
    client.delete(params.writePolicy, key);
    // Initialize Large Map operator.
    com.aerospike.client.large.LargeMap lmap = client.getLargeMap(params.writePolicy, key, binName, null);
    // Write values.
    lmap.put(Value.get("lmapName1"), Value.get("lmapValue1"));
    lmap.put(Value.get("lmapName2"), Value.get("lmapValue2"));
    lmap.put(Value.get("lmapName3"), Value.get("lmapValue3"));
    // Verify large set was created with default configuration.
    Map<?, ?> map = lmap.getConfig();
    for (Entry<?, ?> entry : map.entrySet()) {
        console.info(entry.getKey().toString() + ',' + entry.getValue());
    }
    // Remove last value.
    lmap.remove(Value.get("lmapName3"));
    int size = lmap.size();
    if (size != 2) {
        throw new Exception("Size mismatch. Expected 2 Received " + size);
    }
    Map<?, ?> mapReceived = lmap.get(Value.get("lmapName2"));
    String expected = "lmapValue2";
    String stringReceived = (String) mapReceived.get("lmapName2");
    if (stringReceived != null && stringReceived.equals(expected)) {
        console.info("Data matched: namespace=%s set=%s key=%s value=%s", key.namespace, key.setName, key.userKey, stringReceived);
    } else {
        console.error("Data mismatch: Expected %s. Received %s.", expected, stringReceived);
    }
}
Also used : Key(com.aerospike.client.Key)

Example 40 with Key

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

the class AsyncMultiCommand method parseGroup.

final boolean parseGroup(int receiveSize) {
    // Parse each message response and add it to the result array
    dataOffset = 0;
    while (dataOffset < receiveSize) {
        resultCode = dataBuffer[dataOffset + 5] & 0xFF;
        if (resultCode != 0) {
            if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR) {
                if (stopOnNotFound) {
                    return true;
                }
            } else {
                throw new AerospikeException(resultCode);
            }
        }
        // If this is the end marker of the response, do not proceed further
        if ((dataBuffer[dataOffset + 3] & Command.INFO3_LAST) != 0) {
            return true;
        }
        generation = Buffer.bytesToInt(dataBuffer, dataOffset + 6);
        expiration = Buffer.bytesToInt(dataBuffer, dataOffset + 10);
        batchIndex = Buffer.bytesToInt(dataBuffer, dataOffset + 14);
        fieldCount = Buffer.bytesToShort(dataBuffer, dataOffset + 18);
        opCount = Buffer.bytesToShort(dataBuffer, dataOffset + 20);
        dataOffset += Command.MSG_REMAINING_HEADER_SIZE;
        Key key = parseKey();
        parseRow(key);
    }
    return false;
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Key(com.aerospike.client.Key)

Aggregations

Key (com.aerospike.client.Key)201 Record (com.aerospike.client.Record)104 Bin (com.aerospike.client.Bin)103 Test (org.junit.Test)79 ArrayList (java.util.ArrayList)49 AerospikeException (com.aerospike.client.AerospikeException)47 Value (com.aerospike.client.Value)37 HashMap (java.util.HashMap)32 List (java.util.List)31 WritePolicy (com.aerospike.client.policy.WritePolicy)21 Map (java.util.Map)15 Statement (com.aerospike.client.query.Statement)10 BeforeClass (org.junit.BeforeClass)10 Policy (com.aerospike.client.policy.Policy)9 RecordSet (com.aerospike.client.query.RecordSet)8 IndexTask (com.aerospike.client.task.IndexTask)8 Collections.singletonList (java.util.Collections.singletonList)6 AerospikeClient (com.aerospike.client.AerospikeClient)5 BatchRead (com.aerospike.client.BatchRead)5 MapPolicy (com.aerospike.client.cdt.MapPolicy)5