Search in sources :

Example 86 with Record

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

the class TestOperateList method operateListWildcard.

@Test
public void operateListWildcard() {
    Key key = new Key(args.namespace, args.set, "oplkey17");
    client.delete(null, key);
    List<Value> i1 = new ArrayList<Value>();
    i1.add(Value.get("John"));
    i1.add(Value.get(55));
    List<Value> i2 = new ArrayList<Value>();
    i2.add(Value.get("Jim"));
    i2.add(Value.get(95));
    List<Value> i3 = new ArrayList<Value>();
    i3.add(Value.get("Joe"));
    i3.add(Value.get(80));
    List<Value> itemList = new ArrayList<Value>();
    itemList.add(Value.get(i1));
    itemList.add(Value.get(i2));
    itemList.add(Value.get(i3));
    Record record = client.operate(null, key, ListOperation.appendItems(binName, itemList));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    long size = record.getLong(binName);
    assertEquals(3L, size);
    itemList = new ArrayList<Value>();
    itemList.add(Value.get("Jim"));
    itemList.add(Value.WILDCARD);
    record = client.operate(null, key, ListOperation.getByValue(binName, Value.get(itemList), ListReturnType.VALUE));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<?> results = record.getList(binName);
    int i = 0;
    List<?> items = (List<?>) results.get(i++);
    String s = (String) items.get(0);
    assertEquals("Jim", s);
    long v = (Long) items.get(1);
    assertEquals(95L, v);
}
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 87 with Record

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

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

the class TestOperateList method operateNestedListMap.

@Test
public void operateNestedListMap() {
    Key key = new Key(args.namespace, args.set, "oplkey19");
    client.delete(null, key);
    List<Value> l11 = new ArrayList<Value>();
    l11.add(Value.get(7));
    l11.add(Value.get(9));
    l11.add(Value.get(5));
    List<Value> l12 = new ArrayList<Value>();
    l12.add(Value.get(13));
    List<Value> l1 = new ArrayList<Value>();
    l1.add(Value.get(l11));
    l1.add(Value.get(l12));
    List<Value> l21 = new ArrayList<Value>();
    l21.add(Value.get(9));
    List<Value> l22 = new ArrayList<Value>();
    l22.add(Value.get(2));
    l22.add(Value.get(4));
    List<Value> l23 = new ArrayList<Value>();
    l23.add(Value.get(6));
    l23.add(Value.get(1));
    l23.add(Value.get(9));
    List<Value> l2 = new ArrayList<Value>();
    l2.add(Value.get(l21));
    l2.add(Value.get(l22));
    l2.add(Value.get(l23));
    Map<Value, Value> inputMap = new HashMap<Value, Value>();
    inputMap.put(Value.get("key1"), Value.get(l1));
    inputMap.put(Value.get("key2"), Value.get(l2));
    // Create list.
    client.put(null, key, new Bin(binName, inputMap));
    // Append value to last list and retrieve map.
    Record record = client.operate(null, key, ListOperation.append(binName, Value.get(11), CTX.mapKey(Value.get("key2")), CTX.listRank(0)), Operation.get(binName));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<?> results = record.getList(binName);
    int i = 0;
    long count = (Long) results.get(i++);
    assertEquals(3, count);
    Map<?, ?> map = (Map<?, ?>) results.get(i++);
    assertEquals(2, map.size());
    // Test affected nested list.
    List<?> list = (List<?>) map.get("key2");
    assertEquals(3, list.size());
    list = (List<?>) list.get(1);
    assertEquals(3, list.size());
    assertEquals(2, (long) (Long) list.get(0));
    assertEquals(4, (long) (Long) list.get(1));
    assertEquals(11, (long) (Long) list.get(2));
}
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) 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 89 with Record

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

the class TestOperateList method operateListRemoveRelative.

@Test
public void operateListRemoveRelative() {
    Key key = new Key(args.namespace, args.set, "oplkey14");
    client.delete(null, key);
    List<Value> itemList = new ArrayList<Value>();
    itemList.add(Value.get(0));
    itemList.add(Value.get(4));
    itemList.add(Value.get(5));
    itemList.add(Value.get(9));
    itemList.add(Value.get(11));
    itemList.add(Value.get(15));
    Record record = client.operate(null, key, ListOperation.appendItems(new ListPolicy(ListOrder.ORDERED, ListWriteFlags.DEFAULT), binName, itemList), ListOperation.removeByValueRelativeRankRange(binName, Value.get(5), 0, ListReturnType.VALUE), ListOperation.removeByValueRelativeRankRange(binName, Value.get(5), 1, ListReturnType.VALUE), ListOperation.removeByValueRelativeRankRange(binName, Value.get(5), -1, ListReturnType.VALUE), ListOperation.removeByValueRelativeRankRange(binName, Value.get(3), -3, 1, ListReturnType.VALUE), ListOperation.removeByValueRelativeRankRange(binName, Value.get(3), -3, 2, ListReturnType.VALUE), ListOperation.removeByValueRelativeRankRange(binName, Value.get(3), -3, 3, ListReturnType.VALUE));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<?> results = record.getList(binName);
    int i = 0;
    long size = (Long) results.get(i++);
    assertEquals(6L, size);
    List<?> list = (List<?>) results.get(i++);
    assertEquals(4L, list.size());
    assertEquals(5L, list.get(0));
    assertEquals(9L, list.get(1));
    assertEquals(11L, list.get(2));
    assertEquals(15L, list.get(3));
    list = (List<?>) results.get(i++);
    assertEquals(0L, list.size());
    list = (List<?>) results.get(i++);
    assertEquals(1L, list.size());
    assertEquals(4L, list.get(0));
    list = (List<?>) results.get(i++);
    assertEquals(0L, list.size());
    list = (List<?>) results.get(i++);
    assertEquals(0L, list.size());
    list = (List<?>) results.get(i++);
    assertEquals(1L, list.size());
    assertEquals(0L, list.get(0));
}
Also used : Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) ArrayList(java.util.ArrayList) List(java.util.List) ListPolicy(com.aerospike.client.cdt.ListPolicy) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 90 with Record

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

the class TestQueryExecute method queryExecuteOperate.

@Test
public void queryExecuteOperate() {
    int begin = 3;
    int end = 9;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setFilter(Filter.range(binName1, begin, end));
    Bin bin = new Bin("foo", "bar");
    ExecuteTask task = client.execute(null, stmt, Operation.put(bin));
    task.waitTillComplete(3000, 3000);
    String expected = bin.value.toString();
    stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setFilter(Filter.range(binName1, begin, end));
    RecordSet rs = client.query(null, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            Record record = rs.getRecord();
            String value = record.getString(bin.name);
            if (value == null) {
                fail("Bin " + bin.name + " not found");
            }
            if (!value.equals(expected)) {
                fail("Data mismatch. Expected " + expected + ". Received " + value);
            }
            count++;
        }
        assertEquals(end - begin + 1, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) ExecuteTask(com.aerospike.client.task.ExecuteTask) 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