Search in sources :

Example 21 with Value

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

the class TestOperateMap method operateMapRemove.

@Test
public void operateMapRemove() {
    // Test remove.
    if (!args.validateMap()) {
        return;
    }
    Key key = new Key(args.namespace, args.set, "opmkey7");
    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));
    List<Value> removeItems = new ArrayList<Value>();
    removeItems.add(Value.get("Sally"));
    removeItems.add(Value.get("UNKNOWN"));
    removeItems.add(Value.get("Lenny"));
    Record record = client.operate(null, key, MapOperation.putItems(MapPolicy.Default, binName, inputMap), MapOperation.removeByKey(binName, Value.get("NOTFOUND"), MapReturnType.VALUE), MapOperation.removeByKey(binName, Value.get("Jim"), MapReturnType.VALUE), MapOperation.removeByKeyList(binName, removeItems, MapReturnType.COUNT), MapOperation.removeByValue(binName, Value.get(55), MapReturnType.KEY), MapOperation.size(binName));
    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);
    Object obj = results.get(i++);
    assertNull(obj);
    val = (Long) results.get(i++);
    assertEquals(98, val);
    val = (Long) results.get(i++);
    assertEquals(2, val);
    List<?> list = (List<?>) results.get(i++);
    assertEquals(1, list.size());
    assertEquals("Charlie", (String) list.get(0));
    val = (Long) results.get(i++);
    assertEquals(3, val);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Value(com.aerospike.client.Value) Record(com.aerospike.client.Record) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 22 with Value

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

the class TestOperateMap method operateMapScore.

@Test
public void operateMapScore() {
    // Test score.
    if (!args.validateMap()) {
        return;
    }
    Key key = new Key(args.namespace, args.set, "opmkey10");
    client.delete(null, key);
    MapPolicy mapPolicy = new MapPolicy(MapOrder.KEY_VALUE_ORDERED, MapWriteMode.UPDATE);
    Map<Value, Value> inputMap = new HashMap<Value, Value>();
    inputMap.put(Value.get("weiling"), Value.get(0));
    inputMap.put(Value.get("briann"), Value.get(0));
    inputMap.put(Value.get("brianb"), Value.get(0));
    inputMap.put(Value.get("meher"), Value.get(0));
    // Create map.
    Record record = client.operate(null, key, MapOperation.putItems(mapPolicy, binName, inputMap));
    assertRecordFound(key, record);
    // Change scores
    record = client.operate(null, key, MapOperation.increment(mapPolicy, binName, Value.get("weiling"), Value.get(10)), MapOperation.increment(mapPolicy, binName, Value.get("briann"), Value.get(20)), MapOperation.increment(mapPolicy, binName, Value.get("brianb"), Value.get(1)), MapOperation.increment(mapPolicy, binName, Value.get("meher"), Value.get(20)));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    // Query top 3 scores
    record = client.operate(null, key, MapOperation.getByRankRange(binName, -3, 3, MapReturnType.KEY));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    // Remove people with score 10 and display top 3 again
    record = client.operate(null, key, MapOperation.removeByValue(binName, Value.get(10), MapReturnType.KEY), MapOperation.getByRankRange(binName, -3, 3, MapReturnType.KEY));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<?> results = record.getList(binName);
    int i = 0;
    List<?> list = (List<?>) results.get(i++);
    String s = (String) list.get(0);
    assertEquals("weiling", s);
    list = (List<?>) results.get(i++);
    s = (String) list.get(0);
    assertEquals("brianb", s);
    s = (String) list.get(1);
    assertEquals("briann", s);
    s = (String) list.get(2);
    assertEquals("meher", s);
}
Also used : HashMap(java.util.HashMap) Value(com.aerospike.client.Value) Record(com.aerospike.client.Record) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) MapPolicy(com.aerospike.client.cdt.MapPolicy) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 23 with Value

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

the class TestOperateMap method operateMapGetByList.

