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));
}
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);
}
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));
}
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);
}
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));
}
Aggregations