Search in sources :

Example 86 with Key

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

the class TestOperateList method operateList4.

@Test
public void operateList4() {
    // Test all value types.
    Key key = new Key(args.namespace, args.set, "oplkey4");
    client.delete(null, key);
    List<Value> inputList = new ArrayList<Value>();
    inputList.add(Value.get(12));
    inputList.add(Value.get(-8734.81));
    inputList.add(Value.get("my string"));
    Map<Integer, String> inputMap = new HashMap<Integer, String>();
    inputMap.put(9, "data 9");
    inputMap.put(-2, "data -2");
    byte[] bytes = "string bytes".getBytes();
    List<Value> itemList = new ArrayList<Value>();
    itemList.add(Value.get(true));
    itemList.add(Value.get(55));
    itemList.add(Value.get("string value"));
    itemList.add(Value.get(inputList));
    itemList.add(Value.get(bytes));
    itemList.add(Value.get(99.99));
    itemList.add(Value.get(inputMap));
    Record record = client.operate(null, key, ListOperation.appendItems(binName, itemList), ListOperation.getRange(binName, 0, 100), ListOperation.set(binName, 1, Value.get("88")), ListOperation.get(binName, 1), ListOperation.popRange(binName, -2, 1), ListOperation.popRange(binName, -1), ListOperation.remove(binName, 3), ListOperation.removeRange(binName, 0, 1), ListOperation.removeRange(binName, 2), ListOperation.size(binName));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<?> list = record.getList(binName);
    long size = (Long) list.get(0);
    assertEquals(7, size);
    List<?> rangeList = (List<?>) list.get(1);
    assertTrue((boolean) (Boolean) rangeList.get(0));
    assertEquals(55, (long) (Long) rangeList.get(1));
    assertEquals("string value", (String) rangeList.get(2));
    List<?> subList = (List<?>) rangeList.get(3);
    assertEquals(3, subList.size());
    assertEquals(12, (long) (Long) subList.get(0));
    assertEquals(-8734.81, (double) (Double) subList.get(1), 0.00001);
    assertEquals("my string", (String) subList.get(2));
    byte[] bt = (byte[]) rangeList.get(4);
    assertArrayEquals("bytes not equal", bytes, bt);
    assertEquals(99.99, (double) (Double) rangeList.get(5), 0.00001);
    Map<?, ?> subMap = (Map<?, ?>) rangeList.get(6);
    assertEquals(2, subMap.size());
    assertEquals("data 9", (String) subMap.get(9L));
    assertEquals("data -2", (String) subMap.get(-2L));
    // Set does not return a result.
    assertEquals("88", (String) list.get(2));
    subList = (List<?>) list.get(3);
    assertEquals(1, subList.size());
    assertEquals(99.99, (double) (Double) subList.get(0), 0.00001);
    subList = (List<?>) list.get(4);
    assertEquals(1, subList.size());
    assertTrue(subList.get(0) instanceof Map);
    assertEquals(1, (long) (Long) list.get(5));
    assertEquals(1, (long) (Long) list.get(6));
    assertEquals(1, (long) (Long) list.get(7));
    size = (Long) list.get(8);
    assertEquals(2, size);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Value(com.aerospike.client.Value) Record(com.aerospike.client.Record) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 87 with Key

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

the class TestOperateList method operateList5.

@Test
public void operateList5() {
    // Test trim.
    Key key = new Key(args.namespace, args.set, "oplkey5");
    client.delete(null, key);
    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(null, key, ListOperation.insertItems(binName, 0, itemList), ListOperation.trim(binName, -5, 5), ListOperation.trim(binName, 1, -5), ListOperation.trim(binName, 1, 2));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<?> list = record.getList(binName);
    long size = (Long) list.get(0);
    assertEquals(5, size);
    size = (Long) list.get(1);
    assertEquals(0, size);
    size = (Long) list.get(2);
    assertEquals(1, size);
    size = (Long) list.get(3);
    assertEquals(2, size);
}
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 88 with Key

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

the class TestOperateList method operateListSort.

@Test
public void operateListSort() {
    Key key = new Key(args.namespace, args.set, "oplkey10");
    client.delete(null, key);
    List<Value> itemList = new ArrayList<Value>();
    itemList.add(Value.get(-44));
    itemList.add(Value.get(33));
    itemList.add(Value.get(-1));
    itemList.add(Value.get(33));
    itemList.add(Value.get(-2));
    Record record = client.operate(null, key, ListOperation.appendItems(ListPolicy.Default, binName, itemList), ListOperation.sort(binName, ListSortFlags.DROP_DUPLICATES), ListOperation.size(binName));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<?> results = record.getList(binName);
    int i = 0;
    long size = (Long) results.get(i++);
    assertEquals(5L, size);
    long val = (Long) results.get(i++);
    assertEquals(4L, 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 89 with Key

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

the class TestOperateList method operateList7.

@Test
public void operateList7() {
    // Test null values.
    Key key = new Key(args.namespace, args.set, "oplkey7");
    client.delete(null, key);
    List<Value> itemList = new ArrayList<Value>();
    itemList.add(Value.get("s11"));
    itemList.add(Value.getAsNull());
    itemList.add(Value.get("s3333333"));
    Record record = client.operate(null, key, ListOperation.appendItems(binName, itemList), ListOperation.get(binName, 0), ListOperation.get(binName, 1), ListOperation.get(binName, 2));
    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);
    String str = (String) results.get(i++);
    assertEquals("s11", str);
    str = (String) results.get(i++);
    assertNull(str);
    str = (String) results.get(i++);
    assertEquals("s3333333", str);
}
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 90 with Key

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

the class TestOperateList method operateListInverted.

@Test
public void operateListInverted() {
    Key key = new Key(args.namespace, args.set, "oplkey12");
    client.delete(null, key);
    List<Value> itemList = new ArrayList<Value>();
    itemList.add(Value.get(4));
    itemList.add(Value.get(3));
    itemList.add(Value.get(1));
    itemList.add(Value.get(5));
    itemList.add(Value.get(2));
    List<Value> valueList = new ArrayList<Value>();
    valueList.add(Value.get(4));
    valueList.add(Value.get(2));
    Record record = client.operate(null, key, ListOperation.appendItems(ListPolicy.Default, binName, itemList), ListOperation.getByValue(binName, Value.get(3), ListReturnType.INDEX | ListReturnType.INVERTED), ListOperation.getByValueRange(binName, Value.get(-1), Value.get(3), ListReturnType.COUNT | ListReturnType.INVERTED), ListOperation.getByValueList(binName, valueList, ListReturnType.RANK | ListReturnType.INVERTED), ListOperation.getByIndexRange(binName, -2, 2, ListReturnType.VALUE | ListReturnType.INVERTED), ListOperation.getByRankRange(binName, 2, 3, ListReturnType.VALUE | ListReturnType.INVERTED));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<?> results = record.getList(binName);
    int i = 0;
    long size = (Long) results.get(i++);
    assertEquals(5L, size);
    List<?> list = (List<?>) results.get(i++);
    assertEquals(4L, list.size());
    assertEquals(0L, list.get(0));
    assertEquals(2L, list.get(1));
    assertEquals(3L, list.get(2));
    assertEquals(4L, list.get(3));
    long val = (Long) results.get(i++);
    assertEquals(3L, val);
    list = (List<?>) results.get(i++);
    assertEquals(3L, list.size());
    assertEquals(0L, list.get(0));
    assertEquals(2L, list.get(1));
    assertEquals(4L, list.get(2));
    list = (List<?>) results.get(i++);
    assertEquals(3L, list.size());
    assertEquals(4L, list.get(0));
    assertEquals(3L, list.get(1));
    assertEquals(1L, list.get(2));
    list = (List<?>) results.get(i++);
    assertEquals(2L, list.size());
    assertEquals(1L, list.get(0));
    assertEquals(2L, list.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)

Aggregations

Key (com.aerospike.client.Key)204 Record (com.aerospike.client.Record)106 Bin (com.aerospike.client.Bin)104 Test (org.junit.Test)79 AerospikeException (com.aerospike.client.AerospikeException)50 ArrayList (java.util.ArrayList)50 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)9 IndexTask (com.aerospike.client.task.IndexTask)8 IOException (java.io.IOException)6 Collections.singletonList (java.util.Collections.singletonList)6 AerospikeClient (com.aerospike.client.AerospikeClient)5 BatchRead (com.aerospike.client.BatchRead)5