Search in sources :

Example 76 with Record

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

the class TestOperateMap method operateNestedMapValue.

@Test
public void operateNestedMapValue() {
    Key key = new Key(args.namespace, args.set, "opmkey21");
    client.delete(null, key);
    Map<Value, Value> m1 = new HashMap<Value, Value>();
    m1.put(Value.get(1), Value.get("in"));
    m1.put(Value.get(3), Value.get("order"));
    m1.put(Value.get(2), Value.get("key"));
    Map<Value, Value> inputMap = new HashMap<Value, Value>();
    inputMap.put(Value.get("first"), Value.get(m1));
    MapPolicy mapPolicy = new MapPolicy(MapOrder.KEY_ORDERED, MapWriteFlags.DEFAULT);
    // Create nested maps that are all sorted and lookup by map value.
    Record record = client.operate(null, key, MapOperation.putItems(mapPolicy, binName, inputMap), MapOperation.put(mapPolicy, binName, Value.get("first"), Value.get(m1)), MapOperation.getByKey(binName, Value.get(3), MapReturnType.KEY_VALUE, CTX.mapValue(Value.get(m1))));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<?> results = record.getList(binName);
    int i = 0;
    long count = (Long) results.get(i++);
    assertEquals(1, count);
    count = (Long) results.get(i++);
    assertEquals(1, count);
    List<?> list = (List<?>) results.get(i++);
    assertEquals(1, list.size());
    Entry<?, ?> entry = (Entry<?, ?>) list.get(0);
    assertEquals(3L, entry.getKey());
    assertEquals("order", entry.getValue());
}
Also used : HashMap(java.util.HashMap) Entry(java.util.Map.Entry) 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 77 with Record

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

the class TestOperateMap method operateMapPartial.

@Test
public void operateMapPartial() {
    Key key = new Key(args.namespace, args.set, "opmkey16");
    client.delete(null, key);
    Map<Value, Value> inputMap = new HashMap<Value, Value>();
    inputMap.put(Value.get(0), Value.get(17));
    inputMap.put(Value.get(4), Value.get(2));
    inputMap.put(Value.get(5), Value.get(15));
    inputMap.put(Value.get(9), Value.get(10));
    // Write values to empty map.
    Record record = client.operate(null, key, MapOperation.putItems(MapPolicy.Default, binName, inputMap), MapOperation.putItems(MapPolicy.Default, "bin2", inputMap));
    assertRecordFound(key, record);
    Map<Value, Value> sourceMap = new HashMap<Value, Value>();
    sourceMap.put(Value.get(3), Value.get(3));
    sourceMap.put(Value.get(5), Value.get(15));
    record = client.operate(null, key, MapOperation.putItems(new MapPolicy(MapOrder.UNORDERED, MapWriteFlags.CREATE_ONLY | MapWriteFlags.PARTIAL | MapWriteFlags.NO_FAIL), binName, sourceMap), MapOperation.putItems(new MapPolicy(MapOrder.UNORDERED, MapWriteFlags.CREATE_ONLY | MapWriteFlags.NO_FAIL), "bin2", sourceMap));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    long size = record.getLong(binName);
    assertEquals(5L, size);
    size = record.getLong("bin2");
    assertEquals(4L, size);
}
Also used : HashMap(java.util.HashMap) 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 78 with Record

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

the class TestOperateMap method operateMapGetRelative.

