Search in sources :

Example 31 with Value

use of com.aerospike.client.Value 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 32 with Value

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

the class TestSerialize method serializeComplex.

@Test
public void serializeComplex() {
    Key key = new Key(args.namespace, args.set, "serialcomplexkey");
    // Delete record if it already exists.
    client.delete(null, key);
    ArrayList<Object> inner = new ArrayList<Object>();
    inner.add("string2");
    inner.add(8);
    HashMap<Object, Object> innerMap = new HashMap<Object, Object>();
    innerMap.put("a", 1);
    innerMap.put(2, "b");
    innerMap.put("list", inner);
    ArrayList<Object> list = new ArrayList<Object>();
    list.add("string1");
    list.add(4);
    list.add(inner);
    list.add(innerMap);
    Bin bin = new Bin(args.getBinName("complexbin"), new Value.BlobValue(list));
    client.put(null, key, bin);
    Record record = client.get(null, key, bin.name);
    assertRecordFound(key, record);
    Object received = null;
    try {
        received = (List<?>) record.getValue(bin.name);
    } catch (Exception e) {
        fail("Failed to parse returned value: namespace=" + key.namespace + " set=" + key.setName + " key=" + key.userKey + " bin=" + bin.name);
    }
    if (received == null || !received.equals(list)) {
        fail("Data mismatch" + Environment.Newline + "Expected " + list + Environment.Newline + "Received " + received);
    }
}
Also used : HashMap(java.util.HashMap) Bin(com.aerospike.client.Bin) ArrayList(java.util.ArrayList) Value(com.aerospike.client.Value) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 33 with Value

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

the class TestOperateMap method operateMapRemoveRange.

@Test
public void operateMapRemoveRange() {
    // Test remove ranges.
    if (!args.validateMap()) {
        return;
    }
    Key key = new Key(args.namespace, args.set, "opmkey8");
    client.delete(null, key);
    Map<Value, Value> inputMap = new HashMap<Value, Value>();
    inputMap.put(Value.get("Charlie"), Value.get(55));
    inputMap.put(Value.get("Jim"), Value.get(98));
    inputMap.put(Value.get("John"), Value.get(76));
    inputMap.put(Value.get("Harry"), Value.get(82));
    inputMap.put(Value.get("Sally"), Value.get(79));
    inputMap.put(Value.get("Lenny"), Value.get(84));
    inputMap.put(Value.get("Abe"), Value.get(88));
    Record record = client.operate(null, key, MapOperation.putItems(MapPolicy.Default, binName, inputMap), MapOperation.removeByKeyRange(binName, Value.get("J"), Value.get("K"), MapReturnType.COUNT), MapOperation.removeByValueRange(binName, Value.get(80), Value.get(85), MapReturnType.COUNT), MapOperation.removeByIndexRange(binName, 0, 2, MapReturnType.COUNT), MapOperation.removeByRankRange(binName, 0, 2, MapReturnType.COUNT));
    assertRecordFound(key, record);
    //System.out.println("Record: " + record);
    List<?> results = record.getList(binName);
    int i = 0;
    long val = (Long) results.get(i++);
    assertEquals(7, val);
    val = (Long) results.get(i++);
    assertEquals(2, val);
    val = (Long) results.get(i++);
    assertEquals(2, val);
    val = (Long) results.get(i++);
    assertEquals(2, val);
    val = (Long) results.get(i++);
    assertEquals(1, val);
}
Also used : HashMap(java.util.HashMap) Value(com.aerospike.client.Value) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 34 with Value

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

the class TestOperateList method operateList3.

