Search in sources :

Example 31 with Bin

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

the class TestOperateBit method operateBitNullBlob.

@Test
public void operateBitNullBlob() {
    BitPolicy policy = new BitPolicy();
    byte[] initial = new byte[] {};
    byte[] buf = new byte[] { (byte) 0x80 };
    client.delete(null, key);
    client.put(null, key, new Bin(binName, initial));
    assertThrows(AerospikeException.class, 26, BitOperation.set(policy, binName, 0, 1, buf));
    assertThrows(AerospikeException.class, 26, BitOperation.or(policy, binName, 0, 1, buf));
    assertThrows(AerospikeException.class, 26, BitOperation.xor(policy, binName, 0, 1, buf));
    assertThrows(AerospikeException.class, 26, BitOperation.and(policy, binName, 0, 1, buf));
    assertThrows(AerospikeException.class, 26, BitOperation.not(policy, binName, 0, 1));
    assertThrows(AerospikeException.class, 26, BitOperation.lshift(policy, binName, 0, 1, 1));
    assertThrows(AerospikeException.class, 26, BitOperation.rshift(policy, binName, 0, 1, 1));
    // OK for insert.
    assertThrows(AerospikeException.class, 4, BitOperation.remove(policy, binName, 0, 1));
    assertThrows(AerospikeException.class, 26, BitOperation.add(policy, binName, 0, 1, 1, false, BitOverflowAction.FAIL));
    assertThrows(AerospikeException.class, 26, BitOperation.subtract(policy, binName, 0, 1, 1, false, BitOverflowAction.FAIL));
    assertThrows(AerospikeException.class, 26, BitOperation.setInt(policy, binName, 0, 1, 1));
    assertThrows(AerospikeException.class, 26, BitOperation.get(binName, 0, 1));
    assertThrows(AerospikeException.class, 26, BitOperation.count(binName, 0, 1));
    assertThrows(AerospikeException.class, 26, BitOperation.lscan(binName, 0, 1, true));
    assertThrows(AerospikeException.class, 26, BitOperation.rscan(binName, 0, 1, true));
    assertThrows(AerospikeException.class, 26, BitOperation.getInt(binName, 0, 1, false));
}
Also used : Bin(com.aerospike.client.Bin) BitPolicy(com.aerospike.client.operation.BitPolicy) Test(org.junit.Test)

Example 32 with Bin

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

Example 33 with Bin

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

the class TestOperateBit method operateBitAdd.

@Test
public void operateBitAdd() {
    BitPolicy putMode = new BitPolicy();
    assertBitModifyOperations(new byte[] { 0x38, 0x1F, 0x00, (byte) 0xE8, 0x7F, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03 }, new byte[] { 0x40, 0x20, 0x01, (byte) 0xF0, (byte) 0x80, 0x7F, 0x7F, 0x7F, 0x02, 0x02, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x06, 0x07, 0x07, 0x07 }, BitOperation.add(putMode, binName, 0, 5, 1, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 9, 7, 1, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 23, 6, 0x21, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 32, 8, 1, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 40, 24, 0x7F7F7F, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 64, 20, 0x01010, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 92, 20, 0x10101, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 113, 22, 0x8082, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 136, 23, 0x20202, false, BitOverflowAction.FAIL));
    byte[] initial = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
    int i = 0;
    assertBitModifyOperations(initial, new byte[] { (byte) 0xFE, (byte) 0xFE, 0x7F, (byte) 0xFF, 0x7F, (byte) 0x80 }, BitOperation.add(putMode, binName, 8 * i, 8, 0xFF, false, BitOverflowAction.WRAP), BitOperation.add(putMode, binName, 8 * i++, 8, 0xFF, false, BitOverflowAction.WRAP), BitOperation.add(putMode, binName, 8 * i, 8, 0x7F, true, BitOverflowAction.WRAP), BitOperation.add(putMode, binName, 8 * i++, 8, 0x7F, true, BitOverflowAction.WRAP), BitOperation.add(putMode, binName, 8 * i, 8, 0x80, true, BitOverflowAction.WRAP), BitOperation.add(putMode, binName, 8 * i++, 8, 0xFF, true, BitOverflowAction.WRAP), BitOperation.add(putMode, binName, 8 * i, 8, 0x80, false, BitOverflowAction.SATURATE), BitOperation.add(putMode, binName, 8 * i++, 8, 0x80, false, BitOverflowAction.SATURATE), BitOperation.add(putMode, binName, 8 * i, 8, 0x77, true, BitOverflowAction.SATURATE), BitOperation.add(putMode, binName, 8 * i++, 8, 0x77, true, BitOverflowAction.SATURATE), BitOperation.add(putMode, binName, 8 * i, 8, 0x8F, true, BitOverflowAction.SATURATE), BitOperation.add(putMode, binName, 8 * i++, 8, 0x8F, true, BitOverflowAction.SATURATE));
    client.put(null, key, new Bin(binName, initial));
    assertThrows(AerospikeException.class, 26, BitOperation.add(putMode, binName, 0, 8, 0xFF, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 0, 8, 0xFF, false, BitOverflowAction.FAIL));
    assertThrows(AerospikeException.class, 26, BitOperation.add(putMode, binName, 0, 8, 0x7F, true, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 0, 8, 0x02, true, BitOverflowAction.FAIL));
    assertThrows(AerospikeException.class, 26, BitOperation.add(putMode, binName, 0, 8, 0x81, true, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 0, 8, 0xFE, true, BitOverflowAction.FAIL));
}
Also used : Bin(com.aerospike.client.Bin) BitPolicy(com.aerospike.client.operation.BitPolicy) Test(org.junit.Test)

Example 34 with Bin

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

Example 35 with Bin

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

Aggregations

Bin (com.aerospike.client.Bin)151 Key (com.aerospike.client.Key)129 Record (com.aerospike.client.Record)70 Test (org.junit.Test)54 AerospikeException (com.aerospike.client.AerospikeException)34 ArrayList (java.util.ArrayList)31 WritePolicy (com.aerospike.client.policy.WritePolicy)27 HashMap (java.util.HashMap)22 Value (com.aerospike.client.Value)20 List (java.util.List)15 BeforeClass (org.junit.BeforeClass)14 Map (java.util.Map)13 Policy (com.aerospike.client.policy.Policy)12 IndexTask (com.aerospike.client.task.IndexTask)11 WriteListener (com.aerospike.client.listener.WriteListener)5 RegisterTask (com.aerospike.client.task.RegisterTask)5 AbstractMap (java.util.AbstractMap)4 TreeMap (java.util.TreeMap)4 CTX (com.aerospike.client.cdt.CTX)3 BitPolicy (com.aerospike.client.operation.BitPolicy)3