Search in sources :

Example 81 with Record

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

Example 82 with Record

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

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

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

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

the class TestOperateList method operateList2.

@Test
public void operateList2() {
    Key key = new Key(args.namespace, args.set, "oplkey2");
    client.delete(null, key);
    List<Value> itemList = new ArrayList<Value>();
    itemList.add(Value.get(12));
    itemList.add(Value.get(-8734));
    itemList.add(Value.get("my string"));
    Record record = client.operate(null, key, ListOperation.appendItems(binName, itemList), Operation.put(new Bin("otherbin", "hello")));
    assertRecordFound(key, record);
    record = client.operate(null, key, ListOperation.insert(binName, -1, Value.get(8)), Operation.append(new Bin("otherbin", Value.get("goodbye"))), Operation.get("otherbin"), ListOperation.getRange(binName, 0, 4), ListOperation.getRange(binName, 3));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    String val = record.getString("otherbin");
    assertEquals("hellogoodbye", val);
    List<?> list = record.getList(binName);
    long size = (Long) list.get(0);
    assertEquals(4, size);
    List<?> rangeList = (List<?>) list.get(1);
    long lval = (Long) rangeList.get(0);
    assertEquals(12, lval);
    lval = (Long) rangeList.get(1);
    assertEquals(-8734, lval);
    lval = (Long) rangeList.get(2);
    assertEquals(8, lval);
    val = (String) rangeList.get(3);
    assertEquals("my string", val);
    rangeList = (List<?>) list.get(2);
    val = (String) rangeList.get(0);
    assertEquals("my string", val);
}
Also used : Bin(com.aerospike.client.Bin) 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

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