@Test
public void operateMapGetByList() {
    if (!args.validateMap()) {
        return;
    }
    Key key = new Key(args.namespace, args.set, "opmkey11");
    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));
    // Write values to empty map.
    Record record = client.operate(null, key, MapOperation.putItems(MapPolicy.Default, binName, inputMap));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<Value> keyList = new ArrayList<Value>();
    keyList.add(Value.get("Harry"));
    keyList.add(Value.get("Jim"));
    List<Value> valueList = new ArrayList<Value>();
    valueList.add(Value.get(76));
    valueList.add(Value.get(50));
    record = client.operate(null, key, MapOperation.getByKeyList(binName, keyList, MapReturnType.KEY_VALUE), MapOperation.getByValueList(binName, valueList, MapReturnType.KEY_VALUE));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<?> results = record.getList(binName);
    List<?> list = (List<?>) results.get(0);
    assertEquals(2L, list.size());
    Entry<?, ?> entry = (Entry<?, ?>) list.get(0);
    assertEquals("Harry", entry.getKey());
    assertEquals(82L, entry.getValue());
    entry = (Entry<?, ?>) list.get(1);
    assertEquals("Jim", entry.getKey());
    assertEquals(98L, entry.getValue());
    list = (List<?>) results.get(1);
    assertEquals(1L, list.size());
    entry = (Entry<?, ?>) list.get(0);
    assertEquals("John", entry.getKey());
    assertEquals(76L, entry.getValue());
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 24 with Value

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

the class TestOperateMap method operateMapMixed.

@Test
public void operateMapMixed() {
    // Test normal operations with map operations.
    if (!args.validateMap()) {
        return;
    }
    Key key = new Key(args.namespace, args.set, "opmkey2");
    client.delete(null, key);
    Map<Value, Value> itemMap = new HashMap<Value, Value>();
    itemMap.put(Value.get(12), Value.get("myval"));
    itemMap.put(Value.get(-8734), Value.get("str2"));
    itemMap.put(Value.get(1), Value.get("my default"));
    itemMap.put(Value.get(7), Value.get(1));
    Record record = client.operate(null, key, MapOperation.putItems(new MapPolicy(MapOrder.KEY_VALUE_ORDERED, MapWriteMode.UPDATE), binName, itemMap), Operation.put(new Bin("otherbin", "hello")));
    assertRecordFound(key, record);
    long size = record.getLong(binName);
    assertEquals(4, size);
    record = client.operate(null, key, MapOperation.getByKey(binName, Value.get(12), MapReturnType.INDEX), Operation.append(new Bin("otherbin", Value.get("goodbye"))), Operation.get("otherbin"));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    long index = record.getLong(binName);
    assertEquals(3, index);
    List<?> results = record.getList("otherbin");
    String val = (String) results.get(1);
    assertEquals("hellogoodbye", val);
}
Also used : HashMap(java.util.HashMap) Bin(com.aerospike.client.Bin) Value(com.aerospike.client.Value) Record(com.aerospike.client.Record) MapPolicy(com.aerospike.client.cdt.MapPolicy) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 25 with Value

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

the class RWTaskSync method largeStackPush.

private void largeStackPush(Key key, Value value, long timestamp) {
    // Create entry
    Map<String, Value> entry = new HashMap<String, Value>();
    entry.put("key", Value.get(timestamp));
    entry.put("log", value);
    // Push entry
    LargeStack lstack = client.getLargeStack(args.writePolicy, key, "stackltracker", null);
    lstack.push(Value.get(entry));
}
Also used : HashMap(java.util.HashMap) Value(com.aerospike.client.Value) LargeStack(com.aerospike.client.large.LargeStack)

Aggregations

Value (com.aerospike.client.Value)44 Key (com.aerospike.client.Key)37 ArrayList (java.util.ArrayList)26 Test (org.junit.Test)26 Record (com.aerospike.client.Record)25 HashMap (java.util.HashMap)25 List (java.util.List)18 Bin (com.aerospike.client.Bin)9 Map (java.util.Map)7 Collections.singletonList (java.util.Collections.singletonList)6 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 Entry (java.util.Map.Entry)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