Search in sources :

Example 41 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 : Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) ArrayList(java.util.ArrayList) List(java.util.List) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 42 with Value

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

the class TestOperateList method operateList8.

@Test
public void operateList8() {
    // Test increment.
    Key key = new Key(args.namespace, args.set, "oplkey8");
    client.delete(null, key);
    List<Value> itemList = new ArrayList<Value>();
    itemList.add(Value.get(1));
    itemList.add(Value.get(2));
    itemList.add(Value.get(3));
    Record record = client.operate(null, key, ListOperation.appendItems(binName, itemList), ListOperation.increment(binName, 2), ListOperation.increment(ListPolicy.Default, binName, 2), ListOperation.increment(binName, 1, Value.get(7)), ListOperation.increment(ListPolicy.Default, binName, 1, Value.get(7)), ListOperation.get(binName, 0));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<?> results = record.getList(binName);
    int i = 0;
    long size = (Long) results.get(i++);
    assertEquals(3, size);
    long val = (Long) results.get(i++);
    assertEquals(4, val);
    val = (Long) results.get(i++);
    assertEquals(5, val);
    val = (Long) results.get(i++);
    assertEquals(9, val);
    val = (Long) results.get(i++);
    assertEquals(16, val);
    val = (Long) results.get(i++);
    assertEquals(1, val);
}
Also used : Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 43 with Value

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

the class TestOperateMap method operateMapInverted.

@Test
public void operateMapInverted() {
    if (!args.validateMap()) {
        return;
    }
    Key key = new Key(args.namespace, args.set, "opmkey12");
    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);
    List<Value> valueList = new ArrayList<Value>();
    valueList.add(Value.get(76));
    valueList.add(Value.get(55));
    valueList.add(Value.get(98));
    valueList.add(Value.get(50));
    record = client.operate(null, key, MapOperation.getByValue(binName, Value.get(81), MapReturnType.RANK | MapReturnType.INVERTED), MapOperation.getByValue(binName, Value.get(82), MapReturnType.RANK | MapReturnType.INVERTED), MapOperation.getByValueRange(binName, Value.get(90), Value.get(95), MapReturnType.RANK | MapReturnType.INVERTED), MapOperation.getByValueRange(binName, Value.get(90), Value.get(100), MapReturnType.RANK | MapReturnType.INVERTED), MapOperation.getByValueList(binName, valueList, MapReturnType.KEY_VALUE | MapReturnType.INVERTED), MapOperation.getByRankRange(binName, -2, 2, MapReturnType.KEY | MapReturnType.INVERTED), MapOperation.getByRankRange(binName, 0, 3, MapReturnType.KEY_VALUE | MapReturnType.INVERTED));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<?> results = record.getList(binName);
    int i = 0;
    List<?> list = (List<?>) results.get(i++);
    assertEquals(4L, list.size());
    list = (List<?>) results.get(i++);
    assertEquals(3L, list.size());
    list = (List<?>) results.get(i++);
    assertEquals(4L, list.size());
    list = (List<?>) results.get(i++);
    assertEquals(3L, list.size());
    assertEquals(0L, list.get(0));
    assertEquals(1L, list.get(1));
    assertEquals(2L, list.get(2));
    list = (List<?>) results.get(i++);
    assertEquals(1L, list.size());
    Entry<?, ?> entry = (Entry<?, ?>) list.get(0);
    assertEquals("Harry", entry.getKey());
    assertEquals(82L, entry.getValue());
    list = (List<?>) results.get(i++);
    assertEquals(2L, list.size());
    assertEquals("Charlie", list.get(0));
    assertEquals("John", list.get(1));
    list = (List<?>) results.get(i++);
    assertEquals(1L, list.size());
    entry = (Entry<?, ?>) list.get(0);
    assertEquals("Jim", entry.getKey());
    assertEquals(98L, 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 44 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)

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