@Test
public void operateList3() {
    // Test out of bounds conditions
    Key key = new Key(args.namespace, args.set, "oplkey3");
    client.delete(null, key);
    List<Value> itemList = new ArrayList<Value>();
    itemList.add(Value.get("str1"));
    itemList.add(Value.get("str2"));
    itemList.add(Value.get("str3"));
    itemList.add(Value.get("str4"));
    itemList.add(Value.get("str5"));
    itemList.add(Value.get("str6"));
    itemList.add(Value.get("str7"));
    Record record = client.operate(null, key, ListOperation.appendItems(binName, itemList), ListOperation.get(binName, 2), ListOperation.getRange(binName, 6, 4), ListOperation.getRange(binName, -7, 3), ListOperation.getRange(binName, 0, 2), ListOperation.getRange(binName, -2, 4));
    assertRecordFound(key, record);
    //System.out.println("Record: " + record);
    List<?> list = record.getList(binName);
    long size = (Long) list.get(0);
    assertEquals(7, size);
    assertEquals("str3", (String) list.get(1));
    List<?> rangeList = (List<?>) list.get(2);
    assertEquals(1, rangeList.size());
    assertEquals("str7", (String) rangeList.get(0));
    rangeList = (List<?>) list.get(3);
    assertEquals(3, rangeList.size());
    assertEquals("str1", (String) rangeList.get(0));
    assertEquals("str2", (String) rangeList.get(1));
    assertEquals("str3", (String) rangeList.get(2));
    rangeList = (List<?>) list.get(4);
    assertEquals(2, rangeList.size());
    assertEquals("str1", (String) rangeList.get(0));
    assertEquals("str2", (String) rangeList.get(1));
    rangeList = (List<?>) list.get(5);
    assertEquals(2, rangeList.size());
    assertEquals("str6", (String) rangeList.get(0));
    assertEquals("str7", (String) rangeList.get(1));
}
Also used : ArrayList(java.util.ArrayList) Value(com.aerospike.client.Value) Record(com.aerospike.client.Record) ArrayList(java.util.ArrayList) List(java.util.List) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 35 with Value

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

the class TestOperateList method operateList6.

@Test
public void operateList6() {
    // Test clear.
    Key key = new Key(args.namespace, args.set, "oplkey6");
    client.delete(null, key);
    WritePolicy policy = new WritePolicy();
    policy.respondAllOps = true;
    List<Value> itemList = new ArrayList<Value>();
    itemList.add(Value.get("s11"));
    itemList.add(Value.get("s22222"));
    itemList.add(Value.get("s3333333"));
    itemList.add(Value.get("s4444444444"));
    itemList.add(Value.get("s5555555555555555"));
    Record record = client.operate(policy, key, Operation.put(new Bin("otherbin", 11)), Operation.get("otherbin"), ListOperation.appendItems(binName, itemList), ListOperation.clear(binName), ListOperation.size(binName));
    assertRecordFound(key, record);
    //System.out.println("Record: " + record);
    List<?> list = record.getList("otherbin");
    assertEquals(2, list.size());
    assertNull(list.get(0));
    assertEquals(11, (long) (Long) list.get(1));
    list = record.getList(binName);
    long size = (Long) list.get(0);
    assertEquals(5, size);
    // clear() does not return value by default, but we set respondAllOps, so it returns null.
    assertNull(list.get(1));
    size = (Long) list.get(2);
    assertEquals(0, size);
}
Also used : Bin(com.aerospike.client.Bin) ArrayList(java.util.ArrayList) Value(com.aerospike.client.Value) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) WritePolicy(com.aerospike.client.policy.WritePolicy) Test(org.junit.Test)

Aggregations

Value (com.aerospike.client.Value)37 Key (com.aerospike.client.Key)30 HashMap (java.util.HashMap)23 ArrayList (java.util.ArrayList)19 Test (org.junit.Test)19 Record (com.aerospike.client.Record)18 List (java.util.List)13 Bin (com.aerospike.client.Bin)9 Map (java.util.Map)7 AerospikeException (com.aerospike.client.AerospikeException)5 LargeList (com.aerospike.client.large.LargeList)5 Calendar (java.util.Calendar)4 GregorianCalendar (java.util.GregorianCalendar)4 MapPolicy (com.aerospike.client.cdt.MapPolicy)3 LargeStack (com.aerospike.client.large.LargeStack)2 DeleteListener (com.aerospike.client.listener.DeleteListener)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 LuaInputStream (com.aerospike.client.lua.LuaInputStream)1 LuaOutputStream (com.aerospike.client.lua.LuaOutputStream)1