Search in sources :

Example 21 with Record

use of com.aerospike.client.Record 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)

Example 22 with Record

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

the class ListMap method testListStrings.

/**
 * Write/Read ArrayList<String> directly instead of relying on java serializer.
 */
private void testListStrings(AerospikeClient client, Parameters params) throws Exception {
    console.info("Read/Write ArrayList<String>");
    Key key = new Key(params.namespace, params.set, "listkey1");
    client.delete(params.writePolicy, key);
    ArrayList<String> list = new ArrayList<String>();
    list.add("string1");
    list.add("string2");
    list.add("string3");
    Bin bin = new Bin(params.getBinName("listbin1"), list);
    client.put(params.writePolicy, key, bin);
    Record record = client.get(params.policy, key, bin.name);
    List<?> receivedList = (List<?>) record.getValue(bin.name);
    validateSize(3, receivedList.size());
    validate("string1", receivedList.get(0));
    validate("string2", receivedList.get(1));
    validate("string3", receivedList.get(2));
    console.info("Read/Write ArrayList<String> successful.");
}
Also used : Bin(com.aerospike.client.Bin) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) List(java.util.List) ArrayList(java.util.ArrayList) Key(com.aerospike.client.Key)

Example 23 with Record

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

the class ListMap method testMapComplex.

/**
 * Write/Read HashMap<Object,Object> directly instead of relying on java serializer.
 */
private void testMapComplex(AerospikeClient client, Parameters params) throws Exception {
    console.info("Read/Write HashMap<Object,Object>");
    Key key = new Key(params.namespace, params.set, "mapkey2");
    client.delete(params.writePolicy, key);
    byte[] blob = new byte[] { 3, 52, 125 };
    List<Integer> list = new ArrayList<Integer>();
    list.add(100034);
    list.add(12384955);
    list.add(3);
    list.add(512);
    HashMap<Object, Object> map = new HashMap<Object, Object>();
    map.put("key1", "string1");
    map.put("key2", 2);
    map.put("key3", blob);
    // map.put("key4", Value.getAsList(list)) works too
    map.put("key4", list);
    map.put("key5", true);
    map.put("key6", false);
    Bin bin = new Bin(params.getBinName("mapbin2"), map);
    client.put(params.writePolicy, key, bin);
    Record record = client.get(params.policy, key, bin.name);
    Map<?, ?> receivedMap = (Map<?, ?>) record.getValue(bin.name);
    validateSize(6, receivedMap.size());
    validate("string1", receivedMap.get("key1"));
    // Server convert numbers to long, so must expect long.
    validate(2L, receivedMap.get("key2"));
    validate(blob, (byte[]) receivedMap.get("key3"));
    List<?> receivedInner = (List<?>) receivedMap.get("key4");
    validateSize(4, receivedInner.size());
    validate(100034L, receivedInner.get(0));
    validate(12384955L, receivedInner.get(1));
    validate(3L, receivedInner.get(2));
    validate(512L, receivedInner.get(3));
    validate(true, receivedMap.get("key5"));
    validate(false, receivedMap.get("key6"));
    console.info("Read/Write HashMap<Object,Object> successful");
}
Also used : HashMap(java.util.HashMap) Bin(com.aerospike.client.Bin) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Key(com.aerospike.client.Key)

Example 24 with Record

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

the class ListMap method testListComplex.

/**
 * Write/Read ArrayList<Object> directly instead of relying on java serializer.
 */
private void testListComplex(AerospikeClient client, Parameters params) throws Exception {
    console.info("Read/Write ArrayList<Object>");
    Key key = new Key(params.namespace, params.set, "listkey2");
    client.delete(params.writePolicy, key);
    byte[] blob = new byte[] { 3, 52, 125 };
    ArrayList<Object> list = new ArrayList<Object>();
    list.add("string1");
    list.add(2);
    list.add(blob);
    Bin bin = new Bin(params.getBinName("listbin2"), list);
    client.put(params.writePolicy, key, bin);
    Record record = client.get(params.policy, key, bin.name);
    List<?> receivedList = (List<?>) record.getValue(bin.name);
    validateSize(3, receivedList.size());
    validate("string1", receivedList.get(0));
    // Server convert numbers to long, so must expect long.
    validate(2L, receivedList.get(1));
    validate(blob, (byte[]) receivedList.get(2));
    console.info("Read/Write ArrayList<Object> successful.");
}
Also used : Bin(com.aerospike.client.Bin) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) List(java.util.List) ArrayList(java.util.ArrayList) Key(com.aerospike.client.Key)

Example 25 with Record

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

the class TestBatch method batchReadHeaders.

@Test
public void batchReadHeaders() {
    Key[] keys = new Key[Size];
    for (int i = 0; i < Size; i++) {
        keys[i] = new Key(args.namespace, args.set, KeyPrefix + (i + 1));
    }
    Record[] records = client.getHeader(null, keys);
    assertEquals(Size, records.length);
    for (int i = 0; i < records.length; i++) {
        Key key = keys[i];
        Record record = records[i];
        assertRecordFound(key, record);
        assertNotEquals(0, record.generation);
        assertNotEquals(0, record.expiration);
    }
}
Also used : Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) Test(org.junit.Test)

Aggregations

Record (com.aerospike.client.Record)259 Key (com.aerospike.client.Key)140 Test (org.junit.Test)139 ArrayList (java.util.ArrayList)75 Bin (com.aerospike.client.Bin)70 AerospikeException (com.aerospike.client.AerospikeException)62 Value (com.aerospike.client.Value)54 WritePolicy (com.aerospike.client.policy.WritePolicy)47 List (java.util.List)41 HashMap (java.util.HashMap)36 ThrowingRunnable (org.junit.function.ThrowingRunnable)32 BatchPolicy (com.aerospike.client.policy.BatchPolicy)29 Policy (com.aerospike.client.policy.Policy)29 Statement (com.aerospike.client.query.Statement)23 RecordSet (com.aerospike.client.query.RecordSet)22 Expression (com.aerospike.client.exp.Expression)18 Map (java.util.Map)15 HLLValue (com.aerospike.client.Value.HLLValue)14 Collections.singletonList (java.util.Collections.singletonList)9 MapPolicy (com.aerospike.client.cdt.MapPolicy)7