@Test
public void operateMapGetRelative() {
    Key key = new Key(args.namespace, args.set, "opmkey14");
    client.delete(null, key);
    Map<Value, Value> inputMap = new HashMap<Value, Value>();
    inputMap.put(Value.get(0), Value.get(17));
    inputMap.put(Value.get(4), Value.get(2));
    inputMap.put(Value.get(5), Value.get(15));
    inputMap.put(Value.get(9), Value.get(10));
    // Write values to empty map.
    Record record = client.operate(null, key, MapOperation.putItems(MapPolicy.Default, binName, inputMap));
    assertRecordFound(key, record);
    record = client.operate(null, key, MapOperation.getByKeyRelativeIndexRange(binName, Value.get(5), 0, MapReturnType.KEY), MapOperation.getByKeyRelativeIndexRange(binName, Value.get(5), 1, MapReturnType.KEY), MapOperation.getByKeyRelativeIndexRange(binName, Value.get(5), -1, MapReturnType.KEY), MapOperation.getByKeyRelativeIndexRange(binName, Value.get(3), 2, MapReturnType.KEY), MapOperation.getByKeyRelativeIndexRange(binName, Value.get(3), -2, MapReturnType.KEY), MapOperation.getByKeyRelativeIndexRange(binName, Value.get(5), 0, 1, MapReturnType.KEY), MapOperation.getByKeyRelativeIndexRange(binName, Value.get(5), 1, 2, MapReturnType.KEY), MapOperation.getByKeyRelativeIndexRange(binName, Value.get(5), -1, 1, MapReturnType.KEY), MapOperation.getByKeyRelativeIndexRange(binName, Value.get(3), 2, 1, MapReturnType.KEY), MapOperation.getByKeyRelativeIndexRange(binName, Value.get(3), -2, 2, MapReturnType.KEY), MapOperation.getByValueRelativeRankRange(binName, Value.get(11), 1, MapReturnType.VALUE), MapOperation.getByValueRelativeRankRange(binName, Value.get(11), -1, MapReturnType.VALUE), MapOperation.getByValueRelativeRankRange(binName, Value.get(11), 1, 1, MapReturnType.VALUE), MapOperation.getByValueRelativeRankRange(binName, Value.get(11), -1, 1, MapReturnType.VALUE));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<?> results = record.getList(binName);
    int i = 0;
    List<?> list = (List<?>) results.get(i++);
    assertEquals(2L, list.size());
    assertEquals(5L, list.get(0));
    assertEquals(9L, list.get(1));
    list = (List<?>) results.get(i++);
    assertEquals(1L, list.size());
    assertEquals(9L, list.get(0));
    list = (List<?>) results.get(i++);
    assertEquals(3L, list.size());
    assertEquals(4L, list.get(0));
    assertEquals(5L, list.get(1));
    assertEquals(9L, list.get(2));
    list = (List<?>) results.get(i++);
    assertEquals(1L, list.size());
    assertEquals(9L, list.get(0));
    list = (List<?>) results.get(i++);
    assertEquals(4L, list.size());
    assertEquals(0L, list.get(0));
    assertEquals(4L, list.get(1));
    assertEquals(5L, list.get(2));
    assertEquals(9L, list.get(3));
    list = (List<?>) results.get(i++);
    assertEquals(1L, list.size());
    assertEquals(5L, list.get(0));
    list = (List<?>) results.get(i++);
    assertEquals(1L, list.size());
    assertEquals(9L, list.get(0));
    list = (List<?>) results.get(i++);
    assertEquals(1L, list.size());
    assertEquals(4L, list.get(0));
    list = (List<?>) results.get(i++);
    assertEquals(1L, list.size());
    assertEquals(9L, list.get(0));
    list = (List<?>) results.get(i++);
    assertEquals(1L, list.size());
    assertEquals(0L, list.get(0));
    list = (List<?>) results.get(i++);
    assertEquals(1L, list.size());
    assertEquals(17L, list.get(0));
    list = (List<?>) results.get(i++);
    assertEquals(3L, list.size());
    assertEquals(10L, list.get(0));
    assertEquals(15L, list.get(1));
    assertEquals(17L, list.get(2));
    list = (List<?>) results.get(i++);
    assertEquals(1L, list.size());
    assertEquals(17L, list.get(0));
    list = (List<?>) results.get(i++);
    assertEquals(1L, list.size());
    assertEquals(10L, list.get(0));
}
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) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 79 with Record

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

the class TestOperateMap method operateMapGetByList.

@Test
public void operateMapGetByList() {
    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 80 with Record

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

the class TestOperateBit method assertBitReadOperation.

public void assertBitReadOperation(byte[] initial, Long[] expected, Operation... operations) {
    client.delete(null, key);
    client.put(null, key, new Bin(binName, initial));
    Record record = client.operate(null, key, operations);
    // System.out.println("Record: " + record);
    List<?> result_list = record.getList(binName);
    Long[] actual = new Long[expected.length];
    for (int i = 0; i < expected.length; i++) {
        actual[i] = (Long) result_list.get(i);
    }
    // System.out.println("Initial : " + Arrays.toString(initial));
    // System.out.println("Expected: " + Arrays.toString(expected));
    // System.out.println("Actual  : " + Arrays.toString(actual));
    assertArrayEquals(expected, actual);
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record)

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